mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-16 11:42:06 -06:00
Should fix tests.
This commit is contained in:
parent
92cd3d60b9
commit
ea984281b0
@ -27,6 +27,7 @@ use Illuminate\Support\Collection;
|
|||||||
class PopupReport implements PopupReportInterface
|
class PopupReport implements PopupReportInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
@ -44,6 +45,25 @@ class PopupReport implements PopupReportInterface
|
|||||||
return $journals;
|
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 Budget $budget
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
@ -145,4 +165,35 @@ class PopupReport implements PopupReportInterface
|
|||||||
|
|
||||||
return $journals;
|
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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -24,15 +24,31 @@ use Illuminate\Support\Collection;
|
|||||||
interface PopupReportInterface
|
interface PopupReportInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $account
|
||||||
|
* @param $attributes
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function balanceDifference($account, $attributes): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): Collection;
|
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 Budget $budget
|
||||||
* @param array $attributes
|
* @param array $attributes
|
||||||
|
@ -17,17 +17,14 @@ namespace FireflyIII\Http\Controllers\Popup;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Helpers\Collection\BalanceLine;
|
use FireflyIII\Helpers\Collection\BalanceLine;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|
||||||
use FireflyIII\Helpers\Report\PopupReportInterface;
|
use FireflyIII\Helpers\Report\PopupReportInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Transaction;
|
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Support\Binder\AccountList;
|
use FireflyIII\Support\Binder\AccountList;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Response;
|
use Response;
|
||||||
use View;
|
use View;
|
||||||
@ -128,7 +125,6 @@ class ReportController extends Controller
|
|||||||
$role = intval($attributes['role']);
|
$role = intval($attributes['role']);
|
||||||
$budget = $this->budgetRepository->find(intval($attributes['budgetId']));
|
$budget = $this->budgetRepository->find(intval($attributes['budgetId']));
|
||||||
$account = $this->accountRepository->find(intval($attributes['accountId']));
|
$account = $this->accountRepository->find(intval($attributes['accountId']));
|
||||||
$types = [TransactionType::WITHDRAWAL];
|
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
|
case ($role === BalanceLine::ROLE_DEFAULTROLE && !is_null($budget->id)):
|
||||||
@ -137,39 +133,12 @@ class ReportController extends Controller
|
|||||||
break;
|
break;
|
||||||
case ($role === BalanceLine::ROLE_DEFAULTROLE && is_null($budget->id)):
|
case ($role === BalanceLine::ROLE_DEFAULTROLE && is_null($budget->id)):
|
||||||
// normal row without a budget:
|
// normal row without a budget:
|
||||||
$journals = $this->popupHelper->balanceForNoBudget($account, $attributes);
|
$journals = $this->popupHelper->balanceForNoBudget($account, $attributes);
|
||||||
$budget->name = strval(trans('firefly.no_budget'));
|
$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;
|
break;
|
||||||
case ($role === BalanceLine::ROLE_DIFFROLE):
|
case ($role === BalanceLine::ROLE_DIFFROLE):
|
||||||
// row that displays difference
|
$journals = $this->popupHelper->balanceDifference($account, $attributes);
|
||||||
/** @var JournalCollectorInterface $collector */
|
|
||||||
$collector = app(JournalCollectorInterface::class);
|
|
||||||
$collector
|
|
||||||
->setAccounts(new Collection([$account]))
|
|
||||||
->setTypes($types)
|
|
||||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
|
||||||
->withoutBudget();
|
|
||||||
$journals = $collector->getJournals();
|
|
||||||
|
|
||||||
$budget->name = strval(trans('firefly.leftUnbalanced'));
|
$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;
|
break;
|
||||||
case ($role === BalanceLine::ROLE_TAGROLE):
|
case ($role === BalanceLine::ROLE_TAGROLE):
|
||||||
// row with tag info.
|
// row with tag info.
|
||||||
|
Loading…
Reference in New Issue
Block a user