mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Big refactor to remove the deprecated transaction collector.
This commit is contained in:
parent
10a6ff9bf8
commit
8b7e87ae57
@ -178,7 +178,7 @@ class AccountController extends Controller
|
||||
$defaultSet = $this->repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
if (0 === \count($frontPage->data)) {
|
||||
if (0 === count($frontPage->data)) {
|
||||
$frontPage->data = $defaultSet;
|
||||
$frontPage->save();
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ class PreferenceController extends Controller
|
||||
// an important fallback is that the frontPageAccount array gets refilled automatically
|
||||
// when it turns up empty.
|
||||
$frontPageAccounts = app('preferences')->getForUser($user, 'frontPageAccounts', [])->data;
|
||||
if (0 === \count($frontPageAccounts)) {
|
||||
if (0 === count($frontPageAccounts)) {
|
||||
/** @var Collection $accounts */
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
|
@ -141,7 +141,7 @@ class RuleRequest extends Request
|
||||
$data = $validator->getData();
|
||||
$actions = $data['actions'] ?? [];
|
||||
// need at least one trigger
|
||||
if (0 === \count($actions)) {
|
||||
if (0 === count($actions)) {
|
||||
$validator->errors()->add('title', (string)trans('validation.at_least_one_action'));
|
||||
}
|
||||
}
|
||||
@ -156,7 +156,7 @@ class RuleRequest extends Request
|
||||
$data = $validator->getData();
|
||||
$triggers = $data['triggers'] ?? [];
|
||||
// need at least one trugger
|
||||
if (0 === \count($triggers)) {
|
||||
if (0 === count($triggers)) {
|
||||
$validator->errors()->add('title', (string)trans('validation.at_least_one_trigger'));
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ class ApplyRules extends Command
|
||||
$finalList = new Collection;
|
||||
$accountList = explode(',', $accountString);
|
||||
|
||||
if (0 === \count($accountList)) {
|
||||
if (0 === count($accountList)) {
|
||||
$this->error('Please use the --accounts to indicate the accounts to apply rules to.');
|
||||
|
||||
return false;
|
||||
@ -267,7 +267,7 @@ class ApplyRules extends Command
|
||||
}
|
||||
$ruleGroupList = explode(',', $ruleGroupString);
|
||||
|
||||
if (0 === \count($ruleGroupList)) {
|
||||
if (0 === count($ruleGroupList)) {
|
||||
// can be empty.
|
||||
|
||||
return true;
|
||||
@ -299,7 +299,7 @@ class ApplyRules extends Command
|
||||
$finalList = new Collection;
|
||||
$ruleList = explode(',', $ruleString);
|
||||
|
||||
if (0 === \count($ruleList)) {
|
||||
if (0 === count($ruleList)) {
|
||||
// can be empty.
|
||||
|
||||
return true;
|
||||
|
@ -225,8 +225,8 @@ class CreateImport extends Command
|
||||
if (null === $importJob->tag) {
|
||||
$this->errorLine('No transactions have been imported :(.');
|
||||
}
|
||||
if (\count($importJob->errors) > 0) {
|
||||
$this->infoLine(sprintf('%d error(s) occurred:', \count($importJob->errors)));
|
||||
if (count($importJob->errors) > 0) {
|
||||
$this->infoLine(sprintf('%d error(s) occurred:', count($importJob->errors)));
|
||||
foreach ($importJob->errors as $err) {
|
||||
$this->errorLine('- ' . $err);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class MigrateToRules extends Command
|
||||
|
||||
if (null === $ruleGroup) {
|
||||
$array = RuleGroup::get(['order'])->pluck('order')->toArray();
|
||||
$order = \count($array) > 0 ? max($array) + 1 : 1;
|
||||
$order = count($array) > 0 ? max($array) + 1 : 1;
|
||||
$ruleGroup = RuleGroup::create(
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
|
@ -229,8 +229,8 @@ class AccountFactory
|
||||
Log::debug(sprintf('No account type found by ID, continue search for "%s".', $accountType));
|
||||
/** @var array $types */
|
||||
$types = config('firefly.accountTypeByIdentifier.' . $accountType) ?? [];
|
||||
if (\count($types) > 0) {
|
||||
Log::debug(sprintf('%d accounts in list from config', \count($types)), $types);
|
||||
if (count($types) > 0) {
|
||||
Log::debug(sprintf('%d accounts in list from config', count($types)), $types);
|
||||
$result = AccountType::whereIn('type', $types)->first();
|
||||
}
|
||||
if (null === $result && null !== $accountType) {
|
||||
|
@ -121,7 +121,7 @@ class ChartJsGenerator implements GeneratorInterface
|
||||
$labels = \is_array($first['entries']) ? array_keys($first['entries']) : [];
|
||||
|
||||
$chartData = [
|
||||
'count' => \count($data),
|
||||
'count' => count($data),
|
||||
'labels' => $labels, // take ALL labels from the first set.
|
||||
'datasets' => [],
|
||||
];
|
||||
|
@ -30,7 +30,6 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface;
|
||||
use FireflyIII\Generator\Report\Support;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
@ -79,7 +78,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
$reportType = 'tag';
|
||||
$expenses = $this->getExpenses();
|
||||
$income = $this->getIncome();
|
||||
$accountSummary = $this->getObjectSummary($this->summarizeByAccount($expenses), $this->summarizeByAccount($income));
|
||||
$accountSummary = $this->getObjectSummary($this->summarizeByAssetAccount($expenses), $this->summarizeByAssetAccount($income));
|
||||
$tagSummary = $this->getObjectSummary($this->summarizeByTag($expenses), $this->summarizeByTag($income));
|
||||
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
||||
$averageIncome = $this->getAverages($income, SORT_DESC);
|
||||
@ -163,12 +162,14 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
||||
$result = [];
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
/** @var Tag $journalTag */
|
||||
foreach ($journal['tag_ids'] as $journalTag) {
|
||||
$journalTagId = (int)$journalTag;
|
||||
if (\in_array($journalTagId, $tagIds, true)) {
|
||||
$result[$journalTagId] = $result[$journalTagId] ?? '0';
|
||||
$result[$journalTagId] = bcadd($journal['amount'], $result[$journalTagId]);
|
||||
/**
|
||||
* @var int $id
|
||||
* @var array $tag
|
||||
*/
|
||||
foreach ($journal['tags'] as $id => $tag) {
|
||||
if (in_array($id, $tagIds, true)) {
|
||||
$result[$id] = $result[$id] ?? '0';
|
||||
$result[$id] = bcadd($journal['amount'], $result[$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
}
|
||||
Log::debug('Done processing uploads.');
|
||||
}
|
||||
if (!\is_array($files) || (\is_array($files) && 0 === \count($files))) {
|
||||
if (!\is_array($files) || (\is_array($files) && 0 === count($files))) {
|
||||
Log::debug('Array of files is not an array. Probably nothing uploaded. Will not store attachments.');
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ namespace FireflyIII\Helpers\Chart;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
@ -117,8 +116,7 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
$collector->setUser($this->user);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = $this->sumJournals($journals);
|
||||
$sum = $collector->getSum();
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[$key] = $sum;
|
||||
@ -131,8 +129,7 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$sum = $this->sumJournals($journals);
|
||||
$sum = $collector->getSum();
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[$key] = $sum;
|
||||
}
|
||||
@ -220,22 +217,20 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Collection $set
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function groupByTag(Collection $set): array
|
||||
private function groupByTag(array $array): array
|
||||
{
|
||||
$grouped = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$journal = $transaction->transactionJournal;
|
||||
$tags = $journal->tags;
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$tags = $journal['tags'] ?? [];
|
||||
/** @var Tag $tag */
|
||||
foreach ($tags as $tag) {
|
||||
$tagId = $tag->id;
|
||||
$grouped[$tagId] = $grouped[$tagId] ?? '0';
|
||||
$grouped[$tagId] = bcadd($transaction->transaction_amount, $grouped[$tagId]);
|
||||
foreach ($tags as $id => $tag) {
|
||||
$grouped[$id] = $grouped[$id] ?? '0';
|
||||
$grouped[$id] = bcadd($journal['amount'], $grouped[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,22 +265,6 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
return $chartData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @return string
|
||||
*/
|
||||
private function sumJournals(array $journals): string
|
||||
{
|
||||
$sum = '0';
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = (string)$journal['amount'];
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accounts setter.
|
||||
*
|
||||
@ -413,4 +392,6 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -130,23 +130,15 @@ class GroupCollector implements GroupCollectorInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction journals without group information. Is useful in some instances.
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*
|
||||
* @return array
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getExtractedJournals(): array
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$selection = $this->getGroups();
|
||||
$return = [];
|
||||
/** @var array $group */
|
||||
foreach ($selection as $group) {
|
||||
foreach ($group['transactions'] as $journalId => $journal) {
|
||||
$journal['group_title'] = $group['title'];
|
||||
$return[$journalId] = $journal;
|
||||
}
|
||||
}
|
||||
$set = $this->getGroups();
|
||||
|
||||
return $return;
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -330,18 +322,6 @@ class GroupCollector implements GroupCollectorInterface
|
||||
return $groups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as getGroups but everything is in a paginator.
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
public function getPaginatedGroups(): LengthAwarePaginator
|
||||
{
|
||||
$set = $this->getGroups();
|
||||
|
||||
return new LengthAwarePaginator($set, $this->total, $this->limit, $this->page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define which accounts can be part of the source and destination transactions.
|
||||
*
|
||||
@ -554,7 +534,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
$this->query->where('transaction_journals.date', '>=', $startStr);
|
||||
$this->query->where('transaction_journals.date', '<=', $endStr);
|
||||
app('log')->debug(sprintf('TransactionCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
||||
app('log')->debug(sprintf('GroupCollector range is now %s - %s (inclusive)', $startStr, $endStr));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -642,7 +622,7 @@ class GroupCollector implements GroupCollectorInterface
|
||||
*/
|
||||
private function startQuery(): void
|
||||
{
|
||||
app('log')->debug('TransactionCollector::startQuery');
|
||||
app('log')->debug('GroupCollector::startQuery');
|
||||
$this->query = $this->user
|
||||
->transactionGroups()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.transaction_group_id', 'transaction_groups.id')
|
||||
@ -778,4 +758,76 @@ class GroupCollector implements GroupCollectorInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget..
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): GroupCollectorInterface
|
||||
{
|
||||
$this->withBudgetInformation();
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) {
|
||||
$q->whereNull('budget_transaction_journal.budget_id');
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): GroupCollectorInterface
|
||||
{
|
||||
$this->withCategoryInformation();
|
||||
$this->query->where(
|
||||
function (EloquentBuilder $q) {
|
||||
$q->whereNull('category_transaction_journal.category_id');
|
||||
}
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the sum of all journals.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSum(): string
|
||||
{
|
||||
$journals = $this->getExtractedJournals();
|
||||
$sum = '0';
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = (string)$journal['amount'];
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the transaction journals without group information. Is useful in some instances.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtractedJournals(): array
|
||||
{
|
||||
$selection = $this->getGroups();
|
||||
$return = [];
|
||||
/** @var array $group */
|
||||
foreach ($selection as $group) {
|
||||
foreach ($group['transactions'] as $journalId => $journal) {
|
||||
$journal['group_title'] = $group['title'];
|
||||
$return[$journalId] = $journal;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
@ -46,6 +46,13 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function getExtractedJournals(): array;
|
||||
|
||||
/**
|
||||
* Return the sum of all journals.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSum(): string;
|
||||
|
||||
/**
|
||||
* Return the groups.
|
||||
*
|
||||
@ -170,6 +177,20 @@ interface GroupCollectorInterface
|
||||
*/
|
||||
public function setTags(Collection $tags): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a budget.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutBudget(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit results to a transactions without a category.
|
||||
*
|
||||
* @return GroupCollectorInterface
|
||||
*/
|
||||
public function withoutCategory(): GroupCollectorInterface;
|
||||
|
||||
/**
|
||||
* Limit the search to one specific transaction group.
|
||||
*
|
||||
|
@ -458,7 +458,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
public function setBudgets(Collection $budgets): TransactionCollectorInterface
|
||||
{
|
||||
$budgetIds = $budgets->pluck('id')->toArray();
|
||||
if (0 !== \count($budgetIds)) {
|
||||
if (0 !== count($budgetIds)) {
|
||||
$this->joinBudgetTables();
|
||||
Log::debug('Journal collector will filter for budgets', $budgetIds);
|
||||
|
||||
@ -481,7 +481,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
public function setCategories(Collection $categories): TransactionCollectorInterface
|
||||
{
|
||||
$categoryIds = $categories->pluck('id')->toArray();
|
||||
if (0 !== \count($categoryIds)) {
|
||||
if (0 !== count($categoryIds)) {
|
||||
$this->joinCategoryTables();
|
||||
|
||||
$this->query->where(
|
||||
@ -721,7 +721,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
*/
|
||||
public function setTypes(array $types): TransactionCollectorInterface
|
||||
{
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
Log::debug('Set query collector types', $types);
|
||||
$this->query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
@ -849,7 +849,7 @@ class TransactionCollector implements TransactionCollectorInterface
|
||||
TransactionViewFilter::class => new TransactionViewFilter,
|
||||
DoubleTransactionFilter::class => new DoubleTransactionFilter,
|
||||
];
|
||||
Log::debug(sprintf('Will run %d filters on the set.', \count($this->filters)));
|
||||
Log::debug(sprintf('Will run %d filters on the set.', count($this->filters)));
|
||||
foreach ($this->filters as $enabled) {
|
||||
if (isset($filters[$enabled])) {
|
||||
Log::debug(sprintf('Before filter %s: %d', $enabled, $set->count()));
|
||||
|
@ -22,7 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Helpers\Report;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
@ -52,54 +52,54 @@ class PopupReport implements PopupReportInterface
|
||||
/**
|
||||
* Collect the transactions for one account and one budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): Collection
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])->setBudget($budget);
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the tranactions for one account and no budget.
|
||||
* Collect the transactions for one account and no budget.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForNoBudget(Account $account, array $attributes): Collection
|
||||
public function balanceForNoBudget(Account $account, array $attributes): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector
|
||||
->setAccounts(new Collection([$account]))
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->withoutBudget();
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the tranactions for a budget.
|
||||
* Collect the transactions for a budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byBudget(Budget $budget, array $attributes): Collection
|
||||
public function byBudget(Budget $budget, array $attributes): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($attributes['accounts'])->setRange($attributes['startDate'], $attributes['endDate']);
|
||||
|
||||
@ -110,97 +110,93 @@ class PopupReport implements PopupReportInterface
|
||||
$collector->setBudget($budget);
|
||||
}
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect journals by a category.
|
||||
*
|
||||
* @param Category $category
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byCategory(Category $category, array $attributes): Collection
|
||||
public function byCategory(Category $category, array $attributes): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($attributes['accounts'])->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->withOpposingAccount()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation()
|
||||
->setCategory($category);
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Group transactions by expense.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byExpenses(Account $account, array $attributes): Collection
|
||||
public function byExpenses(Account $account, array $attributes): array
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
|
||||
$transactions = $collector->getTransactions();
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||
|
||||
// filter for transfers and withdrawals TO the given $account
|
||||
$transactions = $transactions->filter(
|
||||
function (Transaction $transaction) use ($report, $repository) {
|
||||
// get the destinations:
|
||||
$sources = $repository->getJournalSourceAccounts($transaction->transactionJournal)->pluck('id')->toArray();
|
||||
|
||||
// do these intersect with the current list?
|
||||
return !empty(array_intersect($report, $sources));
|
||||
$filtered = [];
|
||||
// TODO not sure if filter is necessary.
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if (in_array($journal['source_account_id'], $report, true)) {
|
||||
$filtered[] = $journal;
|
||||
}
|
||||
);
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
return $filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect transactions by income.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byIncome(Account $account, array $attributes): Collection
|
||||
public function byIncome(Account $account, array $attributes): array
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$transactions = $collector->getTransactions();
|
||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
|
||||
|
||||
// filter the set so the destinations outside of $attributes['accounts'] are not included.
|
||||
$transactions = $transactions->filter(
|
||||
function (Transaction $transaction) use ($report, $repository) {
|
||||
// get the destinations:
|
||||
$journal = $transaction->transactionJournal;
|
||||
$destinations = $repository->getJournalDestinationAccounts($journal)->pluck('id')->toArray();
|
||||
|
||||
// do these intersect with the current list?
|
||||
return !empty(array_intersect($report, $destinations));
|
||||
// TODO not sure if filter is necessary.
|
||||
$filtered = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if (in_array($journal['destination_account_id'], $report, true)) {
|
||||
$filtered[] = $journal;
|
||||
}
|
||||
);
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
|
@ -39,9 +39,9 @@ interface PopupReportInterface
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): Collection;
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Get balances for transactions without a budget.
|
||||
@ -49,9 +49,9 @@ interface PopupReportInterface
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForNoBudget(Account $account, array $attributes): Collection;
|
||||
public function balanceForNoBudget(Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Group by budget.
|
||||
@ -59,9 +59,9 @@ interface PopupReportInterface
|
||||
* @param Budget $budget
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byBudget(Budget $budget, array $attributes): Collection;
|
||||
public function byBudget(Budget $budget, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Group by category.
|
||||
@ -69,9 +69,9 @@ interface PopupReportInterface
|
||||
* @param Category $category
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byCategory(Category $category, array $attributes): Collection;
|
||||
public function byCategory(Category $category, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Do something with expense. Sorry, I am not very inspirational here.
|
||||
@ -79,9 +79,9 @@ interface PopupReportInterface
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byExpenses(Account $account, array $attributes): Collection;
|
||||
public function byExpenses(Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Do something with income. Sorry, I am not very inspirational here.
|
||||
@ -89,7 +89,7 @@ interface PopupReportInterface
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function byIncome(Account $account, array $attributes): Collection;
|
||||
public function byIncome(Account $account, array $attributes): array;
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ trait UpdateTrait
|
||||
// get releases from array.
|
||||
$releases = $request->getReleases();
|
||||
|
||||
Log::debug(sprintf('Found %d releases', \count($releases)));
|
||||
Log::debug(sprintf('Found %d releases', count($releases)));
|
||||
|
||||
if (\count($releases) > 0) {
|
||||
if (count($releases) > 0) {
|
||||
// first entry should be the latest entry:
|
||||
/** @var Release $first */
|
||||
$first = reset($releases);
|
||||
|
@ -136,7 +136,7 @@ class CreateController extends Controller
|
||||
|
||||
// update preferences if necessary:
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', [])->data;
|
||||
if (AccountType::ASSET === $account->accountType->type && \count($frontPage) > 0) {
|
||||
if (AccountType::ASSET === $account->accountType->type && count($frontPage) > 0) {
|
||||
// @codeCoverageIgnoreStart
|
||||
$frontPage[] = $account->id;
|
||||
app('preferences')->set('frontPageAccounts', $frontPage);
|
||||
|
@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Account;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@ -126,7 +125,7 @@ class ShowController extends Controller
|
||||
$collector
|
||||
->setAccounts(new Collection([$account]))
|
||||
->setLimit($pageSize)
|
||||
->setPage($page)
|
||||
->setPage($page)->withAccountInformation()
|
||||
->setRange($start, $end);
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
|
||||
@ -170,17 +169,17 @@ class ShowController extends Controller
|
||||
}
|
||||
$subTitle = (string)trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
||||
$periods = new Collection;
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('accounts.show.all', [$account->id]));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('accounts.show.all', [$account->id]));
|
||||
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
$showAll = true;
|
||||
|
||||
return view(
|
||||
'accounts.show',
|
||||
compact('account', 'showAll', 'isLiability', 'currency', 'today', 'chartUri', 'periods', 'subTitleIcon', 'transactions', 'subTitle', 'start', 'end')
|
||||
compact('account', 'showAll', 'isLiability', 'currency', 'today', 'chartUri', 'periods', 'subTitleIcon', 'groups', 'subTitle', 'start', 'end')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ class BillController extends Controller
|
||||
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
|
||||
$this->attachments->saveAttachmentsForModel($bill, $files);
|
||||
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
@ -384,7 +384,7 @@ class BillController extends Controller
|
||||
$this->attachments->saveAttachmentsForModel($bill, $files);
|
||||
|
||||
// flash messages
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore
|
||||
}
|
||||
$redirect = redirect($this->getPreviousUri('bills.edit.uri'));
|
||||
|
@ -25,7 +25,7 @@ namespace FireflyIII\Http\Controllers\Budget;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\BudgetIncomeRequest;
|
||||
use FireflyIII\Models\Budget;
|
||||
@ -71,9 +71,9 @@ class AmountController extends Controller
|
||||
/**
|
||||
* Set the amount for a single budget in a specific period. Shows a waring when its a lot.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param BudgetRepositoryInterface $repository
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
@ -147,6 +147,7 @@ class AmountController extends Controller
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* TODO remove this feature
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
@ -164,10 +165,10 @@ class AmountController extends Controller
|
||||
Log::debug(sprintf('Average is %s, so total available is %s because days is %d.', $average, $available, $daysInPeriod));
|
||||
|
||||
// amount earned in this period:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::DEPOSIT])->withOpposingAccount();
|
||||
$earned = (string)$collector->getTransactions()->sum('transaction_amount');
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::DEPOSIT]);
|
||||
$earned = $collector->getSum();
|
||||
// Total amount earned divided by the number of days in the whole search period is the average amount earned per day.
|
||||
// This is multiplied by the number of days in the current period, showing you the average.
|
||||
$earnedAverage = bcmul(bcdiv($earned, (string)$daysInSearchPeriod), (string)$daysInPeriod);
|
||||
@ -175,10 +176,10 @@ class AmountController extends Controller
|
||||
Log::debug(sprintf('Earned is %s, earned average is %s', $earned, $earnedAverage));
|
||||
|
||||
// amount spent in period
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
|
||||
$spent = (string)$collector->getTransactions()->sum('transaction_amount');
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($searchBegin, $searchEnd)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$spent = $collector->getSum();
|
||||
$spentAverage = app('steam')->positive(bcmul(bcdiv($spent, (string)$daysInSearchPeriod), (string)$daysInPeriod));
|
||||
|
||||
Log::debug(sprintf('Spent is %s, spent average is %s', $earned, $earnedAverage));
|
||||
@ -227,8 +228,8 @@ class AmountController extends Controller
|
||||
* Shows the form to update available budget.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
|
@ -26,7 +26,7 @@ namespace FireflyIII\Http\Controllers\Budget;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
@ -66,7 +66,7 @@ class ShowController extends Controller
|
||||
/**
|
||||
* Show transactions without a budget.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@ -86,20 +86,20 @@ class ShowController extends Controller
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
||||
->withoutBudget()->withOpposingAccount();
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('budgets.no-budget'));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
||||
->withoutBudget()->withAccountInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('budgets.no-budget'));
|
||||
|
||||
return view('budgets.no-budget', compact('transactions', 'subTitle', 'periods', 'start', 'end'));
|
||||
return view('budgets.no-budget', compact('groups', 'subTitle', 'periods', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows ALL transactions without a budget.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
@ -115,14 +115,14 @@ class ShowController extends Controller
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
||||
->withoutBudget()->withOpposingAccount();
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('budgets.no-budget'));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
|
||||
->withoutBudget()->withAccountInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('budgets.no-budget'));
|
||||
|
||||
return view('budgets.no-budget', compact('transactions', 'subTitle', 'start', 'end'));
|
||||
return view('budgets.no-budget', compact('groups', 'subTitle', 'start', 'end'));
|
||||
}
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ class ShowController extends Controller
|
||||
* Show a single budget.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
@ -145,22 +145,22 @@ class ShowController extends Controller
|
||||
$repetition = null;
|
||||
|
||||
// collector:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation();
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('budgets.show', [$budget->id]));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('budgets.show', [$budget->id]));
|
||||
|
||||
$subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
|
||||
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'transactions', 'subTitle'));
|
||||
return view('budgets.show', compact('limits', 'budget', 'repetition', 'groups', 'subTitle'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single budget by a budget limit.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
* @param Request $request
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
@ -184,17 +184,18 @@ class ShowController extends Controller
|
||||
);
|
||||
|
||||
// collector:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($budgetLimit->start_date, $budgetLimit->end_date)
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)
|
||||
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation();
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('budgets.show', [$budget->id, $budgetLimit->id]));
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('budgets.show', [$budget->id, $budgetLimit->id]));
|
||||
/** @var Carbon $start */
|
||||
$start = session('first', Carbon::now()->startOfYear());
|
||||
$end = new Carbon;
|
||||
$limits = $this->getLimits($budget, $start, $end);
|
||||
|
||||
return view('budgets.show', compact('limits', 'budget', 'budgetLimit', 'transactions', 'subTitle'));
|
||||
return view('budgets.show', compact('limits', 'budget', 'budgetLimit', 'groups', 'subTitle'));
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ namespace FireflyIII\Http\Controllers\Category;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
@ -66,7 +65,7 @@ class NoCategoryController extends Controller
|
||||
/**
|
||||
* Show transactions without a category.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@ -90,15 +89,15 @@ class NoCategoryController extends Controller
|
||||
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
|
||||
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount()
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)
|
||||
->setLimit($pageSize)->setPage($page)->withoutCategory()
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('categories.no-category'));
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('categories.no-category'));
|
||||
|
||||
return view('categories.no-category', compact('transactions', 'subTitle', 'periods', 'start', 'end'));
|
||||
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
|
||||
}
|
||||
|
||||
|
||||
@ -125,14 +124,13 @@ class NoCategoryController extends Controller
|
||||
Log::debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
|
||||
Log::debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()->withOpposingAccount()
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withoutCategory()
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath(route('categories.no-category.all'));
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath(route('categories.no-category.all'));
|
||||
|
||||
return view('categories.no-category', compact('transactions', 'subTitle', 'periods', 'start', 'end'));
|
||||
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
|
||||
}
|
||||
}
|
||||
|
@ -24,8 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
@ -69,8 +68,8 @@ class ShowController extends Controller
|
||||
/**
|
||||
* Show a single category.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Category $category
|
||||
* @param Request $request
|
||||
* @param Category $category
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@ -94,23 +93,24 @@ class ShowController extends Controller
|
||||
'end' => $end->formatLocalized($this->monthAndDayFormat),]
|
||||
);
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)
|
||||
->withAccountInformation()
|
||||
->setCategory($category)->withBudgetInformation()->withCategoryInformation();
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath($path);
|
||||
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
|
||||
Log::debug('End of show()');
|
||||
|
||||
return view('categories.show', compact('category', 'transactions', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
|
||||
return view('categories.show', compact('category', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all transactions within a category.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
* @param Category $category
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
@ -133,14 +133,15 @@ class ShowController extends Controller
|
||||
$path = route('categories.show.all', [$category->id]);
|
||||
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)
|
||||
->withAccountInformation()
|
||||
->setCategory($category)->withBudgetInformation()->withCategoryInformation();
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath($path);
|
||||
|
||||
return view('categories.show', compact('category', 'transactions', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
|
||||
return view('categories.show', compact('category', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,10 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@ -147,7 +146,7 @@ class AccountController extends Controller
|
||||
|
||||
// loop all found currencies and build the data array for the chart.
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var int $currencyId
|
||||
* @var TransactionCurrency $currency
|
||||
*/
|
||||
foreach ($currencies as $currencyId => $currency) {
|
||||
@ -174,13 +173,28 @@ class AccountController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expenses per budget for all time, as shown on account overview.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
{
|
||||
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now();
|
||||
|
||||
return $this->expenseBudget($account, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expenses per budget, as shown on account overview.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
@ -194,30 +208,28 @@ class AccountController extends Controller
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withBudgetInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getTransactions();
|
||||
$chartData = [];
|
||||
$result = [];
|
||||
$budgetIds = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlBudgetId = (int)$transaction->transaction_journal_budget_id;
|
||||
$transBudgetId = (int)$transaction->transaction_budget_id;
|
||||
$currencyName = $transaction->transaction_currency_name;
|
||||
$budgetId = max($jrnlBudgetId, $transBudgetId);
|
||||
$combi = $budgetId . $currencyName;
|
||||
$budgetIds[] = $budgetId;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$chartData = [];
|
||||
$result = [];
|
||||
$budgetIds = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyName = $journal['currency_name'];
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$combi = $budgetId . $currencyName;
|
||||
$budgetIds[] = $budgetId;
|
||||
if (!isset($result[$combi])) {
|
||||
$result[$combi] = [
|
||||
'total' => '0',
|
||||
'budget_id' => $budgetId,
|
||||
'currency' => $currencyName,
|
||||
'currency_symbol' => $transaction->transaction_currency_symbol,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
];
|
||||
}
|
||||
$result[$combi]['total'] = bcadd($transaction->transaction_amount, $result[$combi]['total']);
|
||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
||||
}
|
||||
|
||||
$names = $this->getBudgetNames($budgetIds);
|
||||
@ -236,28 +248,27 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Expenses per budget for all time, as shown on account overview.
|
||||
* Expenses grouped by category for account.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function expenseBudgetAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
{
|
||||
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now();
|
||||
|
||||
return $this->expenseBudget($account, $start, $end);
|
||||
return $this->expenseCategory($account, $start, $end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expenses per category for one single account.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
@ -272,20 +283,18 @@ class AccountController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$categoryIds = [];
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$categoryIds = [];
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
|
||||
$transCatId = (int)$transaction->transaction_category_id;
|
||||
$currencyName = $transaction->transaction_currency_name;
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$currencyName = $journal['currency_name'];
|
||||
$categoryId = $journal['category_id'];
|
||||
$combi = $categoryId . $currencyName;
|
||||
$categoryIds[] = $categoryId;
|
||||
if (!isset($result[$combi])) {
|
||||
@ -293,10 +302,10 @@ class AccountController extends Controller
|
||||
'total' => '0',
|
||||
'category_id' => $categoryId,
|
||||
'currency' => $currencyName,
|
||||
'currency_symbol' => $transaction->transaction_currency_symbol,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
];
|
||||
}
|
||||
$result[$combi]['total'] = bcadd($transaction->transaction_amount, $result[$combi]['total']);
|
||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames($categoryIds);
|
||||
@ -314,23 +323,6 @@ class AccountController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expenses grouped by category for account.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function expenseCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
{
|
||||
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now();
|
||||
|
||||
return $this->expenseCategory($account, $start, $end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows the balances for all the user's frontpage accounts.
|
||||
*
|
||||
@ -348,7 +340,7 @@ class AccountController extends Controller
|
||||
|
||||
|
||||
Log::debug('Frontpage preference set is ', $frontPage->data);
|
||||
if (0 === \count($frontPage->data)) {
|
||||
if (0 === count($frontPage->data)) {
|
||||
$frontPage->data = $defaultSet;
|
||||
Log::debug('frontpage set is empty!');
|
||||
$frontPage->save();
|
||||
@ -358,13 +350,28 @@ class AccountController extends Controller
|
||||
return response()->json($this->accountBalanceChart($accounts, $start, $end));
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the income grouped by category for an account, in all time.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
{
|
||||
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now();
|
||||
|
||||
return $this->incomeCategory($account, $start, $end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows all income per account for each category.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
@ -380,19 +387,18 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
// grab all journals:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]);
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$categoryIds = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
|
||||
$transCatId = (int)$transaction->transaction_category_id;
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$currencyName = $transaction->transaction_currency_name;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
$categoryIds = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$categoryId = $journal['category_id'];
|
||||
$currencyName = $journal['currency_name'];
|
||||
$combi = $categoryId . $currencyName;
|
||||
$categoryIds[] = $categoryId;
|
||||
if (!isset($result[$combi])) {
|
||||
@ -400,10 +406,10 @@ class AccountController extends Controller
|
||||
'total' => '0',
|
||||
'category_id' => $categoryId,
|
||||
'currency' => $currencyName,
|
||||
'currency_symbol' => $transaction->transaction_currency_symbol,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
];
|
||||
}
|
||||
$result[$combi]['total'] = bcadd($transaction->transaction_amount, $result[$combi]['total']);
|
||||
$result[$combi]['total'] = bcadd($journal['amount'], $result[$combi]['total']);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames($categoryIds);
|
||||
@ -419,32 +425,15 @@ class AccountController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the income grouped by category for an account, in all time.
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function incomeCategoryAll(AccountRepositoryInterface $repository, Account $account): JsonResponse
|
||||
{
|
||||
$start = $repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
|
||||
$end = Carbon::now();
|
||||
|
||||
return $this->incomeCategory($account, $start, $end);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shows overview of account during a single period.
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $start
|
||||
*
|
||||
* @param Carbon $end
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@ -502,8 +491,8 @@ class AccountController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -579,7 +568,7 @@ class AccountController extends Controller
|
||||
|
||||
// loop all found currencies and build the data array for the chart.
|
||||
/**
|
||||
* @var int $currencyId
|
||||
* @var int $currencyId
|
||||
* @var TransactionCurrency $currency
|
||||
*/
|
||||
foreach ($currencies as $currencyId => $currency) {
|
||||
|
@ -24,15 +24,13 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class BillController.
|
||||
@ -99,12 +97,11 @@ class BillController extends Controller
|
||||
/**
|
||||
* Shows overview for a single bill.
|
||||
*
|
||||
* @param TransactionCollectorInterface $collector
|
||||
* @param Bill $bill
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function single(TransactionCollectorInterface $collector, Bill $bill): JsonResponse
|
||||
public function single(Bill $bill): JsonResponse
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('chart.bill.single');
|
||||
@ -113,23 +110,18 @@ class BillController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$results = $collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->getTransactions();
|
||||
// TODO remove me
|
||||
/** @var Collection $results */
|
||||
$results = $results->sortBy(
|
||||
function (Transaction $transaction) {
|
||||
return $transaction->date->format('U');
|
||||
}
|
||||
);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$journals = $collector->setBill($bill)->getExtractedJournals();
|
||||
|
||||
$chartData = [
|
||||
['type' => 'bar', 'label' => (string)trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
|
||||
['type' => 'bar', 'label' => (string)trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
|
||||
['type' => 'line', 'label' => (string)trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, 'entries' => []],
|
||||
];
|
||||
|
||||
/** @var Transaction $entry */
|
||||
foreach ($results as $entry) {
|
||||
$date = $entry->date->formatLocalized((string)trans('config.month_and_day'));
|
||||
foreach ($journals as $journal) {
|
||||
$date = $journal['date']->formatLocalized((string)trans('config.month_and_day'));
|
||||
$chartData[0]['entries'][$date] = $bill->amount_min; // minimum amount of bill
|
||||
$chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill
|
||||
|
||||
@ -137,7 +129,7 @@ class BillController extends Controller
|
||||
if (!isset($chartData[2]['entries'][$date])) {
|
||||
$chartData[2]['entries'][$date] = '0';
|
||||
}
|
||||
$amount = bcmul($entry->transaction_amount, '-1');
|
||||
$amount = bcmul($journal['amount'], '-1');
|
||||
$chartData[2]['entries'][$date] = bcadd($chartData[2]['entries'][$date], $amount); // amount of journal
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,10 @@ namespace FireflyIII\Http\Controllers\Chart;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
@ -128,7 +127,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -177,7 +176,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit|null $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -195,21 +194,20 @@ class BudgetController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setBudget($budget);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setBudget($budget);
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$assetId = (int)$transaction->account_id;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
foreach ($journals as $journal) {
|
||||
$assetId = (int)$journal['destination_account_id'];
|
||||
$result[$assetId] = $result[$assetId] ?? '0';
|
||||
$result[$assetId] = bcadd($transaction->transaction_amount, $result[$assetId]);
|
||||
$result[$assetId] = bcadd($journal['amount'], $result[$assetId]);
|
||||
}
|
||||
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
@ -229,7 +227,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit|null $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -247,23 +245,20 @@ class BudgetController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setBudget($budget)->withCategoryInformation();
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setBudget($budget)->withCategoryInformation();
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
|
||||
$transCatId = (int)$transaction->transaction_category_id;
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
foreach ($journals as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
||||
$result[$categoryId] = bcadd($transaction->transaction_amount, $result[$categoryId]);
|
||||
$result[$categoryId] = bcadd($journal['amount'], $result[$categoryId]);
|
||||
}
|
||||
|
||||
$names = $this->getCategoryNames(array_keys($result));
|
||||
@ -282,7 +277,7 @@ class BudgetController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Budget $budget
|
||||
* @param BudgetLimit|null $budgetLimit
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -300,21 +295,22 @@ class BudgetController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withOpposingAccount();
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
|
||||
if (null !== $budgetLimit) {
|
||||
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
|
||||
}
|
||||
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$opposingId = (int)$transaction->opposing_account_id;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [];
|
||||
$chartData = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$opposingId = (int)$journal['destination_account_id'];
|
||||
$result[$opposingId] = $result[$opposingId] ?? '0';
|
||||
$result[$opposingId] = bcadd($transaction->transaction_amount, $result[$opposingId]);
|
||||
$result[$opposingId] = bcadd($journal['amount'], $result[$opposingId]);
|
||||
}
|
||||
|
||||
$names = $this->getAccountNames(array_keys($result));
|
||||
@ -392,9 +388,9 @@ class BudgetController extends Controller
|
||||
*
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Budget $budget
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return JsonResponse
|
||||
@ -441,8 +437,8 @@ class BudgetController extends Controller
|
||||
* TODO this chart is not multi-currency aware.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
|
@ -201,7 +201,7 @@ class BudgetReportController extends Controller
|
||||
$chartData[$budget->id]['entries'][$label] = bcmul($currentExpenses, '-1');
|
||||
$chartData[$budget->id . '-sum']['entries'][$label] = bcmul($sumOfExpenses[$budget->id], '-1');
|
||||
|
||||
if (\count($budgetLimits) > 0) {
|
||||
if (count($budgetLimits) > 0) {
|
||||
$budgetLimitId = $budgetLimits->first()->id;
|
||||
$leftOfLimits[$budgetLimitId] = $leftOfLimits[$budgetLimitId] ?? (string)$budgetLimits->sum('amount');
|
||||
$leftOfLimits[$budgetLimitId] = bcadd($leftOfLimits[$budgetLimitId], $currentExpenses);
|
||||
|
@ -188,7 +188,7 @@ class ExpenseReportController extends Controller
|
||||
$newSet[$key] = $chartData[$key];
|
||||
}
|
||||
}
|
||||
if (0 === \count($newSet)) {
|
||||
if (0 === count($newSet)) {
|
||||
$newSet = $chartData; // @codeCoverageIgnore
|
||||
}
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
|
@ -200,7 +200,7 @@ class TagReportController extends Controller
|
||||
$cache->addProperty($start);
|
||||
$cache->addProperty($end);
|
||||
if ($cache->has()) {
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
//return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
|
||||
@ -254,7 +254,7 @@ class TagReportController extends Controller
|
||||
$labelOut = $tag->id . '-out';
|
||||
$labelSumIn = $tag->id . '-total-in';
|
||||
$labelSumOut = $tag->id . '-total-out';
|
||||
$currentIncome = $income[$tag->id] ?? '0';
|
||||
$currentIncome = bcmul($income[$tag->id] ?? '0','-1');
|
||||
$currentExpense = $expenses[$tag->id] ?? '0';
|
||||
|
||||
// add to sum:
|
||||
@ -272,6 +272,8 @@ class TagReportController extends Controller
|
||||
/** @var Carbon $currentStart */
|
||||
$currentStart = clone $currentEnd;
|
||||
$currentStart->addDay();
|
||||
$currentStart->startOfDay();
|
||||
|
||||
}
|
||||
// remove all empty entries to prevent cluttering:
|
||||
$newSet = [];
|
||||
@ -280,7 +282,7 @@ class TagReportController extends Controller
|
||||
$newSet[$key] = $chartData[$key];
|
||||
}
|
||||
}
|
||||
if (0 === \count($newSet)) {
|
||||
if (0 === count($newSet)) {
|
||||
$newSet = $chartData; // @codeCoverageIgnore
|
||||
}
|
||||
$data = $this->generator->multiSet($newSet);
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Json;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@ -98,12 +98,10 @@ class AutoCompleteController extends Controller
|
||||
/**
|
||||
* List of all journals.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TransactionCollectorInterface $collector
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function allTransactionJournals(Request $request, TransactionCollectorInterface $collector): JsonResponse
|
||||
public function allTransactionJournals(Request $request): JsonResponse
|
||||
{
|
||||
$search = (string)$request->get('search');
|
||||
$cache = new CacheProperties;
|
||||
@ -115,8 +113,22 @@ class AutoCompleteController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
// find everything:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setLimit(250)->setPage(1);
|
||||
$return = array_values(array_unique($collector->getTransactions()->pluck('description')->toArray()));
|
||||
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
if (strlen($journal['group_title']) > 0) {
|
||||
$return[] = $journal['group_title'];
|
||||
}
|
||||
if (strlen($journal['description']) > 0) {
|
||||
$return[] = $journal['description'];
|
||||
}
|
||||
}
|
||||
$return = array_unique($return);
|
||||
|
||||
if ('' !== $search) {
|
||||
$return = array_values(
|
||||
@ -136,7 +148,7 @@ class AutoCompleteController extends Controller
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $subject
|
||||
* @param string $subject
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
@ -250,13 +262,12 @@ class AutoCompleteController extends Controller
|
||||
/**
|
||||
* List of journals with their ID.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TransactionCollectorInterface $collector
|
||||
* @param TransactionJournal $except
|
||||
* @param Request $request
|
||||
* @param TransactionJournal $except
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function journalsWithId(Request $request, TransactionCollectorInterface $collector, TransactionJournal $except): JsonResponse
|
||||
public function journalsWithId(Request $request, TransactionJournal $except): JsonResponse
|
||||
{
|
||||
$search = (string)$request->get('search');
|
||||
$cache = new CacheProperties;
|
||||
@ -268,15 +279,17 @@ class AutoCompleteController extends Controller
|
||||
return response()->json($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
// find everything:
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setLimit(400)->setPage(1);
|
||||
$set = $collector->getTransactions()->pluck('description', 'journal_id')->toArray();
|
||||
$set = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
foreach ($set as $id => $description) {
|
||||
$id = (int)$id;
|
||||
foreach ($set as $journal) {
|
||||
$id = (int)$journal['transaction_journal_id'];
|
||||
if ($id !== $except->id) {
|
||||
$return[] = [
|
||||
'id' => $id,
|
||||
'name' => $id . ': ' . $description,
|
||||
'name' => $id . ': ' . $journal['description'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -327,13 +340,12 @@ class AutoCompleteController extends Controller
|
||||
/**
|
||||
* List of journals by type.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param TransactionCollectorInterface $collector
|
||||
* @param string $what
|
||||
* @param Request $request
|
||||
* @param string $what
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function transactionJournals(Request $request, TransactionCollectorInterface $collector, string $what): JsonResponse
|
||||
public function transactionJournals(Request $request, string $what): JsonResponse
|
||||
{
|
||||
$search = (string)$request->get('search');
|
||||
$cache = new CacheProperties;
|
||||
@ -348,8 +360,15 @@ class AutoCompleteController extends Controller
|
||||
$type = config('firefly.transactionTypesByWhat.' . $what);
|
||||
$types = [$type];
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setTypes($types)->setLimit(250)->setPage(1);
|
||||
$return = array_unique($collector->getTransactions()->pluck('description')->toArray());
|
||||
$result = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
foreach ($result as $journal) {
|
||||
$return[] = $journal['description'];
|
||||
}
|
||||
$return = array_unique($return);
|
||||
sort($return);
|
||||
|
||||
if ('' !== $search) {
|
||||
|
@ -23,12 +23,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@ -134,35 +133,33 @@ class BoxController extends Controller
|
||||
$sums = [];
|
||||
|
||||
// collect income of user:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)
|
||||
->setTypes([TransactionType::DEPOSIT])
|
||||
->withOpposingAccount();
|
||||
$set = $collector->getTransactions();
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes([TransactionType::DEPOSIT]);
|
||||
$set = $collector->getExtractedJournals();
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$incomes[$currencyId] = $incomes[$currencyId] ?? '0';
|
||||
$incomes[$currencyId] = bcadd($incomes[$currencyId], $transaction->transaction_amount);
|
||||
$incomes[$currencyId] = bcadd($incomes[$currencyId], $journal['amount']);
|
||||
$sums[$currencyId] = $sums[$currencyId] ?? '0';
|
||||
$sums[$currencyId] = bcadd($sums[$currencyId], $transaction->transaction_amount);
|
||||
$sums[$currencyId] = bcadd($sums[$currencyId], $journal['amount']);
|
||||
}
|
||||
|
||||
// collect expenses
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->withOpposingAccount();
|
||||
$set = $collector->getTransactions();
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$set = $collector->getExtractedJournals();
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$expenses[$currencyId] = $expenses[$currencyId] ?? '0';
|
||||
$expenses[$currencyId] = bcadd($expenses[$currencyId], $transaction->transaction_amount);
|
||||
$expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount']);
|
||||
$sums[$currencyId] = $sums[$currencyId] ?? '0';
|
||||
$sums[$currencyId] = bcadd($sums[$currencyId], $transaction->transaction_amount);
|
||||
$sums[$currencyId] = bcadd($sums[$currencyId], $journal['amount']);
|
||||
}
|
||||
|
||||
// format amounts:
|
||||
@ -173,7 +170,7 @@ class BoxController extends Controller
|
||||
$incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false);
|
||||
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
|
||||
}
|
||||
if (0 === \count($sums)) {
|
||||
if (0 === count($sums)) {
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
$sums[$currency->id] = app('amount')->formatAnything($currency, '0', false);
|
||||
$incomes[$currency->id] = app('amount')->formatAnything($currency, '0', false);
|
||||
@ -184,7 +181,7 @@ class BoxController extends Controller
|
||||
'incomes' => $incomes,
|
||||
'expenses' => $expenses,
|
||||
'sums' => $sums,
|
||||
'size' => \count($sums),
|
||||
'size' => count($sums),
|
||||
];
|
||||
|
||||
|
||||
|
@ -64,7 +64,7 @@ class FrontpageController extends Controller
|
||||
}
|
||||
}
|
||||
$html = '';
|
||||
if (\count($info) > 0) {
|
||||
if (count($info) > 0) {
|
||||
try {
|
||||
$html = view('json.piggy-banks', compact('info'))->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@ -47,7 +47,7 @@ class IntroController
|
||||
$specificPage = $specificPage ?? '';
|
||||
$steps = $this->getBasicSteps($route);
|
||||
$specificSteps = $this->getSpecificSteps($route, $specificPage);
|
||||
if (0 === \count($specificSteps)) {
|
||||
if (0 === count($specificSteps)) {
|
||||
Log::debug(sprintf('No specific steps for route "%s" and page "%s"', $route, $specificPage));
|
||||
|
||||
return response()->json($steps);
|
||||
@ -55,7 +55,7 @@ class IntroController
|
||||
if ($this->hasOutroStep($route)) {
|
||||
// @codeCoverageIgnoreStart
|
||||
// save last step:
|
||||
$lastStep = $steps[\count($steps) - 1];
|
||||
$lastStep = $steps[count($steps) - 1];
|
||||
// remove last step:
|
||||
array_pop($steps);
|
||||
// merge arrays and add last step again
|
||||
|
@ -26,7 +26,7 @@ namespace FireflyIII\Http\Controllers\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@ -44,7 +44,7 @@ use Throwable;
|
||||
/**
|
||||
*
|
||||
* Class ReconcileController
|
||||
*
|
||||
* TODO needs a full rewrite
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ReconcileController extends Controller
|
||||
@ -84,8 +84,8 @@ class ReconcileController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
@ -189,8 +189,8 @@ class ReconcileController extends Controller
|
||||
* Returns a list of transactions in a modal.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
@ -220,14 +220,15 @@ class ReconcileController extends Controller
|
||||
$selectionEnd->addDays(3);
|
||||
|
||||
// grab transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts(new Collection([$account]))
|
||||
->setRange($selectionStart, $selectionEnd)->withBudgetInformation()->withOpposingAccount()->withCategoryInformation();
|
||||
$transactions = $collector->getTransactions();
|
||||
->setRange($selectionStart, $selectionEnd)->withBudgetInformation()->withCategoryInformation();
|
||||
$groups = $collector->getGroups();
|
||||
try {
|
||||
$html = view(
|
||||
'accounts.reconcile.transactions', compact('account', 'transactions', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
|
||||
'accounts.reconcile.transactions', compact('account', 'groups', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
|
||||
)->render();
|
||||
// @codeCoverageIgnoreStart
|
||||
} catch (Throwable $e) {
|
||||
|
@ -72,7 +72,7 @@ class PreferencesController extends Controller
|
||||
|
||||
// an important fallback is that the frontPageAccount array gets refilled automatically
|
||||
// when it turns up empty.
|
||||
if (0 === \count($frontPageAccounts->data)) {
|
||||
if (0 === count($frontPageAccounts->data)) {
|
||||
$frontPageAccounts = $accountIds;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ class PreferencesController extends Controller
|
||||
{
|
||||
// front page accounts
|
||||
$frontPageAccounts = [];
|
||||
if (\is_array($request->get('frontPageAccounts')) && \count($request->get('frontPageAccounts')) > 0) {
|
||||
if (\is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) {
|
||||
foreach ($request->get('frontPageAccounts') as $id) {
|
||||
$frontPageAccounts[] = (int)$id;
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ class CreateController extends Controller
|
||||
$oldActions = $this->getPreviousActions($request);
|
||||
}
|
||||
|
||||
$triggerCount = \count($oldTriggers);
|
||||
$actionCount = \count($oldActions);
|
||||
$triggerCount = count($oldTriggers);
|
||||
$actionCount = count($oldActions);
|
||||
$subTitleIcon = 'fa-clone';
|
||||
|
||||
// title depends on whether or not there is a rule group:
|
||||
@ -140,8 +140,8 @@ class CreateController extends Controller
|
||||
$oldTriggers = $this->getTriggersForBill($bill);
|
||||
$oldActions = $this->getActionsForBill($bill);
|
||||
|
||||
$triggerCount = \count($oldTriggers);
|
||||
$actionCount = \count($oldActions);
|
||||
$triggerCount = count($oldTriggers);
|
||||
$actionCount = count($oldActions);
|
||||
$subTitleIcon = 'fa-clone';
|
||||
|
||||
// title depends on whether or not there is a rule group:
|
||||
|
@ -79,19 +79,19 @@ class EditController extends Controller
|
||||
$oldActions = [];
|
||||
$oldTriggers = [];
|
||||
// has old input?
|
||||
if (\count($request->old()) > 0) {
|
||||
if (count($request->old()) > 0) {
|
||||
$oldTriggers = $this->getPreviousTriggers($request);
|
||||
$triggerCount = \count($oldTriggers);
|
||||
$triggerCount = count($oldTriggers);
|
||||
$oldActions = $this->getPreviousActions($request);
|
||||
$actionCount = \count($oldActions);
|
||||
$actionCount = count($oldActions);
|
||||
}
|
||||
|
||||
// overrule old input when it has no rule data:
|
||||
if (0 === $triggerCount && 0 === $actionCount) {
|
||||
$oldTriggers = $this->getCurrentTriggers($rule);
|
||||
$triggerCount = \count($oldTriggers);
|
||||
$triggerCount = count($oldTriggers);
|
||||
$oldActions = $this->getCurrentActions($rule);
|
||||
$actionCount = \count($oldActions);
|
||||
$actionCount = count($oldActions);
|
||||
}
|
||||
|
||||
$hasOldInput = null !== $request->old('_token');
|
||||
|
@ -145,7 +145,7 @@ class SelectController extends Controller
|
||||
// build trigger array from response
|
||||
$triggers = $this->getValidTriggerList($request);
|
||||
|
||||
if (0 === \count($triggers)) {
|
||||
if (0 === count($triggers)) {
|
||||
return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ class SelectController extends Controller
|
||||
{
|
||||
$triggers = $rule->ruleTriggers;
|
||||
|
||||
if (0 === \count($triggers)) {
|
||||
if (0 === count($triggers)) {
|
||||
return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Requests\TagFormRequest;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
@ -171,8 +170,8 @@ class TagController extends Controller
|
||||
/**
|
||||
* Show a single tag.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Tag $tag
|
||||
* @param Request $request
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@ -196,23 +195,23 @@ class TagController extends Controller
|
||||
$periods = $this->getTagPeriodOverview($tag, $start);
|
||||
$path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||
->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath($path);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withAccountInformation()
|
||||
->setTag($tag)->withBudgetInformation()->withCategoryInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
$sums = $this->repository->sumsOfTag($tag, $start, $end);
|
||||
|
||||
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end'));
|
||||
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single tag over all time.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
@ -230,15 +229,15 @@ class TagController extends Controller
|
||||
$start = $this->repository->firstUseDate($tag) ?? new Carbon;
|
||||
$end = new Carbon;
|
||||
$path = route('tags.show', [$tag->id, 'all']);
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||
->setTag($tag)->withBudgetInformation()->withCategoryInformation()->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath($path);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withAccountInformation()
|
||||
->setTag($tag)->withBudgetInformation()->withCategoryInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
$sums = $this->repository->sumsOfTag($tag, $start, $end);
|
||||
|
||||
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'transactions', 'start', 'end'));
|
||||
return view('tags.show', compact('tag', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,7 +275,7 @@ class TagController extends Controller
|
||||
* Update a tag.
|
||||
*
|
||||
* @param TagFormRequest $request
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
|
@ -27,7 +27,7 @@ namespace FireflyIII\Http\Controllers\Transaction;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@ -37,20 +37,21 @@ use Illuminate\Http\Request;
|
||||
class IndexController extends Controller
|
||||
{
|
||||
use PeriodOverview;
|
||||
|
||||
/**
|
||||
* Index for a range of transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $transactionType
|
||||
* @param Request $request
|
||||
* @param string $objectType
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(Request $request, string $transactionType, Carbon $start = null, Carbon $end = null)
|
||||
public function index(Request $request, string $objectType, Carbon $start = null, Carbon $end = null)
|
||||
{
|
||||
$subTitleIcon = config('firefly.transactionIconsByType.' . $transactionType);
|
||||
$types = config('firefly.transactionTypesByType.' . $transactionType);
|
||||
$subTitleIcon = config('firefly.transactionIconsByType.' . $objectType);
|
||||
$types = config('firefly.transactionTypesByType.' . $objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
if (null === $start) {
|
||||
@ -65,13 +66,12 @@ class IndexController extends Controller
|
||||
[$start, $end] = [$end, $start];
|
||||
}
|
||||
|
||||
$path = route('transactions.index', [$transactionType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
|
||||
|
||||
$startStr = $start->formatLocalized($this->monthAndDayFormat);
|
||||
$endStr = $end->formatLocalized($this->monthAndDayFormat);
|
||||
$subTitle = (string)trans(sprintf('firefly.title_%s_between',$transactionType), ['start' => $startStr, 'end' => $endStr]);
|
||||
|
||||
$periods = $this->getTransactionPeriodOverview($transactionType, $end);
|
||||
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
|
||||
$periods = $this->getTransactionPeriodOverview($objectType, $end);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
@ -86,6 +86,42 @@ class IndexController extends Controller
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
|
||||
return view('transactions.index', compact('subTitle', 'transactionType', 'subTitleIcon', 'groups', 'periods', 'start', 'end'));
|
||||
return view('transactions.index', compact('subTitle', 'objectType', 'subTitleIcon', 'groups', 'periods', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Index for ALL transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $objectType
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function indexAll(Request $request, string $objectType)
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
|
||||
|
||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $objectType);
|
||||
$types = config('firefly.transactionTypesByWhat.' . $objectType);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$path = route('transactions.index.all', [$objectType]);
|
||||
$first = $repository->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$end = new Carbon;
|
||||
$subTitle = (string)trans('firefly.all_' . $objectType);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setRange($start, $end)
|
||||
->setTypes($types)->setLimit($pageSize)->setPage($page)->withAccountInformation()
|
||||
->withBudgetInformation()->withCategoryInformation();
|
||||
$groups = $collector->getPaginatedGroups();
|
||||
$groups->setPath($path);
|
||||
|
||||
return view('transactions.index', compact('subTitle', 'objectType', 'subTitleIcon', 'groups', 'start', 'end'));
|
||||
}
|
||||
}
|
@ -393,11 +393,11 @@ class SingleController extends Controller
|
||||
|
||||
// store the journal only, flash the rest.
|
||||
Log::debug(sprintf('Count of error messages is %d', $this->attachments->getErrors()->count()));
|
||||
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
// flash messages
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
|
||||
@ -460,10 +460,10 @@ class SingleController extends Controller
|
||||
$this->attachments->saveAttachmentsForModel($journal, $files);
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getErrors()->get('attachments')) > 0) {
|
||||
session()->flash('error', $this->attachments->getErrors()->get('attachments'));
|
||||
}
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -152,7 +152,7 @@ class SplitController extends Controller
|
||||
|
||||
// flash messages
|
||||
// @codeCoverageIgnoreStart
|
||||
if (\count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
|
||||
session()->flash('info', $this->attachments->getMessages()->get('attachments'));
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
@ -25,19 +25,12 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\CountAttachmentsFilter;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Filter\SplitIndicatorFilter;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Controllers\ModelInformation;
|
||||
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@ -72,40 +65,6 @@ class TransactionController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index for ALL transactions.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function indexAll(Request $request, string $what)
|
||||
{
|
||||
throw new FireflyException('Do not use me.');
|
||||
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
|
||||
$types = config('firefly.transactionTypesByWhat.' . $what);
|
||||
$page = (int)$request->get('page');
|
||||
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
|
||||
$path = route('transactions.index.all', [$what]);
|
||||
$first = $this->repository->firstNull();
|
||||
$start = null === $first ? new Carbon : $first->date;
|
||||
$end = new Carbon;
|
||||
$subTitle = (string)trans('firefly.all_' . $what);
|
||||
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAllAssetAccounts()->setRange($start, $end)
|
||||
->setTypes($types)->setLimit($pageSize)->setPage($page)->withOpposingAccount()
|
||||
->withBudgetInformation()->withCategoryInformation();
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$collector->addFilter(SplitIndicatorFilter::class);
|
||||
$collector->addFilter(CountAttachmentsFilter::class);
|
||||
$transactions = $collector->getPaginatedTransactions();
|
||||
$transactions->setPath($path);
|
||||
|
||||
return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'transactions', 'start', 'end'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a reconciliation.
|
||||
@ -141,7 +100,7 @@ class TransactionController extends Controller
|
||||
{
|
||||
$ids = $request->get('items');
|
||||
$date = new Carbon($request->get('date'));
|
||||
if (\count($ids) > 0) {
|
||||
if (count($ids) > 0) {
|
||||
$order = 0;
|
||||
$ids = array_unique($ids);
|
||||
foreach ($ids as $id) {
|
||||
|
@ -130,7 +130,7 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon;
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string)$range);
|
||||
if (2 === \count($parts)) {
|
||||
if (2 === count($parts)) {
|
||||
try {
|
||||
$date = new Carbon($parts[1]);
|
||||
// @codeCoverageIgnoreStart
|
||||
@ -181,7 +181,7 @@ class ReportFormRequest extends Request
|
||||
$date = new Carbon;
|
||||
$range = $this->get('daterange');
|
||||
$parts = explode(' - ', (string)$range);
|
||||
if (2 === \count($parts)) {
|
||||
if (2 === count($parts)) {
|
||||
try {
|
||||
$date = new Carbon($parts[0]);
|
||||
// @codeCoverageIgnoreStart
|
||||
|
@ -100,8 +100,8 @@ class FakeJobConfiguration implements JobConfigurationInterface
|
||||
$this->repository->setConfiguration($this->importJob, $configuration);
|
||||
$messages = new MessageBag();
|
||||
|
||||
if (3 !== \count($configuration)) {
|
||||
$messages->add('some_key', 'Ignore this error: ' . \count($configuration));
|
||||
if (3 !== count($configuration)) {
|
||||
$messages->add('some_key', 'Ignore this error: ' . count($configuration));
|
||||
}
|
||||
|
||||
return $messages;
|
||||
|
@ -83,14 +83,14 @@ class YnabRoutine implements RoutineInterface
|
||||
$budgets = $configuration['budgets'] ?? [];
|
||||
|
||||
// if more than 1 budget, select budget first.
|
||||
if (\count($budgets) > 1) {
|
||||
if (count($budgets) > 1) {
|
||||
$this->repository->setStage($this->importJob, 'select_budgets');
|
||||
$this->repository->setStatus($this->importJob, 'need_job_config');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (1 === \count($budgets)) {
|
||||
if (1 === count($budgets)) {
|
||||
$this->repository->setStatus($this->importJob, 'ready_to_run');
|
||||
$this->repository->setStage($this->importJob, 'get_accounts');
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ class IngDescription implements SpecificInterface
|
||||
public function run(array $row): array
|
||||
{
|
||||
$this->row = array_values($row);
|
||||
if (\count($this->row) >= 8) { // check if the array is correct
|
||||
if (count($this->row) >= 8) { // check if the array is correct
|
||||
switch ($this->row[4]) { // Get value for the mutation type
|
||||
case 'GT': // InternetBankieren
|
||||
case 'OV': // Overschrijving
|
||||
|
@ -424,7 +424,7 @@ class ImportArrayStorage
|
||||
{
|
||||
/** @var array $array */
|
||||
$array = $this->repository->getTransactions($this->importJob);
|
||||
$count = \count($array);
|
||||
$count = count($array);
|
||||
$toStore = [];
|
||||
|
||||
Log::notice(sprintf('Will now store the transactions. Count of items is %d.', $count));
|
||||
@ -441,7 +441,7 @@ class ImportArrayStorage
|
||||
$transaction['import_hash_v2'] = $this->getHash($transaction);
|
||||
$toStore[] = $transaction;
|
||||
}
|
||||
$count = \count($toStore);
|
||||
$count = count($toStore);
|
||||
if (0 === $count) {
|
||||
Log::info('No transactions to store left!');
|
||||
|
||||
@ -509,13 +509,13 @@ class ImportArrayStorage
|
||||
return false;
|
||||
}
|
||||
// how many hits do we need?
|
||||
Log::debug(sprintf('Array has %d transactions.', \count($transaction['transactions'])));
|
||||
Log::debug(sprintf('System has %d existing transfers', \count($this->transfers)));
|
||||
Log::debug(sprintf('Array has %d transactions.', count($transaction['transactions'])));
|
||||
Log::debug(sprintf('System has %d existing transfers', count($this->transfers)));
|
||||
// loop over each split:
|
||||
Log::debug(sprintf('This transfer has %d split(s)', \count($transaction['transactions'])));
|
||||
Log::debug(sprintf('This transfer has %d split(s)', count($transaction['transactions'])));
|
||||
foreach ($transaction['transactions'] as $index => $current) {
|
||||
Log::debug(sprintf('Required hits for transfer comparison is %d', self::REQUIRED_HITS));
|
||||
Log::debug(sprintf('Now at transfer split %d of %d', $index + 1, \count($transaction['transactions'])));
|
||||
Log::debug(sprintf('Now at transfer split %d of %d', $index + 1, count($transaction['transactions'])));
|
||||
|
||||
// get the amount:
|
||||
/** @noinspection UnnecessaryCastingInspection */
|
||||
|
@ -416,7 +416,7 @@ class CreateRecurringTransactions implements ShouldQueue
|
||||
Log::debug(
|
||||
sprintf(
|
||||
'Calculated %d occurrences between %s and %s',
|
||||
\count($occurrences),
|
||||
count($occurrences),
|
||||
$recurrence->first_date->format('Y-m-d'),
|
||||
$includeWeekend->format('Y-m-d')
|
||||
), $this->debugArray($occurrences)
|
||||
|
@ -332,7 +332,7 @@ class TransactionJournal extends Model
|
||||
if (!self::isJoined($query, 'transaction_types')) {
|
||||
$query->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id');
|
||||
}
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->whereIn('transaction_types.type', $types);
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->where('account_meta.name', 'accountNumber')
|
||||
->where('account_meta.data', json_encode($number));
|
||||
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@ -123,7 +123,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
|
||||
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@ -149,7 +149,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts();
|
||||
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
@ -244,7 +244,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
/** @var Collection $result */
|
||||
$query = $this->user->accounts();
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->orderBy('accounts.name','ASC');
|
||||
@ -267,7 +267,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
$query->where('name', 'accountRole');
|
||||
}]
|
||||
);
|
||||
if (\count($types) > 0) {
|
||||
if (count($types) > 0) {
|
||||
$query->accountTypeIn($types);
|
||||
}
|
||||
$query->where('active', 1);
|
||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Repositories\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -52,8 +53,8 @@ class AccountTasker implements AccountTaskerInterface
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
@ -119,8 +120,8 @@ class AccountTasker implements AccountTaskerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
@ -130,23 +131,15 @@ class AccountTasker implements AccountTaskerInterface
|
||||
// get all expenses for the given accounts in the given period!
|
||||
// also transfers!
|
||||
// get all transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->withOpposingAccount();
|
||||
$transactions = $collector->getTransactions();
|
||||
$transactions = $transactions->filter(
|
||||
function (Transaction $transaction) {
|
||||
// return negative amounts only.
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$expenses = $this->groupByOpposing($transactions);
|
||||
->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$expenses = $this->groupByDestination($journals);
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
@ -161,8 +154,66 @@ class AccountTasker implements AccountTaskerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function groupByDestination(array $array): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency,];
|
||||
$expenses = [];
|
||||
$countAccounts = []; // if count remains 0 use original name, not the name with the currency.
|
||||
|
||||
|
||||
/** @var array $journal */
|
||||
foreach ($array as $journal) {
|
||||
$opposingId = (int)$journal['destination_account_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$key = sprintf('%s-%s', $opposingId, $currencyId);
|
||||
$name = sprintf('%s (%s)', $journal['destination_account_name'], $journal['currency_name']);
|
||||
$countAccounts[$opposingId] = isset($countAccounts[$opposingId]) ? $countAccounts[$opposingId] + 1 : 1;
|
||||
if (!isset($expenses[$key])) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
|
||||
$expenses[$key] = [
|
||||
'id' => $opposingId,
|
||||
'name' => $name,
|
||||
'original' => $journal['destination_account_name'],
|
||||
'sum' => '0',
|
||||
'average' => '0',
|
||||
'currencies' => [],
|
||||
'single_currency' => $currencies[$currencyId],
|
||||
'count' => 0,
|
||||
];
|
||||
}
|
||||
$expenses[$key]['currencies'][] = (int)$journal['currency_id'];
|
||||
$expenses[$key]['sum'] = bcadd($expenses[$key]['sum'], $journal['amount']);
|
||||
++$expenses[$key]['count'];
|
||||
}
|
||||
// do averages:
|
||||
$keys = array_keys($expenses);
|
||||
foreach ($keys as $key) {
|
||||
$opposingId = $expenses[$key]['id'];
|
||||
if (1 === $countAccounts[$opposingId]) {
|
||||
$expenses[$key]['name'] = $expenses[$key]['original'];
|
||||
}
|
||||
|
||||
if ($expenses[$key]['count'] > 1) {
|
||||
$expenses[$key]['average'] = bcdiv($expenses[$key]['sum'], (string)$expenses[$key]['count']);
|
||||
}
|
||||
$expenses[$key]['currencies'] = count(array_unique($expenses[$key]['currencies']));
|
||||
$expenses[$key]['all_currencies'] = count($currencies);
|
||||
}
|
||||
|
||||
return $expenses;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
@ -172,23 +223,14 @@ class AccountTasker implements AccountTaskerInterface
|
||||
// get all expenses for the given accounts in the given period!
|
||||
// also transfers!
|
||||
// get all transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->withOpposingAccount();
|
||||
$transactions = $collector->getTransactions();
|
||||
$transactions = $transactions->filter(
|
||||
function (Transaction $transaction) {
|
||||
// return positive amounts only.
|
||||
if (1 === bccomp($transaction->transaction_amount, '0')) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
);
|
||||
$income = $this->groupByOpposing($transactions);
|
||||
->withAccountInformation();
|
||||
$income = $this->groupByDestination($collector->getExtractedJournals());
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
@ -209,62 +251,4 @@ class AccountTasker implements AccountTaskerInterface
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $transactions
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function groupByOpposing(Collection $transactions): array
|
||||
{
|
||||
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($this->user);
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
$currencies = [$defaultCurrency->id => $defaultCurrency,];
|
||||
$expenses = [];
|
||||
$countAccounts = []; // if count remains 0 use original name, not the name with the currency.
|
||||
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$opposingId = (int)$transaction->opposing_account_id;
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
$key = sprintf('%s-%s', $opposingId, $currencyId);
|
||||
$name = sprintf('%s (%s)', $transaction->opposing_account_name, $transaction->transaction_currency_code);
|
||||
$countAccounts[$opposingId] = isset($countAccounts[$opposingId]) ? $countAccounts[$opposingId] + 1 : 1;
|
||||
if (!isset($expenses[$key])) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
|
||||
$expenses[$key] = [
|
||||
'id' => $opposingId,
|
||||
'name' => $name,
|
||||
'original' => $transaction->opposing_account_name,
|
||||
'sum' => '0',
|
||||
'average' => '0',
|
||||
'currencies' => [],
|
||||
'single_currency' => $currencies[$currencyId],
|
||||
'count' => 0,
|
||||
];
|
||||
}
|
||||
$expenses[$key]['currencies'][] = (int)$transaction->transaction_currency_id;
|
||||
$expenses[$key]['sum'] = bcadd($expenses[$key]['sum'], $transaction->transaction_amount);
|
||||
++$expenses[$key]['count'];
|
||||
}
|
||||
// do averages:
|
||||
$keys = array_keys($expenses);
|
||||
foreach ($keys as $key) {
|
||||
$opposingId = $expenses[$key]['id'];
|
||||
if (1 === $countAccounts[$opposingId]) {
|
||||
$expenses[$key]['name'] = $expenses[$key]['original'];
|
||||
}
|
||||
|
||||
if ($expenses[$key]['count'] > 1) {
|
||||
$expenses[$key]['average'] = bcdiv($expenses[$key]['sum'], (string)$expenses[$key]['count']);
|
||||
}
|
||||
$expenses[$key]['currencies'] = \count(array_unique($expenses[$key]['currencies']));
|
||||
$expenses[$key]['all_currencies'] = \count($currencies);
|
||||
}
|
||||
|
||||
return $expenses;
|
||||
}
|
||||
}
|
||||
|
@ -155,21 +155,17 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
return $collector->getSum();
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -719,7 +715,6 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriodMc(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
@ -777,30 +772,17 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriodWoBudget(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->withoutBudget();
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])
|
||||
->withoutBudget();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$set = $set->filter(
|
||||
function (Transaction $transaction) {
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
return $collector->getSum();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,7 @@ namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Factory\CategoryFactory;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -77,8 +78,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -86,34 +87,46 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
$set = $this->earnedInPeriodCollection($categories, $accounts, $start, $end);
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
return $this->sumJournals($set);
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
if (0 !== $accounts->count()) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setCategories($categories);
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $journals
|
||||
* @return string
|
||||
*/
|
||||
private function sumJournals(array $journals): string
|
||||
{
|
||||
$sum = '0';
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = (string)$journal['amount'];
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,8 +135,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
* Get me the amount earned in this period, grouped per currency, where no category was set.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -174,8 +187,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -234,26 +247,20 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Category|null
|
||||
* @return Collection
|
||||
*/
|
||||
public function findByName(string $name): ?Category
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
$categories = $this->user->categories()->get(['categories.*']);
|
||||
foreach ($categories as $category) {
|
||||
if ($category->name === $name) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->categories()->orderBy('name', 'ASC')->get();
|
||||
|
||||
return null;
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $categoryId
|
||||
* @param int|null $categoryId
|
||||
* @param string|null $categoryName
|
||||
*
|
||||
* @return Category|null
|
||||
@ -279,6 +286,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Find a category or return NULL
|
||||
*
|
||||
@ -291,8 +300,41 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $this->user->categories()->find($categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Category|null
|
||||
*/
|
||||
public function findByName(string $name): ?Category
|
||||
{
|
||||
$categories = $this->user->categories()->get(['categories.*']);
|
||||
foreach ($categories as $category) {
|
||||
if ($category->name === $name) {
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data): Category
|
||||
{
|
||||
/** @var CategoryFactory $factory */
|
||||
$factory = app(CategoryFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
return $factory->findOrCreate(null, $data['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@ -321,6 +363,47 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $firstJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getFirstJournalDate(Category $category): ?Carbon
|
||||
{
|
||||
$query = $category->transactionJournals()->orderBy('date', 'ASC');
|
||||
$result = $query->first(['transaction_journals.*']);
|
||||
|
||||
if (null !== $result) {
|
||||
return $result->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getFirstTransactionDate(Category $category): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'ASC');
|
||||
|
||||
$lastTransaction = $query->first(['transaction_journals.*']);
|
||||
if (null !== $lastTransaction) {
|
||||
return new Carbon($lastTransaction->date);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Get all categories with ID's.
|
||||
*
|
||||
@ -336,20 +419,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getCategories(): Collection
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->categories()->orderBy('name', 'ASC')->get();
|
||||
|
||||
return $set;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
@ -378,11 +448,61 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $lastJournalDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getLastJournalDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
$query = $category->transactionJournals()->orderBy('date', 'DESC');
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$query->leftJoin('transactions as t', 't.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$query->whereIn('t.account_id', $accounts->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
$result = $query->first(['transaction_journals.*']);
|
||||
|
||||
if (null !== $result) {
|
||||
return $result->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC');
|
||||
if ($accounts->count() > 0) {
|
||||
// filter journals:
|
||||
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
$lastTransaction = $query->first(['transaction_journals.*']);
|
||||
if (null !== $lastTransaction) {
|
||||
return new Carbon($lastTransaction->date);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -423,12 +543,10 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -463,13 +581,11 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -510,12 +626,10 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $data;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -576,42 +690,38 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function spentInPeriod(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$set = $this->spentInPeriodCollection($categories, $accounts, $start, $end);
|
||||
$array = $this->spentInPeriodCollection($categories, $accounts, $start, $end);
|
||||
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
return $this->sumJournals($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setCategories($categories);
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
return $collector->getTransactions();
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -620,50 +730,38 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
* Get me the amount spent in this period, grouped per currency, where no category was set.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodPcWoCategory(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->withoutCategory();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$set = $set->filter(
|
||||
function (Transaction $transaction) {
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
$set = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
/** @var array $journal */
|
||||
foreach($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
if (!isset($return[$currencyId])) {
|
||||
$return[$currencyId] = [
|
||||
'spent' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_symbol' => $transaction->transaction_currency_symbol,
|
||||
'currency_code' => $transaction->transaction_currency_code,
|
||||
'currency_decimal_places' => $transaction->transaction_currency_dp,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$currencyId]['spent'] = bcadd($return[$currencyId]['spent'], $transaction->transaction_amount);
|
||||
$return[$currencyId]['spent'] = bcadd($return[$currencyId]['spent'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $return;
|
||||
@ -672,15 +770,15 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodPerCurrency(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
|
||||
@ -694,20 +792,14 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$set = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$jrnlCatId = (int)$transaction->transaction_journal_category_id;
|
||||
$transCatId = (int)$transaction->transaction_category_id;
|
||||
$categoryId = max($jrnlCatId, $transCatId);
|
||||
$currencyId = (int)$transaction->transaction_currency_id;
|
||||
$name = $transaction->transaction_category_name;
|
||||
$name = '' === (string)$name ? $transaction->transaction_journal_category_name : $name;
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$name = $journal['category_name'];
|
||||
|
||||
// make array for category:
|
||||
if (!isset($return[$categoryId])) {
|
||||
@ -720,13 +812,13 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
$return[$categoryId]['spent'][$currencyId] = [
|
||||
'spent' => '0',
|
||||
'currency_id' => $currencyId,
|
||||
'currency_symbol' => $transaction->transaction_currency_symbol,
|
||||
'currency_code' => $transaction->transaction_currency_code,
|
||||
'currency_decimal_places' => $transaction->transaction_currency_dp,
|
||||
'currency_symbol' => $journal['currency_symbol'],
|
||||
'currency_code' => $journal['currency_code'],
|
||||
'currency_decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$return[$categoryId]['spent'][$currencyId]['spent']
|
||||
= bcadd($return[$categoryId]['spent'][$currencyId]['spent'], $transaction->transaction_amount);
|
||||
= bcadd($return[$categoryId]['spent'][$currencyId]['spent'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $return;
|
||||
@ -734,8 +826,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -767,23 +859,9 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return (string)$set->sum('transaction_amount');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data): Category
|
||||
{
|
||||
/** @var CategoryFactory $factory */
|
||||
$factory = app(CategoryFactory::class);
|
||||
$factory->setUser($this->user);
|
||||
|
||||
return $factory->findOrCreate(null, $data['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
@ -794,91 +872,4 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
return $service->update($category, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getFirstJournalDate(Category $category): ?Carbon
|
||||
{
|
||||
$query = $category->transactionJournals()->orderBy('date', 'ASC');
|
||||
$result = $query->first(['transaction_journals.*']);
|
||||
|
||||
if (null !== $result) {
|
||||
return $result->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getFirstTransactionDate(Category $category): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'ASC');
|
||||
|
||||
$lastTransaction = $query->first(['transaction_journals.*']);
|
||||
if (null !== $lastTransaction) {
|
||||
return new Carbon($lastTransaction->date);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
private function getLastJournalDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
$query = $category->transactionJournals()->orderBy('date', 'DESC');
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$query->leftJoin('transactions as t', 't.transaction_journal_id', '=', 'transaction_journals.id');
|
||||
$query->whereIn('t.account_id', $accounts->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
$result = $query->first(['transaction_journals.*']);
|
||||
|
||||
if (null !== $result) {
|
||||
return $result->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getLastTransactionDate(Category $category, Collection $accounts): ?Carbon
|
||||
{
|
||||
// check transactions:
|
||||
$query = $category->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC');
|
||||
if ($accounts->count() > 0) {
|
||||
// filter journals:
|
||||
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
|
||||
}
|
||||
|
||||
$lastTransaction = $query->first(['transaction_journals.*']);
|
||||
if (null !== $lastTransaction) {
|
||||
return new Carbon($lastTransaction->date);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -66,9 +66,9 @@ interface CategoryRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
public function earnedInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
@ -222,9 +222,9 @@ interface CategoryRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
public function spentInPeriodCollection(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* A very cryptic method name that means:
|
||||
|
@ -91,9 +91,9 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
Log::debug(sprintf('Now in appendTransactions(%s)', $job->key));
|
||||
$existingTransactions = $this->getTransactions($job);
|
||||
$new = array_merge($existingTransactions, $transactions);
|
||||
Log::debug(sprintf('Old transaction count: %d', \count($existingTransactions)));
|
||||
Log::debug(sprintf('To be added transaction count: %d', \count($transactions)));
|
||||
Log::debug(sprintf('New count: %d', \count($new)));
|
||||
Log::debug(sprintf('Old transaction count: %d', count($existingTransactions)));
|
||||
Log::debug(sprintf('To be added transaction count: %d', count($transactions)));
|
||||
Log::debug(sprintf('New count: %d', count($new)));
|
||||
$this->setTransactions($job, $new);
|
||||
|
||||
return $job;
|
||||
@ -333,7 +333,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
$json = Crypt::encrypt(json_encode($transactions));
|
||||
|
||||
// set count for easy access
|
||||
$array = ['count' => \count($transactions)];
|
||||
$array = ['count' => count($transactions)];
|
||||
$job->transactions = $array;
|
||||
$job->save();
|
||||
// store file.
|
||||
|
@ -25,8 +25,8 @@ namespace FireflyIII\Repositories\Tag;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
@ -76,7 +76,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@ -94,20 +94,21 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
return $collector->getTransactions();
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setTag($tag);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -157,20 +158,21 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector =app(GroupCollectorInterface::class);
|
||||
|
||||
return $collector->getTransactions();
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setTag($tag);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,7 +236,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
@ -266,7 +268,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Tag $tag
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@ -275,16 +277,15 @@ class TagRepository implements TagRepositoryInterface
|
||||
*/
|
||||
public function sumsOfTag(Tag $tag, ?Carbon $start, ?Carbon $end): array
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
if (null !== $start && null !== $end) {
|
||||
$collector->setRange($start, $end);
|
||||
}
|
||||
|
||||
$collector->setAllAssetAccounts()->setTag($tag)->withOpposingAccount();
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$transactions = $collector->getTransactions();
|
||||
$collector->setTag($tag)->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
$sums = [
|
||||
TransactionType::WITHDRAWAL => '0',
|
||||
@ -292,9 +293,10 @@ class TagRepository implements TagRepositoryInterface
|
||||
TransactionType::TRANSFER => '0',
|
||||
];
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
$amount = app('steam')->positive((string)$transaction->transaction_amount);
|
||||
$type = $transaction->transaction_type_type;
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$amount = app('steam')->positive((string)$journal['amount']);
|
||||
$type = $journal['transaction_type_type'];
|
||||
if (TransactionType::WITHDRAWAL === $type) {
|
||||
$amount = bcmul($amount, '-1');
|
||||
}
|
||||
@ -350,39 +352,37 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param int|null $year
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection
|
||||
private function getTagsInYear(?int $year): Collection
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::TRANSFER])->setAllAssetAccounts()->setTag($tag);
|
||||
// get all tags in the year (if present):
|
||||
$tagQuery = $this->user->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where(
|
||||
function (Builder $query) {
|
||||
$query->where('transactions.amount', '>', 0);
|
||||
$query->orWhereNull('transactions.amount');
|
||||
}
|
||||
)
|
||||
->groupBy(['tags.id', 'tags.tag']);
|
||||
|
||||
return $collector->getTransactions();
|
||||
}
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
Log::debug('Get tags without a date.');
|
||||
$tagQuery->whereNull('tags.date');
|
||||
}
|
||||
if (null !== $year) {
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public function update(Tag $tag, array $data): Tag
|
||||
{
|
||||
$tag->tag = $data['tag'];
|
||||
$tag->date = $data['date'];
|
||||
$tag->description = $data['description'];
|
||||
$tag->latitude = $data['latitude'];
|
||||
$tag->longitude = $data['longitude'];
|
||||
$tag->zoomLevel = $data['zoom_level'];
|
||||
$tag->save();
|
||||
return $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]);
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -436,36 +436,38 @@ class TagRepository implements TagRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $year
|
||||
* @param Tag $tag
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
private function getTagsInYear(?int $year): Collection
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
{
|
||||
// get all tags in the year (if present):
|
||||
$tagQuery = $this->user->tags()
|
||||
->leftJoin('tag_transaction_journal', 'tag_transaction_journal.tag_id', '=', 'tags.id')
|
||||
->leftJoin('transaction_journals', 'tag_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('transactions', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where(
|
||||
function (Builder $query) {
|
||||
$query->where('transactions.amount', '>', 0);
|
||||
$query->orWhereNull('transactions.amount');
|
||||
}
|
||||
)
|
||||
->groupBy(['tags.id', 'tags.tag']);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::TRANSFER])->setTag($tag);
|
||||
|
||||
// add date range (or not):
|
||||
if (null === $year) {
|
||||
Log::debug('Get tags without a date.');
|
||||
$tagQuery->whereNull('tags.date');
|
||||
}
|
||||
if (null !== $year) {
|
||||
Log::debug(sprintf('Get tags with year %s.', $year));
|
||||
$tagQuery->where('tags.date', '>=', $year . '-01-01 00:00:00')->where('tags.date', '<=', $year . '-12-31 23:59:59');
|
||||
}
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
return $tagQuery->get(['tags.id', 'tags.tag', DB::raw('SUM(transactions.amount) as amount_sum')]);
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @param array $data
|
||||
*
|
||||
* @return Tag
|
||||
*/
|
||||
public function update(Tag $tag, array $data): Tag
|
||||
{
|
||||
$tag->tag = $data['tag'];
|
||||
$tag->date = $data['date'];
|
||||
$tag->description = $data['description'];
|
||||
$tag->latitude = $data['latitude'];
|
||||
$tag->longitude = $data['longitude'];
|
||||
$tag->zoomLevel = $data['zoom_level'];
|
||||
$tag->save();
|
||||
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ interface TagRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection;
|
||||
public function expenseInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param string $tag
|
||||
@ -97,9 +97,9 @@ interface TagRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection;
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
@ -179,9 +179,9 @@ interface TagRepositoryInterface
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): Collection;
|
||||
public function transferredInPeriod(Tag $tag, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* Update a tag.
|
||||
|
@ -138,10 +138,10 @@ class BelongsUser implements Rule
|
||||
private function parseAttribute(string $attribute): string
|
||||
{
|
||||
$parts = explode('.', $attribute);
|
||||
if (1 === \count($parts)) {
|
||||
if (1 === count($parts)) {
|
||||
return $attribute;
|
||||
}
|
||||
if (3 === \count($parts)) {
|
||||
if (3 === count($parts)) {
|
||||
return $parts[2];
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ class ValidRecurrenceRepetitionValue implements Rule
|
||||
private function validateNdom(string $value): bool
|
||||
{
|
||||
$parameters = explode(',', substr($value, 5));
|
||||
if (2 !== \count($parameters)) {
|
||||
if (2 !== count($parameters)) {
|
||||
return false;
|
||||
}
|
||||
$nthDay = (int)($parameters[0] ?? 0.0);
|
||||
|
@ -67,7 +67,7 @@ class UpdateRequest implements GithubRequest
|
||||
|
||||
//fetch the products for each category
|
||||
if (isset($releaseXml->entry)) {
|
||||
Log::debug(sprintf('Count of entries is: %d', \count($releaseXml->entry)));
|
||||
Log::debug(sprintf('Count of entries is: %d', count($releaseXml->entry)));
|
||||
foreach ($releaseXml->entry as $entry) {
|
||||
$array = [
|
||||
'id' => (string)$entry->id,
|
||||
|
@ -233,7 +233,7 @@ trait RecurringTransactionTrait
|
||||
*/
|
||||
protected function updateTags(Recurrence $recurrence, array $tags): void
|
||||
{
|
||||
if (\count($tags) > 0) {
|
||||
if (count($tags) > 0) {
|
||||
/** @var RecurrenceMeta $entry */
|
||||
$entry = $recurrence->recurrenceMeta()->where('name', 'tags')->first();
|
||||
if (null === $entry) {
|
||||
@ -242,7 +242,7 @@ trait RecurringTransactionTrait
|
||||
$entry->value = implode(',', $tags);
|
||||
$entry->save();
|
||||
}
|
||||
if (0 === \count($tags)) {
|
||||
if (0 === count($tags)) {
|
||||
// delete if present
|
||||
$recurrence->recurrenceMeta()->where('name', 'tags')->delete();
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class ListAccountsRequest extends SpectreRequest
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', \count($response['data'])));
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
|
@ -51,7 +51,7 @@ class ListCustomersRequest extends SpectreRequest
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', \count($response['data'])));
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
|
@ -55,7 +55,7 @@ class ListLoginsRequest extends SpectreRequest
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', \count($response['data'])));
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
|
@ -53,7 +53,7 @@ class ListTransactionsRequest extends SpectreRequest
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', \count($response['data'])));
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
|
@ -60,7 +60,7 @@ abstract class YnabRequest
|
||||
'Authorization' => 'Bearer ' . $this->token,
|
||||
],
|
||||
];
|
||||
if (\count($params) > 0) {
|
||||
if (count($params) > 0) {
|
||||
$uri = $uri . '?' . http_build_query($params);
|
||||
}
|
||||
Log::debug(sprintf('Going to call YNAB on URI: %s', $uri), $options);
|
||||
|
@ -44,7 +44,7 @@ class BudgetList implements BinderInterface
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
if (0 === \count($list)) {
|
||||
if (0 === count($list)) {
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class CategoryList implements BinderInterface
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
if (0 === \count($list)) {
|
||||
if (0 === count($list)) {
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class JournalList implements BinderInterface
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
if (0 === \count($list)) {
|
||||
if (0 === count($list)) {
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ class SimpleJournalList implements BinderInterface
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$list = array_unique(array_map('\intval', explode(',', $value)));
|
||||
if (0 === \count($list)) {
|
||||
if (0 === count($list)) {
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ class SimpleJournalList implements BinderInterface
|
||||
}
|
||||
|
||||
if ($final->count() > 0) {
|
||||
if (\count($messages) > 0) {
|
||||
if (count($messages) > 0) {
|
||||
session()->flash('info', $messages);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ class TagList implements BinderInterface
|
||||
if (auth()->check()) {
|
||||
$list = array_unique(array_map('\strtolower', explode(',', $value)));
|
||||
Log::debug('List of tags is', $list);
|
||||
if (0 === \count($list)) {
|
||||
if (0 === count($list)) {
|
||||
Log::error('Tag list is empty.');
|
||||
throw new NotFoundHttpException; // @codeCoverageIgnore
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class ChartColour
|
||||
*/
|
||||
public static function getColour(int $index): string
|
||||
{
|
||||
$index %= \count(self::$colours);
|
||||
$index %= count(self::$colours);
|
||||
$row = self::$colours[$index];
|
||||
|
||||
return sprintf('rgba(%d, %d, %d, 0.7)', $row[0], $row[1], $row[2]);
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ trait GetSpectreCustomerTrait
|
||||
$request->call();
|
||||
$customers = $request->getCustomers();
|
||||
|
||||
Log::debug(sprintf('Found %d customer(s)', \count($customers)));
|
||||
Log::debug(sprintf('Found %d customer(s)', count($customers)));
|
||||
/** @var Customer $current */
|
||||
foreach ($customers as $current) {
|
||||
if ('default_ff3_customer' === $current->getIdentifier()) {
|
||||
|
@ -58,7 +58,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
{
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$mapping = $config['mapping'] ?? [];
|
||||
$complete = \count($mapping) > 0;
|
||||
$complete = count($mapping) > 0;
|
||||
if (true === $complete) {
|
||||
// move job to correct stage to download transactions
|
||||
$this->repository->setStage($this->importJob, 'go-for-import');
|
||||
@ -94,10 +94,10 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
*/
|
||||
$ibanToAsset = [];
|
||||
Log::debug('Going to map IBANs for easy mapping later on.');
|
||||
if (0 === \count($accounts)) {
|
||||
if (0 === count($accounts)) {
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
if (0 === \count($mapping)) {
|
||||
if (0 === count($mapping)) {
|
||||
$messages = new MessageBag;
|
||||
$messages->add('nomap', (string)trans('import.bunq_no_mapping'));
|
||||
|
||||
@ -144,7 +144,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
|
||||
{
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$accounts = $config['accounts'] ?? [];
|
||||
if (0 === \count($accounts)) {
|
||||
if (0 === count($accounts)) {
|
||||
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
// list the users accounts:
|
||||
|
@ -311,7 +311,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
|
||||
$columnConfig[$columnIndex]['values'] = array_unique($columnConfig[$columnIndex]['values']);
|
||||
asort($columnConfig[$columnIndex]['values']);
|
||||
// if the count of this array is zero, there is nothing to map.
|
||||
if (0 === \count($columnConfig[$columnIndex]['values'])) {
|
||||
if (0 === count($columnConfig[$columnIndex]['values'])) {
|
||||
unset($columnConfig[$columnIndex]);
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
|
||||
foreach ($records as $line) {
|
||||
$line = array_values($line);
|
||||
$line = $this->processSpecifics($config, $line);
|
||||
$count = \count($line);
|
||||
$count = count($line);
|
||||
$this->totalColumns = $count > $this->totalColumns ? $count : $this->totalColumns;
|
||||
$this->getExampleFromLine($line);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
|
||||
Log::debug('Now in ChooseAccountsHandler::configurationComplete()');
|
||||
$config = $this->importJob->configuration;
|
||||
$importAccounts = $config['account_mapping'] ?? [];
|
||||
$complete = \count($importAccounts) > 0 && $importAccounts !== [0 => 0];
|
||||
$complete = count($importAccounts) > 0 && $importAccounts !== [0 => 0];
|
||||
if ($complete) {
|
||||
Log::debug('Looks like user has mapped import accounts to Firefly III accounts', $importAccounts);
|
||||
$this->repository->setStage($this->importJob, 'go-for-import');
|
||||
@ -98,7 +98,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
|
||||
$config['account_mapping'] = $final;
|
||||
$config['apply-rules'] = $applyRules;
|
||||
$this->repository->setConfiguration($this->importJob, $config);
|
||||
if ($final === [0 => 0] || 0 === \count($final)) {
|
||||
if ($final === [0 => 0] || 0 === count($final)) {
|
||||
$messages->add('count', (string)trans('import.spectre_no_mapping'));
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
|
||||
Log::debug('Now in ChooseAccountsHandler::getnextData()');
|
||||
$config = $this->importJob->configuration;
|
||||
$accounts = $config['accounts'] ?? [];
|
||||
if (0 === \count($accounts)) {
|
||||
if (0 === count($accounts)) {
|
||||
throw new FireflyException('It seems you have no accounts with this bank. The import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
$converted = [];
|
||||
@ -129,7 +129,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
|
||||
$login = null;
|
||||
$logins = $config['all-logins'] ?? [];
|
||||
$selected = $config['selected-login'] ?? 0;
|
||||
if (0 === \count($logins)) {
|
||||
if (0 === count($logins)) {
|
||||
throw new FireflyException('It seems you have no configured logins in this import job. The import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
Log::debug(sprintf('Selected login to use is %d', $selected));
|
||||
|
@ -112,7 +112,7 @@ class ChooseLoginHandler implements SpectreJobConfigurationInterface
|
||||
$config = $this->importJob->configuration;
|
||||
$data = ['logins' => []];
|
||||
$logins = $config['all-logins'] ?? [];
|
||||
Log::debug(sprintf('Count of logins in configuration is %d.', \count($logins)));
|
||||
Log::debug(sprintf('Count of logins in configuration is %d.', count($logins)));
|
||||
foreach ($logins as $login) {
|
||||
$data['logins'][] = new Login($login);
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class SelectAccountsHandler implements YnabJobConfigurationInterface
|
||||
Log::debug('Now in SelectAccountsHandler::configurationComplete()');
|
||||
$config = $this->importJob->configuration;
|
||||
$mapping = $config['mapping'] ?? [];
|
||||
if (\count($mapping) > 0) {
|
||||
if (count($mapping) > 0) {
|
||||
// mapping is complete.
|
||||
Log::debug('Looks like user has mapped YNAB accounts to Firefly III accounts', $mapping);
|
||||
$this->repository->setStage($this->importJob, 'go-for-import');
|
||||
@ -97,7 +97,7 @@ class SelectAccountsHandler implements YnabJobConfigurationInterface
|
||||
$config['mapping'] = $final;
|
||||
$config['apply-rules'] = $applyRules;
|
||||
$this->repository->setConfiguration($this->importJob, $config);
|
||||
if ($final === ['' => 0] || 0 === \count($final)) {
|
||||
if ($final === ['' => 0] || 0 === count($final)) {
|
||||
$messages->add('count', (string)trans('import.ynab_no_mapping'));
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ class SelectAccountsHandler implements YnabJobConfigurationInterface
|
||||
$config = $this->importJob->configuration;
|
||||
$ynabAccounts = $config['accounts'] ?? [];
|
||||
$budget = $this->getSelectedBudget();
|
||||
if (0 === \count($ynabAccounts)) {
|
||||
if (0 === count($ynabAccounts)) {
|
||||
throw new FireflyException('It seems you have no accounts with this budget. The import cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
// list the users accounts:
|
||||
|
@ -104,7 +104,7 @@ class SelectBudgetHandler implements YnabJobConfigurationInterface
|
||||
$budgets = $configuration['budgets'] ?? [];
|
||||
$available = [];
|
||||
$notAvailable = [];
|
||||
$total = \count($budgets);
|
||||
$total = count($budgets);
|
||||
foreach ($budgets as $budget) {
|
||||
if ($this->haveAssetWithCurrency($budget['currency_code'])) {
|
||||
Log::debug('Add budget to available list.');
|
||||
|
@ -325,7 +325,7 @@ class StageImportDataHandler
|
||||
/*
|
||||
* After the loop, check if Firefly III must loop again.
|
||||
*/
|
||||
Log::debug(sprintf('Count of result is now %d', \count($return)));
|
||||
Log::debug(sprintf('Count of result is now %d', count($return)));
|
||||
$count++;
|
||||
if (null === $olderId) {
|
||||
Log::debug('Older ID is NULL, so stop looping cause we are done!');
|
||||
@ -351,7 +351,7 @@ class StageImportDataHandler
|
||||
// store newest and oldest tranasction ID to be used later:
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-oldest-transaction-%d', $bunqAccountId), $oldestTransaction);
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-newest-transaction-%d', $bunqAccountId), $newestTransaction);
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', \count($return)));
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', count($return)));
|
||||
|
||||
return $return;
|
||||
}
|
||||
@ -428,7 +428,7 @@ class StageImportDataHandler
|
||||
/*
|
||||
* After the loop, check if Firefly III must loop again.
|
||||
*/
|
||||
Log::debug(sprintf('Count of result is now %d', \count($return)));
|
||||
Log::debug(sprintf('Count of result is now %d', count($return)));
|
||||
$count++;
|
||||
if (null === $newerId) {
|
||||
Log::debug('Newer ID is NULL, so stop looping cause we are done!');
|
||||
@ -446,7 +446,7 @@ class StageImportDataHandler
|
||||
|
||||
// store newest tranasction ID to be used later:
|
||||
\Preferences::setForUser($this->importJob->user, sprintf('bunq-newest-transaction-%d', $bunqAccountId), $newestTransaction);
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', \count($return)));
|
||||
Log::info(sprintf('Downloaded and parsed %d transactions from bunq.', count($return)));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ class StageNewHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
Log::info(sprintf('Found %d account(s) at bunq', \count($accounts)), $accounts);
|
||||
Log::info(sprintf('Found %d account(s) at bunq', count($accounts)), $accounts);
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
@ -224,7 +224,7 @@ class StageNewHandler
|
||||
Log::debug('Setting is not null.');
|
||||
}
|
||||
if (null !== $maj->getAlias()) {
|
||||
Log::debug(sprintf('Alias is not NULL. Count is %d', \count($maj->getAlias())));
|
||||
Log::debug(sprintf('Alias is not NULL. Count is %d', count($maj->getAlias())));
|
||||
/** @var Pointer $alias */
|
||||
foreach ($maj->getAlias() as $alias) {
|
||||
$return['aliases'][] = [
|
||||
@ -239,7 +239,7 @@ class StageNewHandler
|
||||
}
|
||||
}
|
||||
$coOwners = $maj->getAllCoOwner() ?? [];
|
||||
Log::debug(sprintf('Count of getAllCoOwner is %d', \count($coOwners)));
|
||||
Log::debug(sprintf('Count of getAllCoOwner is %d', count($coOwners)));
|
||||
/** @var CoOwner $coOwner */
|
||||
foreach ($coOwners as $coOwner) {
|
||||
$alias = $coOwner->getAlias();
|
||||
|
@ -69,7 +69,7 @@ class ImportableConverter
|
||||
*/
|
||||
public function convert(array $importables): array
|
||||
{
|
||||
$total = \count($importables);
|
||||
$total = count($importables);
|
||||
Log::debug(sprintf('Going to convert %d import transactions', $total));
|
||||
$result = [];
|
||||
/** @var ImportTransaction $importable */
|
||||
|
@ -90,7 +90,7 @@ class MappedValuesValidator
|
||||
foreach ($mappings as $role => $values) {
|
||||
Log::debug(sprintf('Now at role "%s"', $role));
|
||||
$values = array_unique($values);
|
||||
if (\count($values) > 0) {
|
||||
if (count($values) > 0) {
|
||||
switch ($role) {
|
||||
default:
|
||||
throw new FireflyException(sprintf('Cannot validate mapped values for role "%s"', $role)); // @codeCoverageIgnore
|
||||
|
@ -69,7 +69,7 @@ class MappingConverger
|
||||
{
|
||||
Log::debug('Start converging process.');
|
||||
$collection = [];
|
||||
$total = \count($lines);
|
||||
$total = count($lines);
|
||||
/** @var array $line */
|
||||
foreach ($lines as $lineIndex => $line) {
|
||||
Log::debug(sprintf('Now converging line %d out of %d.', $lineIndex + 1, $total));
|
||||
|
@ -56,8 +56,8 @@ class StageAuthenticatedHandler
|
||||
// grab a list of logins.
|
||||
$config = $this->importJob->configuration;
|
||||
$logins = $config['all-logins'] ?? [];
|
||||
Log::debug(sprintf('%d logins in config', \count($logins)));
|
||||
if (0 === \count($logins)) {
|
||||
Log::debug(sprintf('%d logins in config', count($logins)));
|
||||
if (0 === count($logins)) {
|
||||
// get logins from Spectre.
|
||||
$logins = $this->getLogins();
|
||||
$config['all-logins'] = $logins;
|
||||
@ -115,7 +115,7 @@ class StageAuthenticatedHandler
|
||||
$request->setLogin($login);
|
||||
$request->call();
|
||||
$accounts = $request->getAccounts();
|
||||
Log::debug(sprintf('Found %d accounts using login', \count($accounts)));
|
||||
Log::debug(sprintf('Found %d accounts using login', count($accounts)));
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
@ -137,7 +137,7 @@ class StageAuthenticatedHandler
|
||||
$logins = $request->getLogins();
|
||||
$return = [];
|
||||
|
||||
Log::debug(sprintf('Found %d logins in users Spectre account.', \count($logins)));
|
||||
Log::debug(sprintf('Found %d logins in users Spectre account.', count($logins)));
|
||||
|
||||
/** @var Login $login */
|
||||
foreach ($logins as $login) {
|
||||
|
@ -59,8 +59,8 @@ class StageImportDataHandler
|
||||
Log::debug('Now in StageImportDataHandler::run()');
|
||||
$config = $this->importJob->configuration;
|
||||
$accounts = $config['accounts'] ?? [];
|
||||
Log::debug(sprintf('Count of accounts in array is %d', \count($accounts)));
|
||||
if (0 === \count($accounts)) {
|
||||
Log::debug(sprintf('Count of accounts in array is %d', count($accounts)));
|
||||
if (0 === count($accounts)) {
|
||||
throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore
|
||||
}
|
||||
$toImport = $config['account_mapping'] ?? [];
|
||||
@ -73,14 +73,14 @@ class StageImportDataHandler
|
||||
$merge = $this->getTransactions($spectreAccount, $localAccount);
|
||||
$totalSet[] = $merge;
|
||||
Log::debug(
|
||||
sprintf('Found %d transactions in account "%s" (%s)', \count($merge), $spectreAccount->getName(), $spectreAccount->getCurrencyCode())
|
||||
sprintf('Found %d transactions in account "%s" (%s)', count($merge), $spectreAccount->getName(), $spectreAccount->getCurrencyCode())
|
||||
);
|
||||
continue;
|
||||
}
|
||||
Log::debug(sprintf('Local account is = zero, will not import from Spectr account with ID #%d', $spectreId));
|
||||
}
|
||||
$totalSet = array_merge(...$totalSet);
|
||||
Log::debug(sprintf('Found %d transactions in total.', \count($totalSet)));
|
||||
Log::debug(sprintf('Found %d transactions in total.', count($totalSet)));
|
||||
$this->repository->setTransactions($this->importJob, $totalSet);
|
||||
}
|
||||
|
||||
@ -112,8 +112,8 @@ class StageImportDataHandler
|
||||
private function convertToArray(array $transactions, SpectreAccount $spectreAccount, LocalAccount $originalSource): array
|
||||
{
|
||||
$array = [];
|
||||
$total = \count($transactions);
|
||||
Log::debug(sprintf('Now in StageImportDataHandler::convertToArray() with count %d', \count($transactions)));
|
||||
$total = count($transactions);
|
||||
Log::debug(sprintf('Now in StageImportDataHandler::convertToArray() with count %d', count($transactions)));
|
||||
/** @var SpectreTransaction $transaction */
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
Log::debug(sprintf('Now creating array for transaction %d of %d', $index + 1, $total));
|
||||
@ -216,7 +216,7 @@ class StageImportDataHandler
|
||||
];
|
||||
$array[] = $entry;
|
||||
}
|
||||
Log::debug(sprintf('Return %d entries', \count($array)));
|
||||
Log::debug(sprintf('Return %d entries', count($array)));
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ class StageNewHandler
|
||||
$list = $request->getLogins();
|
||||
|
||||
// count is zero?
|
||||
$this->countLogins = \count($list);
|
||||
$this->countLogins = count($list);
|
||||
Log::debug(sprintf('Number of logins is %d', $this->countLogins));
|
||||
if ($this->countLogins > 0) {
|
||||
$store = [];
|
||||
|
@ -63,7 +63,7 @@ class GetAccountsHandler
|
||||
$request->call();
|
||||
$config['accounts'] = $request->accounts;
|
||||
$this->repository->setConfiguration($this->importJob, $config);
|
||||
if (0 === \count($config['accounts'])) {
|
||||
if (0 === count($config['accounts'])) {
|
||||
throw new FireflyException('This budget contains zero accounts.');
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class ImportDataHandler
|
||||
}
|
||||
|
||||
$totalSet = array_merge(...$total);
|
||||
Log::debug(sprintf('Found %d transactions in total.', \count($totalSet)));
|
||||
Log::debug(sprintf('Found %d transactions in total.', count($totalSet)));
|
||||
$this->repository->setTransactions($this->importJob, $totalSet);
|
||||
|
||||
// assuming this works, store today's date as a preference
|
||||
@ -114,9 +114,9 @@ class ImportDataHandler
|
||||
{
|
||||
$config = $this->repository->getConfiguration($this->importJob);
|
||||
$array = [];
|
||||
$total = \count($transactions);
|
||||
$total = count($transactions);
|
||||
$budget = $this->getSelectedBudget();
|
||||
Log::debug(sprintf('Now in StageImportDataHandler::convertToArray() with count %d', \count($transactions)));
|
||||
Log::debug(sprintf('Now in StageImportDataHandler::convertToArray() with count %d', count($transactions)));
|
||||
/** @var array $transaction */
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
$description = $transaction['memo'] ?? '(empty)';
|
||||
|
@ -57,8 +57,8 @@ class StageGetBudgetsHandler
|
||||
// store budgets in users preferences.
|
||||
$configuration['budgets'] = $request->budgets;
|
||||
$this->repository->setConfiguration($this->importJob, $configuration);
|
||||
Log::debug(sprintf('Found %d budgets', \count($request->budgets)));
|
||||
if (0 === \count($request->budgets)) {
|
||||
Log::debug(sprintf('Found %d budgets', count($request->budgets)));
|
||||
if (0 === count($request->budgets)) {
|
||||
throw new FireflyException('It seems this user has zero budgets or an error prevented Firefly III from reading them.');
|
||||
}
|
||||
}
|
||||
|
@ -87,12 +87,12 @@ trait FiltersWeekends
|
||||
}
|
||||
|
||||
// filter unique dates
|
||||
Log::debug(sprintf('Count before filtering: %d', \count($dates)));
|
||||
Log::debug(sprintf('Count before filtering: %d', count($dates)));
|
||||
$collection = new Collection($return);
|
||||
$filtered = $collection->unique();
|
||||
$return = $filtered->toArray();
|
||||
|
||||
Log::debug(sprintf('Count after filtering: %d', \count($return)));
|
||||
Log::debug(sprintf('Count after filtering: %d', count($return)));
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ class Search implements SearchInterface
|
||||
private function extractModifier(string $string): void
|
||||
{
|
||||
$parts = explode(':', $string);
|
||||
if (2 === \count($parts) && '' !== trim((string)$parts[1]) && '' !== trim((string)$parts[0])) {
|
||||
if (2 === count($parts) && '' !== trim((string)$parts[1]) && '' !== trim((string)$parts[0])) {
|
||||
$type = trim((string)$parts[0]);
|
||||
$value = trim((string)$parts[1]);
|
||||
if (\in_array($type, $this->validModifiers, true)) {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user