Should fix tests.

This commit is contained in:
James Cole 2017-03-30 18:42:02 +02:00
parent 92cd3d60b9
commit ea984281b0
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
3 changed files with 70 additions and 34 deletions

View File

@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
class PopupReport implements PopupReportInterface
{
/**
* @param Budget $budget
* @param Account $account
@ -44,6 +45,25 @@ class PopupReport implements PopupReportInterface
return $journals;
}
/**
* @param Account $account
* @param array $attributes
*
* @return Collection
*/
public function balanceForNoBudget(Account $account, array $attributes): Collection
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setTypes([TransactionType::WITHDRAWAL])
->setRange($attributes['startDate'], $attributes['endDate'])
->withoutBudget();
return $collector->getJournals();
}
/**
* @param Budget $budget
* @param array $attributes
@ -145,4 +165,35 @@ class PopupReport implements PopupReportInterface
return $journals;
}
/**
* @param $account
* @param $attributes
*
* @return Collection
*/
public function balanceDifference($account, $attributes): Collection
{
// row that displays difference
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setTypes([TransactionType::WITHDRAWAL])
->setRange($attributes['startDate'], $attributes['endDate'])
->withoutBudget();
$journals = $collector->getJournals();
return $journals->filter(
function (Transaction $transaction) {
$tags = $transaction->transactionJournal->tags()->where('tagMode', 'balancingAct')->count();
if ($tags === 0) {
return true;
}
return false;
}
);
}
}

View File

@ -24,6 +24,14 @@ use Illuminate\Support\Collection;
interface PopupReportInterface
{
/**
* @param $account
* @param $attributes
*
* @return Collection
*/
public function balanceDifference($account, $attributes): Collection;
/**
* @param Budget $budget
* @param Account $account
@ -33,6 +41,14 @@ interface PopupReportInterface
*/
public function balanceForBudget(Budget $budget, Account $account, array $attributes): Collection;
/**
* @param Account $account
* @param array $attributes
*
* @return Collection
*/
public function balanceForNoBudget(Account $account, array $attributes): Collection;
/**
* @param Budget $budget
* @param array $attributes

View File

@ -17,17 +17,14 @@ namespace FireflyIII\Http\Controllers\Popup;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collection\BalanceLine;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Report\PopupReportInterface;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Support\Binder\AccountList;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use InvalidArgumentException;
use Response;
use View;
@ -128,7 +125,6 @@ class ReportController extends Controller
$role = intval($attributes['role']);
$budget = $this->budgetRepository->find(intval($attributes['budgetId']));
$account = $this->accountRepository->find(intval($attributes['accountId']));
$types = [TransactionType::WITHDRAWAL];
switch (true) {
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
@ -139,37 +135,10 @@ class ReportController extends Controller
// normal row without a budget:
$journals = $this->popupHelper->balanceForNoBudget($account, $attributes);
$budget->name = strval(trans('firefly.no_budget'));
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setTypes($types)
->setRange($attributes['startDate'], $attributes['endDate'])
->withoutBudget();
$journals = $collector->getJournals();
break;
case ($role === BalanceLine::ROLE_DIFFROLE):
// row that displays difference
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setTypes($types)
->setRange($attributes['startDate'], $attributes['endDate'])
->withoutBudget();
$journals = $collector->getJournals();
$journals = $this->popupHelper->balanceDifference($account, $attributes);
$budget->name = strval(trans('firefly.leftUnbalanced'));
$journals = $journals->filter(
function (Transaction $transaction) {
$tags = $transaction->transactionJournal->tags()->where('tagMode', 'balancingAct')->count();
if ($tags === 0) {
return true;
}
return false;
}
);
break;
case ($role === BalanceLine::ROLE_TAGROLE):
// row with tag info.