Various fixes for #916

This commit is contained in:
James Cole 2017-10-14 07:58:29 +02:00
parent 70ab42bc43
commit 401ae92a62
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
4 changed files with 9 additions and 20 deletions

View File

@ -91,8 +91,6 @@ class JournalCollector implements JournalCollectorInterface
'account_types.type as account_type',
];
/** @var bool */
private $filterTransfers = false;
/** @var array */
private $filters = [InternalTransferFilter::class];
@ -125,7 +123,7 @@ class JournalCollector implements JournalCollectorInterface
public function addFilter(string $filter): JournalCollectorInterface
{
$interfaces = class_implements($filter);
if (in_array(FilterInterface::class, $interfaces)) {
if (in_array(FilterInterface::class, $interfaces) && !in_array($filter, $this->filters) ) {
Log::debug(sprintf('Enabled filter %s', $filter));
$this->filters[] = $filter;
}
@ -237,7 +235,6 @@ class JournalCollector implements JournalCollectorInterface
if ($accounts->count() > 1) {
$this->addFilter(TransferFilter::class);
$this->filterTransfers = true;
}
@ -261,7 +258,6 @@ class JournalCollector implements JournalCollectorInterface
if ($accounts->count() > 1) {
$this->addFilter(TransferFilter::class);
$this->filterTransfers = true;
}
return $this;

View File

@ -17,13 +17,12 @@ use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Http\Requests\BudgetFormRequest;
use FireflyIII\Http\Requests\BudgetIncomeRequest;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Support\CacheProperties;
@ -447,8 +446,6 @@ class BudgetController extends Controller
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation();
$journals = $collector->getPaginatedJournals();
$journals->setPath(route('budgets.show', [$budget->id, $budgetLimit->id]));
$start = session('first', Carbon::create()->startOfYear());
$end = new Carbon;
$limits = $this->getLimits($budget, $start, $end);
@ -541,15 +538,12 @@ class BudgetController extends Controller
return $cache->get(); // @codeCoverageIgnore
}
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH]);
$set = $this->repository->getBudgetLimits($budget, $start, $end);
$limits = new Collection();
$set = $this->repository->getBudgetLimits($budget, $start, $end);
$limits = new Collection();
/** @var BudgetLimit $entry */
foreach ($set as $entry) {
$entry->spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $entry->start_date, $entry->end_date);
$entry->spent = $this->repository->spentInPeriod(new Collection([$budget]), new Collection(), $entry->start_date, $entry->end_date);
$limits->push($entry);
}
$cache->store($limits);

View File

@ -175,7 +175,7 @@ class BudgetController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget);
$collector->setAllAssetAccounts()->setBudget($budget);
if (!is_null($budgetLimit->id)) {
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
}
@ -220,7 +220,7 @@ class BudgetController extends Controller
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setAllAssetAccounts()->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withCategoryInformation();
$collector->setAllAssetAccounts()->setBudget($budget)->withCategoryInformation();
if (!is_null($budgetLimit->id)) {
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
}
@ -244,7 +244,6 @@ class BudgetController extends Controller
$data = $this->generator->pieChart($chartData);
$cache->store($data);
return Response::json($data);
}
@ -439,7 +438,7 @@ class BudgetController extends Controller
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$accounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::EXPENSE]);
$accounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::EXPENSE, AccountType::CASH]);
$grouped = $accounts->groupBy('id')->toArray();
$return = [];
foreach ($accountIds as $accountId) {

View File

@ -492,7 +492,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user);
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setBudgets($budgets);
$collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
if ($accounts->count() > 0) {
$collector->setAccounts($accounts);