More views and options for limits [skip ci]

This commit is contained in:
James Cole
2014-07-24 06:47:28 +02:00
parent 30553ed7a3
commit 36901359d0
13 changed files with 280 additions and 82 deletions

View File

@@ -20,7 +20,6 @@ class Toolkit implements ToolkitInterface
*/
public function getDateRange()
{
\Log::debug('Should be mocked!');
$preferences = \App::make('Firefly\Helper\Preferences\PreferencesHelperInterface');
$viewRange = $preferences->get('viewRange', '1M');

View File

@@ -34,13 +34,31 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
// $q->where('startdate',$date->format('Y-m-d'));
}, 'limits.limitrepetitions' => function ($q) use ($date) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
$q->where('startdate',$date->format('Y-m-d'));
$q->where('startdate', $date->format('Y-m-d'));
}]
)->orderBy('name', 'ASC')->get();
foreach ($set as $budget) {
$budget->count = 0;
foreach($budget->limits as $limit) {
foreach ($budget->limits as $limit) {
/** @var $rep \LimitRepetition */
foreach ($limit->limitrepetitions as $rep) {
$rep->left = $rep->left();
// overspent:
if ($rep->left < 0) {
$rep->spent = ($rep->left * -1) + $rep->amount;
$rep->overspent = $rep->left * -1;
$total = $rep->spent + $rep->overspent;
$rep->spent_pct = round(($rep->spent / $total) * 100);
$rep->overspent_pct = 100 - $rep->spent_pct;
} else {
$rep->spent = $rep->amount - $rep->left;
$rep->spent_pct = round(($rep->spent / $rep->amount) * 100);
$rep->left_pct = 100 - $rep->spent_pct;
}
}
$budget->count += count($limit->limitrepetitions);
}
}

View File

@@ -14,7 +14,9 @@ class EloquentLimitRepository implements LimitRepositoryInterface
public function find($limitId)
{
return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin('components', 'components.id', '=', 'limits.component_id')
return \Limit::with('limitrepetitions')->where('limits.id', $limitId)->leftJoin(
'components', 'components.id', '=', 'limits.component_id'
)
->where('components.user_id', \Auth::user()->id)->first(['limits.*']);
}

View File

@@ -167,7 +167,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
}
public function getByAccount(\Account $account, $count = 25)
public function getByAccountInDateRange(\Account $account, $count = 25,\Carbon\Carbon $start, \Carbon\Carbon $end)
{
$accountID = $account->id;
$query = \Auth::user()->transactionjournals()->with(
@@ -180,6 +180,8 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->where('accounts.id', $accountID)
->where('date','>=',$start->format('Y-m-d'))
->where('date','<=',$end->format('Y-m-d'))
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.id', 'DESC')
->take($count)

View File

@@ -11,7 +11,7 @@ interface TransactionJournalRepositoryInterface
public function find($journalId);
public function getByAccount(\Account $account, $count = 25);
public function getByAccountInDateRange(\Account $account, $count = 25,\Carbon\Carbon $start, \Carbon\Carbon $end);
public function getByAccountAndDate(\Account $account, \Carbon\Carbon $date);

View File

@@ -25,23 +25,11 @@ class EloquentLimitTrigger
// get todays date.
foreach ($budgets as $budget) {
\Log::debug(
'Now checking the ' . count($budget->limits) . ' limits in ' . $budget->name . ' (#' . $budget->id
. ').'
);
// loop limits:
foreach ($budget->limits as $limit) {
\Log::debug(
'Now at limit #' . $limit->id . ', which has ' . count($limit->limitrepetitions) . ' reps already'
);
\Log::debug(
'More: Amount: ' . $limit->amount . ', repeat: ' . $limit->repeats . ', freq: '
. $limit->repeat_freq
);
// should have a repetition, at the very least
// for the period it starts (startdate and onwards).
if (count($limit->limitrepetitions) == 0) {
\Log::debug('No reps, create one.');
// create such a repetition:
$repetition = new \LimitRepetition();
$start = clone $limit->startdate;
@@ -73,7 +61,6 @@ class EloquentLimitTrigger
$repetition->enddate = $end;
$repetition->amount = $limit->amount;
$repetition->limit()->associate($limit);
\Log::debug('Created single rep for non-repeating limit, from ' . $start . ' until ' . $end);
try {
$repetition->save();
@@ -163,7 +150,6 @@ class EloquentLimitTrigger
}
}
}
\Log::debug('Done checking the budget!');
}
}