mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 08:30:06 +00:00
Migrated all code to group collector.
This commit is contained in:
@@ -24,9 +24,7 @@ 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;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
@@ -230,7 +228,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->withAccountInformation();
|
||||
$income = $this->groupByDestination($collector->getExtractedJournals());
|
||||
$income = $this->groupByDestination($collector->getExtractedJournals());
|
||||
|
||||
// sort the result
|
||||
// Obtain a list of columns
|
||||
|
||||
@@ -27,14 +27,12 @@ use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\BudgetLimit;
|
||||
use FireflyIII\Models\RuleAction;
|
||||
use FireflyIII\Models\RuleTrigger;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -164,6 +162,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
|
||||
return $collector->getSum();
|
||||
|
||||
}
|
||||
@@ -556,18 +555,19 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
}
|
||||
|
||||
// get all transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setBudgets($budgets);
|
||||
$transactions = $collector->getTransactions();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// loop transactions:
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$budgetId = max((int)$transaction->transaction_journal_budget_id, (int)$transaction->transaction_budget_id);
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
$data[$budgetId]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $transaction->transaction_amount);
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$budgetId = (int)$journal['budget_id'];
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
$data[$budgetId]['entries'][$date] = bcadd($data[$budgetId]['entries'][$date] ?? '0', $journal['amount']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -623,25 +623,28 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
public function getNoBudgetPeriodReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$collector->withoutBudget();
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [
|
||||
'entries' => [],
|
||||
'name' => (string)trans('firefly.no_budget'),
|
||||
'sum' => '0',
|
||||
];
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
|
||||
if (!isset($result['entries'][$date])) {
|
||||
$result['entries'][$date] = '0';
|
||||
}
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $transaction->transaction_amount);
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $journal['amount']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -794,39 +797,41 @@ class BudgetRepository implements BudgetRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriodWoBudgetMc(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])->withoutBudget();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
$total = [];
|
||||
$currencies = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$code = $transaction->transaction_currency_code;
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$code = $journal['currency_code'];
|
||||
if (!isset($currencies[$code])) {
|
||||
$currencies[$code] = $transaction->transactionCurrency;
|
||||
$currencies[$code] = [
|
||||
'id' => $journal['currency_id'],
|
||||
'name' => $journal['currency_name'],
|
||||
'symbol' => $journal['currency_symbol'],
|
||||
'decimal_places' => $journal['currency_decimal_places'],
|
||||
];
|
||||
}
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $transaction->transaction_amount) : $transaction->transaction_amount;
|
||||
$total[$code] = isset($total[$code]) ? bcadd($total[$code], $journal['amount']) : $journal['amount'];
|
||||
}
|
||||
foreach ($total as $code => $spent) {
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $currencies[$code];
|
||||
$return[] = [
|
||||
'currency_id' => $currency->id,
|
||||
'currency_id' => $currency['id'],
|
||||
'currency_code' => $code,
|
||||
'currency_symbol' => $currency->symbol,
|
||||
'currency_decimal_places' => $currency->decimal_places,
|
||||
'amount' => round($spent, $currency->decimal_places),
|
||||
'currency_symbol' => $currency['symbol'],
|
||||
'currency_decimal_places' => $currency['decimal_places'],
|
||||
'amount' => round($spent, $currency['decimal_places']),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,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;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Services\Internal\Destroy\CategoryDestroyService;
|
||||
use FireflyIII\Services\Internal\Update\CategoryUpdateService;
|
||||
@@ -142,43 +140,30 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function earnedInPeriodPcWoCategory(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::DEPOSIT])->withoutCategory();
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$set = $set->filter(
|
||||
function (Transaction $transaction) {
|
||||
if (bccomp($transaction->transaction_amount, '0') === 1) {
|
||||
return $transaction;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
$return = [];
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($set as $transaction) {
|
||||
$currencyId = $transaction->transaction_currency_id;
|
||||
foreach ($journals 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;
|
||||
@@ -194,8 +179,9 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function earnedInPeriodPerCurrency(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::DEPOSIT]);
|
||||
|
||||
@@ -209,20 +195,12 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
if ($accounts->count() > 0) {
|
||||
$collector->setAccounts($accounts);
|
||||
}
|
||||
if (0 === $accounts->count()) {
|
||||
$collector->setAllAssetAccounts();
|
||||
}
|
||||
|
||||
$set = $collector->getTransactions();
|
||||
$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;
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
foreach ($journals as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$name = $journal['category_name'];
|
||||
// make array for category:
|
||||
if (!isset($return[$categoryId])) {
|
||||
$return[$categoryId] = [
|
||||
@@ -234,13 +212,13 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
$return[$categoryId]['earned'][$currencyId] = [
|
||||
'earned' => '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]['earned'][$currencyId]['earned']
|
||||
= bcadd($return[$categoryId]['earned'][$currencyId]['earned'], $transaction->transaction_amount);
|
||||
= bcadd($return[$categoryId]['earned'][$currencyId]['earned'], $journal['amount']);
|
||||
}
|
||||
|
||||
return $return;
|
||||
@@ -521,23 +499,20 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
// get all transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setCategories($categories)->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
->withOpposingAccount();
|
||||
$transactions = $collector->getTransactions();
|
||||
->withAccountInformation()->withCategoryInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// loop transactions:
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// if positive, skip:
|
||||
if (1 === bccomp($transaction->transaction_amount, '0')) {
|
||||
continue;
|
||||
}
|
||||
$categoryId = max((int)$transaction->transaction_journal_category_id, (int)$transaction->transaction_category_id);
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $transaction->transaction_amount);
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $journal['amount']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -553,29 +528,28 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
public function periodExpensesNoCategory(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->withAccountInformation();
|
||||
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
|
||||
$collector->withoutCategory();
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [
|
||||
'entries' => [],
|
||||
'name' => (string)trans('firefly.no_category'),
|
||||
'sum' => '0',
|
||||
];
|
||||
|
||||
foreach ($transactions as $transaction) {
|
||||
// if positive, skip:
|
||||
if (1 === bccomp($transaction->transaction_amount, '0')) {
|
||||
continue;
|
||||
}
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
|
||||
if (!isset($result['entries'][$date])) {
|
||||
$result['entries'][$date] = '0';
|
||||
}
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $transaction->transaction_amount);
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $journal['amount']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@@ -604,23 +578,20 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
}
|
||||
|
||||
// get all transactions:
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end);
|
||||
$collector->setCategories($categories)->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||
->withOpposingAccount();
|
||||
$transactions = $collector->getTransactions();
|
||||
->withAccountInformation();
|
||||
$journals = $collector->getExtractedJournals();
|
||||
|
||||
// loop transactions:
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
// if negative, skip:
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||
continue;
|
||||
}
|
||||
$categoryId = max((int)$transaction->transaction_journal_category_id, (int)$transaction->transaction_category_id);
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $transaction->transaction_amount);
|
||||
/** @var array $journal */
|
||||
foreach ($journals as $journal) {
|
||||
$categoryId = (int)$journal['category_id'];
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
$data[$categoryId]['entries'][$date] = bcadd($data[$categoryId]['entries'][$date] ?? '0', $journal['amount']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
@@ -637,29 +608,28 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
Log::debug('Now in periodIncomeNoCategory()');
|
||||
$carbonFormat = Navigation::preferredCarbonFormat($start, $end);
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->withOpposingAccount();
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($accounts)->setRange($start, $end)->withAccountInformation();
|
||||
$collector->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER]);
|
||||
$collector->withoutCategory();
|
||||
$transactions = $collector->getTransactions();
|
||||
$result = [
|
||||
$journals = $collector->getExtractedJournals();
|
||||
$result = [
|
||||
'entries' => [],
|
||||
'name' => (string)trans('firefly.no_category'),
|
||||
'sum' => '0',
|
||||
];
|
||||
Log::debug('Looping transactions..');
|
||||
foreach ($transactions as $transaction) {
|
||||
// if negative, skip:
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1) {
|
||||
continue;
|
||||
}
|
||||
$date = $transaction->date->format($carbonFormat);
|
||||
|
||||
foreach ($journals as $journal) {
|
||||
$date = $journal['date']->format($carbonFormat);
|
||||
|
||||
if (!isset($result['entries'][$date])) {
|
||||
$result['entries'][$date] = '0';
|
||||
}
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $transaction->transaction_amount);
|
||||
$result['entries'][$date] = bcadd($result['entries'][$date], $journal['amount']);
|
||||
}
|
||||
Log::debug('Done looping transactions..');
|
||||
Log::debug('Finished periodIncomeNoCategory()');
|
||||
@@ -714,6 +684,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setCategories($categories);
|
||||
|
||||
@@ -750,7 +722,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
$set = $collector->getExtractedJournals();
|
||||
$return = [];
|
||||
/** @var array $journal */
|
||||
foreach($set as $journal) {
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
if (!isset($return[$currencyId])) {
|
||||
$return[$currencyId] = [
|
||||
@@ -833,30 +805,17 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriodWithoutCategory(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])->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;
|
||||
}
|
||||
);
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
return $collector->getSum();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,11 +25,6 @@ namespace FireflyIII\Repositories\Journal;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use Exception;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\TransactionGroupFactory;
|
||||
use FireflyIII\Factory\TransactionJournalFactory;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
@@ -74,9 +69,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param TransactionType $type
|
||||
* @param Account $source
|
||||
* @param Account $destination
|
||||
* @param TransactionType $type
|
||||
* @param Account $source
|
||||
* @param Account $destination
|
||||
*
|
||||
* @return MessageBag
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -354,7 +349,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* otherwise look for meta field and return that one.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param null|string $field
|
||||
* @param null|string $field
|
||||
*
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -386,11 +381,40 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('journal-meta-updated');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return new Carbon($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
if (null === $entry) {
|
||||
return null;
|
||||
}
|
||||
$value = new Carbon($entry->data);
|
||||
$cache->store($entry->data);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all destination accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $useCache
|
||||
* @param bool $useCache
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -418,7 +442,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* Return a list of all source accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $useCache
|
||||
* @param bool $useCache
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -493,40 +517,11 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Carbon value of a meta field (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|Carbon
|
||||
*/
|
||||
public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('journal-meta-updated');
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty($field);
|
||||
|
||||
if ($cache->has()) {
|
||||
return new Carbon($cache->get()); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$entry = $journal->transactionJournalMeta()->where('name', $field)->first();
|
||||
if (null === $entry) {
|
||||
return null;
|
||||
}
|
||||
$value = new Carbon($entry->data);
|
||||
$cache->store($entry->data);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return string value of a meta date (or NULL).
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
@@ -544,7 +539,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* Return value of a meta field (or NULL) as a string.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $field
|
||||
* @param string $field
|
||||
*
|
||||
* @return null|string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -666,33 +661,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $journal->transactionType->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $transactionIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTransactionsById(array $transactionIds): Collection
|
||||
{
|
||||
$journalIds = Transaction::whereIn('id', $transactionIds)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
|
||||
$journals = new Collection;
|
||||
foreach ($journalIds as $journalId) {
|
||||
$result = $this->findNull((int)$journalId);
|
||||
if (null !== $result) {
|
||||
$journals->push($result);
|
||||
}
|
||||
}
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setAllAssetAccounts();
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
//$collector->addFilter(TransferFilter::class);
|
||||
|
||||
$collector->setJournals($journals)->withOpposingAccount();
|
||||
|
||||
return $collector->getTransactions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Will tell you if journal is reconciled or not.
|
||||
*
|
||||
@@ -711,6 +679,22 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $transactionId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reconcileById(int $transactionId): bool
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $this->user->transactions()->find($transactionId);
|
||||
if (null !== $transaction) {
|
||||
return $this->reconcile($transaction);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
@@ -736,25 +720,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $transactionId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function reconcileById(int $transactionId): bool
|
||||
{
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $this->user->transactions()->find($transactionId);
|
||||
if (null !== $transaction) {
|
||||
return $this->reconcile($transaction);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $order
|
||||
* @param int $order
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -778,7 +746,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* Update budget for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param int $budgetId
|
||||
* @param int $budgetId
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -794,7 +762,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* Update category for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param string $category
|
||||
* @param string $category
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
@@ -810,7 +778,7 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
* Update tag(s) for a journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $tags
|
||||
* @param array $tags
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
|
||||
@@ -276,13 +276,6 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getTransactionType(TransactionJournal $journal): string;
|
||||
|
||||
/**
|
||||
* @param array $transactionIds
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTransactionsById(array $transactionIds): Collection;
|
||||
|
||||
/**
|
||||
* Will tell you if journal is reconciled or not.
|
||||
*
|
||||
@@ -319,8 +312,6 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function setUser(User $user);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Update budget for a journal.
|
||||
*
|
||||
|
||||
@@ -26,8 +26,7 @@ namespace FireflyIII\Repositories\Recurring;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\RecurrenceFactory;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Filter\InternalTransferFilter;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Recurrence;
|
||||
@@ -151,7 +150,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
/**
|
||||
* Returns the journals created for this recurrence, possibly limited by time.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param Recurrence $recurrence
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
@@ -213,8 +212,8 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
* Generate events in the date range.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
@@ -274,8 +273,8 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
* @param int $page
|
||||
* @param int $pageSize
|
||||
*
|
||||
* @return LengthAwarePaginator
|
||||
*/
|
||||
@@ -290,25 +289,27 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
->get()->pluck('transaction_journal_id')->toArray();
|
||||
$search = [];
|
||||
foreach ($journalMeta as $journalId) {
|
||||
$search[] = ['id' => (int)$journalId];
|
||||
$search[] = (int)$journalId;
|
||||
}
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withOpposingAccount()->setAllAssetAccounts()->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page);
|
||||
// filter on specific journals.
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$collector->setJournals(new Collection($search));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
return $collector->getPaginatedTransactions();
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withCategoryInformation()->withBudgetInformation()->setLimit($pageSize)->setPage($page)
|
||||
->withAccountInformation();
|
||||
$collector->setJournalIds($search);
|
||||
|
||||
return $collector->getPaginatedGroups();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO check usage and verify it still works.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getTransactions(Recurrence $recurrence): Collection
|
||||
public function getTransactions(Recurrence $recurrence): array
|
||||
{
|
||||
$journalMeta = TransactionJournalMeta
|
||||
::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
@@ -319,25 +320,25 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
->get()->pluck('transaction_journal_id')->toArray();
|
||||
$search = [];
|
||||
foreach ($journalMeta as $journalId) {
|
||||
$search[] = ['id' => (int)$journalId];
|
||||
$search[] = (int)$journalId;
|
||||
}
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withOpposingAccount()->setAllAssetAccounts()->withCategoryInformation()->withBudgetInformation();
|
||||
// filter on specific journals.
|
||||
$collector->removeFilter(InternalTransferFilter::class);
|
||||
$collector->setJournals(new Collection($search));
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
return $collector->getTransactions();
|
||||
$collector->setUser($recurrence->user);
|
||||
$collector->withCategoryInformation()->withBudgetInformation()->withAccountInformation();
|
||||
// filter on specific journals.
|
||||
$collector->setJournalIds($search);
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the next X iterations starting on the date given in $date.
|
||||
*
|
||||
* @param RecurrenceRepetition $repetition
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
* @param Carbon $date
|
||||
* @param int $count
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
@@ -441,7 +442,7 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
* Update a recurring transaction.
|
||||
*
|
||||
* @param Recurrence $recurrence
|
||||
* @param array $data
|
||||
* @param array $data
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
|
||||
@@ -141,9 +141,9 @@ interface RecurringRepositoryInterface
|
||||
/**
|
||||
* @param Recurrence $recurrence
|
||||
*
|
||||
* @return Collection
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(Recurrence $recurrence): Collection;
|
||||
public function getTransactions(Recurrence $recurrence): array;
|
||||
|
||||
/**
|
||||
* Calculate the next X iterations starting on the date given in $date.
|
||||
|
||||
@@ -26,7 +26,6 @@ use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Factory\TagFactory;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
@@ -84,13 +83,13 @@ class TagRepository implements TagRepositoryInterface
|
||||
*/
|
||||
public function earnedInPeriod(Tag $tag, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setAllAssetAccounts()->setTag($tag);
|
||||
$set = $collector->getTransactions();
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setTag($tag);
|
||||
|
||||
return $collector->getSum();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +166,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
public function incomeInPeriod(Tag $tag, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector =app(GroupCollectorInterface::class);
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::DEPOSIT])->setTag($tag);
|
||||
@@ -244,13 +243,13 @@ class TagRepository implements TagRepositoryInterface
|
||||
*/
|
||||
public function spentInPeriod(Tag $tag, Carbon $start, Carbon $end): string
|
||||
{
|
||||
/** @var TransactionCollectorInterface $collector */
|
||||
$collector = app(TransactionCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setAllAssetAccounts()->setTag($tag);
|
||||
$set = $collector->getTransactions();
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
return (string)$set->sum('transaction_amount');
|
||||
$collector->setUser($this->user);
|
||||
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setTag($tag);
|
||||
|
||||
return $collector->getSum();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user