Completed the renaming of some methods.

This commit is contained in:
James Cole 2015-12-24 10:27:45 +01:00
parent 55333156ac
commit 15fd8cf486
9 changed files with 22 additions and 125 deletions

View File

@ -63,7 +63,7 @@ class ReportHelper implements ReportHelperInterface
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$set = $repository->getCategories();
foreach ($set as $category) {
$spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
$spent = $repository->balanceInPeriod($category, $start, $end, $accounts);
$category->spent = $spent;
$object->addCategory($category);
}
@ -222,7 +222,7 @@ class ReportHelper implements ReportHelperInterface
// no repetition(s) for this budget:
if ($repetitions->count() == 0) {
$spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);
$spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);
$budgetLine->setOverspent($spent);
@ -237,7 +237,7 @@ class ReportHelper implements ReportHelperInterface
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget);
$budgetLine->setRepetition($repetition);
$expenses = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);
$expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts);
// 200 en -100 is 100, vergeleken met 0 === 1
// 200 en -200 is 0, vergeleken met 0 === 0

View File

@ -159,7 +159,7 @@ class BudgetController extends Controller
// loop the budgets:
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budget->spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);
$budget->spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
$budget->currentRep = $repository->getCurrentRepetition($budget, $start, $end);
if ($budget->currentRep) {
$budgeted = bcadd($budgeted, $budget->currentRep->amount);

View File

@ -86,7 +86,7 @@ class BudgetController extends Controller
$budgeted = 0;
} else {
$name = $budget->name;
$sum = $repository->balanceInPeriodForList($budget, $currentStart, $currentEnd, $accounts);
$sum = $repository->balanceInPeriod($budget, $currentStart, $currentEnd, $accounts);
$budgeted = $repository->getBudgetLimitRepetitions($budget, $currentStart, $currentEnd)->sum('amount');
}
@ -144,7 +144,7 @@ class BudgetController extends Controller
$end->subDay();
$chartDate = clone $end;
$chartDate->startOfMonth();
$spent = $repository->balanceInPeriodForList($budget, $first, $end, $accounts) * -1;
$spent = $repository->balanceInPeriod($budget, $first, $end, $accounts) * -1;
$entries->push([$chartDate, $spent]);
$first = Navigation::addPeriod($first, $range, 0);
}
@ -233,13 +233,13 @@ class BudgetController extends Controller
foreach ($budgets as $budget) {
$repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end);
if ($repetitions->count() == 0) {
$expenses = $repository->balanceInPeriodForList($budget, $start, $end, $accounts) * -1;
$expenses = $repository->balanceInPeriod($budget, $start, $end, $accounts) * -1;
$allEntries->push([$budget->name, 0, 0, $expenses, 0, 0]);
continue;
}
/** @var LimitRepetition $repetition */
foreach ($repetitions as $repetition) {
$expenses = $repository->balanceInPeriodForList($budget, $repetition->startdate, $repetition->enddate, $accounts) * -1;
$expenses = $repository->balanceInPeriod($budget, $repetition->startdate, $repetition->enddate, $accounts) * -1;
// $left can be less than zero.
// $overspent can be more than zero ( = overspending)
@ -293,7 +293,7 @@ class BudgetController extends Controller
// filter empty budgets:
foreach ($allBudgets as $budget) {
$spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);
$spent = $repository->balanceInPeriod($budget, $start, $end, $accounts);
if ($spent != 0) {
$budgets->push($budget);
}
@ -309,7 +309,7 @@ class BudgetController extends Controller
// each budget, fill the row:
foreach ($budgets as $budget) {
$spent = $repository->balanceInPeriodForList($budget, $start, $month, $accounts);
$spent = $repository->balanceInPeriod($budget, $start, $month, $accounts);
$row[] = $spent * -1;
}
$entries->push($row);

View File

@ -316,7 +316,7 @@ class CategoryController extends Controller
$entries = new Collection;
$categories = $allCategories->filter(
function (Category $category) use ($repository, $start, $end, $accounts) {
$spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
$spent = $repository->balanceInPeriod($category, $start, $end, $accounts);
if ($spent < 0) {
return $category;
}
@ -331,7 +331,7 @@ class CategoryController extends Controller
$row = [clone $start]; // make a row:
foreach ($categories as $category) { // each budget, fill the row
$spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);
$spent = $repository->balanceInPeriod($category, $start, $month, $accounts);
if ($spent < 0) {
$row[] = $spent * -1;
} else {
@ -375,7 +375,7 @@ class CategoryController extends Controller
$allEntries = new Collection;
$categories = $allCategories->filter(
function (Category $category) use ($repository, $start, $end, $accounts) {
$spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
$spent = $repository->balanceInPeriod($category, $start, $end, $accounts);
if ($spent > 0) {
return $category;
}
@ -390,7 +390,7 @@ class CategoryController extends Controller
$row = [clone $start]; // make a row:
foreach ($categories as $category) { // each budget, fill the row
$spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);
$spent = $repository->balanceInPeriod($category, $start, $month, $accounts);
if ($spent > 0) {
$row[] = $spent;
} else {

View File

@ -320,22 +320,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
*
* @return string
*/
public function balanceInPeriodForList(Budget $budget, Carbon $start, Carbon $end, Collection $accounts)
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, Collection $accounts)
{
return $this->commonBalanceInPeriodForList($budget, $start, $end, $accounts);
}
/**
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @param bool $shared
*
* @return string
*/
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true)
{
return $this->commonBalanceInPeriod($budget, $start, $end, $shared);
return $this->commonBalanceInPeriod($budget, $start, $end, $accounts);
}
/**

View File

@ -126,19 +126,6 @@ interface BudgetRepositoryInterface
*/
public function getWithoutBudgetSum(Carbon $start, Carbon $end);
/**
*
* Same as ::spentInPeriod but corrects journals for their amount (tags).
*
* @param Budget $budget
* @param Carbon $start
* @param Carbon $end
* @param boolean $shared
*
* @return string
*/
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true);
/**
*
* Same as ::spentInPeriod but corrects journals for a set of accounts
@ -150,7 +137,7 @@ interface BudgetRepositoryInterface
*
* @return string
*/
public function balanceInPeriodForList(Budget $budget, Carbon $start, Carbon $end, Collection $accounts);
public function balanceInPeriod(Budget $budget, Carbon $start, Carbon $end, Collection $accounts);
/**
* @param array $data

View File

@ -242,20 +242,6 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
->get(['transaction_journals.*']);
}
/**
* @param Category $category
* @param Carbon $start
* @param Carbon $end
*
* @param bool $shared
*
* @return string
*/
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)
{
return $this->commonBalanceInPeriod($category, $start, $end, $shared);
}
/**
* @param Category $category
* @param Carbon $start
@ -264,9 +250,9 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
*
* @return string
*/
public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts)
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, Collection $accounts)
{
return $this->commonBalanceInPeriodForList($category, $start, $end, $accounts);
return $this->commonBalanceInPeriod($category, $start, $end, $accounts);
}
/**

View File

@ -147,21 +147,7 @@ interface CategoryRepositoryInterface
public function getWithoutCategory(Carbon $start, Carbon $end);
/**
* Corrected for tags.
*
* @param Category $category
* @param \Carbon\Carbon $start
* @param \Carbon\Carbon $end
*
* @param bool $shared
*
* @return string
*/
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);
/**
* Corrected for tags.
* Corrected for tags and list of accounts.
*
* @param Category $category
* @param \Carbon\Carbon $start
@ -170,7 +156,7 @@ interface CategoryRepositoryInterface
*
* @return string
*/
public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts);
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, Collection $accounts);
/**
* @param Category $category

View File

@ -17,55 +17,6 @@ use Illuminate\Support\Collection;
class ComponentRepository
{
/**
* @param $object
* @param Carbon $start
* @param Carbon $end
*
* @param bool $shared
*
* @return string
*/
protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, $shared = false)
{
$cache = new CacheProperties; // we must cache this.
$cache->addProperty($object->id);
$cache->addProperty(get_class($object));
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($shared);
$cache->addProperty('balanceInPeriod');
if ($cache->has()) {
return $cache->get(); // @codeCoverageIgnore
}
if ($shared === true) { // shared is true: always ignore transfers between accounts!
$sum = $object->transactionjournals()
->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])
->before($end)
->after($start)
->get(['transaction_journals.*'])->sum('amount');
} else {
// do something else, SEE budgets.
// get all journals in this month where the asset account is NOT shared.
$sum = $object->transactionjournals()->before($end)->after($start)
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->transactionTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::OPENING_BALANCE])
->leftJoin(
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
)->where('account_meta.data', '!=', '"sharedAsset"')->get(['transaction_journals.*'])->sum('amount');
}
$cache->store($sum);
return $sum;
}
/**
* @param $object
* @param Carbon $start
@ -74,7 +25,7 @@ class ComponentRepository
*
* @return string
*/
protected function commonBalanceInPeriodForList($object, Carbon $start, Carbon $end, Collection $accounts)
protected function commonBalanceInPeriod($object, Carbon $start, Carbon $end, Collection $accounts)
{
$cache = new CacheProperties; // we must cache this.
$cache->addProperty($object->id);