mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 05:06:37 +00:00
Log.
This commit is contained in:
@@ -13,6 +13,7 @@ use Illuminate\Database\Query\Builder as QueryBuilder;
|
|||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Input;
|
use Input;
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BudgetRepository
|
* Class BudgetRepository
|
||||||
@@ -87,10 +88,10 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
/** @var Collection $repetitions */
|
/** @var Collection $repetitions */
|
||||||
return LimitRepetition::
|
return LimitRepetition::
|
||||||
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||||
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
|
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
|
||||||
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
|
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
|
||||||
->where('budget_limits.budget_id', $budget->id)
|
->where('budget_limits.budget_id', $budget->id)
|
||||||
->get(['limit_repetitions.*']);
|
->get(['limit_repetitions.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,9 +140,10 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
$data = $budget->limitrepetitions()
|
$data = $budget->limitrepetitions()
|
||||||
->where('limit_repetitions.startdate', $start)
|
->where('limit_repetitions.startdate', $start)
|
||||||
->where('limit_repetitions.enddate', $end)
|
->where('limit_repetitions.enddate', $end)
|
||||||
->first(['limit_repetitions.*']);
|
->first(['limit_repetitions.*']);
|
||||||
|
Log::debug('Looking for limit reps for budget #' . $budget->id . ' start [' . $start . '] and end [' . $end . '].');
|
||||||
$cache->store($data);
|
$cache->store($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
@@ -182,9 +184,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
/**
|
/**
|
||||||
* Returns all the transaction journals for a limit, possibly limited by a limit repetition.
|
* Returns all the transaction journals for a limit, possibly limited by a limit repetition.
|
||||||
*
|
*
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param LimitRepetition $repetition
|
* @param LimitRepetition $repetition
|
||||||
* @param int $take
|
* @param int $take
|
||||||
*
|
*
|
||||||
* @return LengthAwarePaginator
|
* @return LengthAwarePaginator
|
||||||
*/
|
*/
|
||||||
@@ -201,11 +203,11 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0;
|
$offset = intval(Input::get('page')) > 0 ? intval(Input::get('page')) * $take : 0;
|
||||||
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
|
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
|
||||||
->orderBy('transaction_journals.date', 'DESC')
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC');
|
->orderBy('transaction_journals.id', 'DESC');
|
||||||
$countQuery = $budget->transactionJournals();
|
$countQuery = $budget->transactionJournals();
|
||||||
|
|
||||||
|
|
||||||
@@ -215,7 +217,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$set = $setQuery->get(['transaction_journals.*']);
|
$set = $setQuery->get(['transaction_journals.*']);
|
||||||
$count = $countQuery->count();
|
$count = $countQuery->count();
|
||||||
|
|
||||||
|
|
||||||
@@ -249,9 +251,9 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
public function getLimitAmountOnDate(Budget $budget, Carbon $date)
|
public function getLimitAmountOnDate(Budget $budget, Carbon $date)
|
||||||
{
|
{
|
||||||
$repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
$repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
|
||||||
->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
|
->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
|
||||||
->where('budget_limits.budget_id', $budget->id)
|
->where('budget_limits.budget_id', $budget->id)
|
||||||
->first(['limit_repetitions.*']);
|
->first(['limit_repetitions.*']);
|
||||||
|
|
||||||
if ($repetition) {
|
if ($repetition) {
|
||||||
return $repetition->amount;
|
return $repetition->amount;
|
||||||
@@ -269,15 +271,15 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
public function getWithoutBudget(Carbon $start, Carbon $end)
|
public function getWithoutBudget(Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
return Auth::user()
|
return Auth::user()
|
||||||
->transactionjournals()
|
->transactionjournals()
|
||||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->whereNull('budget_transaction_journal.id')
|
->whereNull('budget_transaction_journal.id')
|
||||||
->before($end)
|
->before($end)
|
||||||
->after($start)
|
->after($start)
|
||||||
->orderBy('transaction_journals.date', 'DESC')
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
->orderBy('transaction_journals.order', 'ASC')
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
->orderBy('transaction_journals.id', 'DESC')
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
->get(['transaction_journals.*']);
|
->get(['transaction_journals.*']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -289,22 +291,22 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
public function getWithoutBudgetSum(Carbon $start, Carbon $end)
|
public function getWithoutBudgetSum(Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
$noBudgetSet = Auth::user()
|
$noBudgetSet = Auth::user()
|
||||||
->transactionjournals()
|
->transactionjournals()
|
||||||
->whereNotIn(
|
->whereNotIn(
|
||||||
'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
|
'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
|
||||||
$query
|
$query
|
||||||
->select('transaction_journals.id')
|
->select('transaction_journals.id')
|
||||||
->from('transaction_journals')
|
->from('transaction_journals')
|
||||||
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
|
||||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'))
|
->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'))
|
||||||
->whereNotNull('budget_transaction_journal.budget_id');
|
->whereNotNull('budget_transaction_journal.budget_id');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
->after($start)
|
->after($start)
|
||||||
->before($end)
|
->before($end)
|
||||||
->transactionTypes(['Withdrawal'])
|
->transactionTypes(['Withdrawal'])
|
||||||
->get(['transaction_journals.*'])->sum('amount');
|
->get(['transaction_journals.*'])->sum('amount');
|
||||||
|
|
||||||
bcscale(2);
|
bcscale(2);
|
||||||
|
|
||||||
@@ -315,7 +317,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param Carbon $start
|
* @param Carbon $start
|
||||||
* @param Carbon $end
|
* @param Carbon $end
|
||||||
* @param bool $shared
|
* @param bool $shared
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
@@ -334,7 +336,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
$newBudget = new Budget(
|
$newBudget = new Budget(
|
||||||
[
|
[
|
||||||
'user_id' => $data['user'],
|
'user_id' => $data['user'],
|
||||||
'name' => $data['name'],
|
'name' => $data['name'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$newBudget->save();
|
$newBudget->save();
|
||||||
@@ -345,14 +347,14 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Budget $budget
|
* @param Budget $budget
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @return Budget
|
* @return Budget
|
||||||
*/
|
*/
|
||||||
public function update(Budget $budget, array $data)
|
public function update(Budget $budget, array $data)
|
||||||
{
|
{
|
||||||
// update the account:
|
// update the account:
|
||||||
$budget->name = $data['name'];
|
$budget->name = $data['name'];
|
||||||
$budget->active = $data['active'];
|
$budget->active = $data['active'];
|
||||||
$budget->save();
|
$budget->save();
|
||||||
|
|
||||||
@@ -376,10 +378,10 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
|||||||
// if not, create one!
|
// if not, create one!
|
||||||
$limit = new BudgetLimit;
|
$limit = new BudgetLimit;
|
||||||
$limit->budget()->associate($budget);
|
$limit->budget()->associate($budget);
|
||||||
$limit->startdate = $date;
|
$limit->startdate = $date;
|
||||||
$limit->amount = $amount;
|
$limit->amount = $amount;
|
||||||
$limit->repeat_freq = 'monthly';
|
$limit->repeat_freq = 'monthly';
|
||||||
$limit->repeats = 0;
|
$limit->repeats = 0;
|
||||||
$limit->save();
|
$limit->save();
|
||||||
|
|
||||||
// likewise, there should be a limit repetition to match the end date
|
// likewise, there should be a limit repetition to match the end date
|
||||||
|
|||||||
Reference in New Issue
Block a user