mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-20 19:42:02 +00:00
Some code cleanup [skip ci]
This commit is contained in:
@@ -134,7 +134,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
'accounts.*',
|
||||
'ccType.data as ccType',
|
||||
'accountRole.data as accountRole',
|
||||
DB::Raw('SUM(`transactions`.`amount`) AS `balance`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) AS `balance`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -329,7 +329,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
$balance = Steam::balance($account, $date, true);
|
||||
/** @var PiggyBank $p */
|
||||
foreach ($account->piggybanks()->get() as $p) {
|
||||
foreach ($account->piggyBanks()->get() as $p) {
|
||||
$balance = bcsub($p->currentRelevantRep()->currentamount, $balance);
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->transactionTypes([TransactionType::OPENING_BALANCE])
|
||||
->orderBy('created_at', 'ASC')
|
||||
->first(['transaction_journals.*']);
|
||||
if(is_null($journal)) {
|
||||
if (is_null($journal)) {
|
||||
return new TransactionJournal;
|
||||
}
|
||||
|
||||
|
@@ -48,7 +48,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
->get(
|
||||
[
|
||||
'bills.*',
|
||||
DB::Raw('(`bills`.`amount_min` + `bills`.`amount_max` / 2) as `expectedAmount`'),
|
||||
DB::raw('(`bills`.`amount_min` + `bills`.`amount_max` / 2) as `expectedAmount`'),
|
||||
]
|
||||
)->sortBy('name');
|
||||
|
||||
@@ -83,7 +83,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
[
|
||||
'transaction_journals.bill_id',
|
||||
'transaction_journals.id',
|
||||
DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) as `journalAmount`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -173,7 +173,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
$sumAmount = $paid->sum_amount ?? '0';
|
||||
$amount = bcadd($amount, $sumAmount);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
|
||||
}
|
||||
)
|
||||
->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
$sumAmount = $paid->sum_amount ?? '0';
|
||||
$paidBill = bcadd($sumAmount, $paidBill);
|
||||
}
|
||||
@@ -257,7 +257,7 @@ class BillRepository implements BillRepositoryInterface
|
||||
'transactions', function (JoinClause $join) {
|
||||
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('transactions.amount', '>', 0);
|
||||
}
|
||||
)->first([DB::Raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
)->first([DB::raw('SUM(`transactions`.`amount`) as `sum_amount`')]);
|
||||
|
||||
$amount = bcadd($amount, $set->sum_amount);
|
||||
} else {
|
||||
|
@@ -135,8 +135,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->get(
|
||||
[
|
||||
'budgets.*',
|
||||
DB::Raw('DATE_FORMAT(`limit_repetitions`.`startdate`,"%Y") as `dateFormatted`'),
|
||||
DB::Raw('SUM(`limit_repetitions`.`amount`) as `budgeted`'),
|
||||
DB::raw('DATE_FORMAT(`limit_repetitions`.`startdate`,"%Y") as `dateFormatted`'),
|
||||
DB::raw('SUM(`limit_repetitions`.`amount`) as `budgeted`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -191,8 +191,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->get(
|
||||
[
|
||||
'budgets.*',
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
|
||||
DB::Raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -254,8 +254,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->get(
|
||||
[
|
||||
'budgets.*',
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y") AS `dateFormatted`'),
|
||||
DB::Raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y") AS `dateFormatted`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) AS `sumAmount`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -365,7 +365,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->where('transactions.amount', '<', 0)
|
||||
->groupBy('transaction_journals.date')
|
||||
->orderBy('transaction_journals.date')
|
||||
->get(['transaction_journals.date', DB::Raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
|
||||
->get(['transaction_journals.date', DB::raw('SUM(`transactions`.`amount`) as `dailyAmount`')]);
|
||||
|
||||
return $set;
|
||||
}
|
||||
@@ -395,8 +395,8 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->orderBy('transaction_journals.date')
|
||||
->get(
|
||||
[
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
|
||||
DB::Raw('SUM(`transactions`.`amount`) as `monthlyAmount`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`, "%Y-%m") AS `dateFormatted`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) as `monthlyAmount`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -447,11 +447,11 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
public function getJournals(Budget $budget, LimitRepetition $repetition = null, int $take = 50)
|
||||
{
|
||||
$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.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC');
|
||||
$countQuery = $budget->transactionJournals();
|
||||
$countQuery = $budget->transactionjournals();
|
||||
|
||||
|
||||
if (!is_null($repetition->id)) {
|
||||
@@ -519,7 +519,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
}
|
||||
)
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->first([DB::Raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
|
||||
->first([DB::raw('SUM(`transactions`.`amount`) as `journalAmount`')]);
|
||||
if (is_null($entry->journalAmount)) {
|
||||
return '';
|
||||
}
|
||||
@@ -561,7 +561,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->groupBy('dateFormatted')
|
||||
->get(
|
||||
['transaction_journals.date as dateFormatted', 'budget_transaction_journal.budget_id',
|
||||
DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]
|
||||
DB::raw('SUM(`transactions`.`amount`) AS `sum`')]
|
||||
);
|
||||
|
||||
$return = [];
|
||||
@@ -618,7 +618,7 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
->get(
|
||||
[
|
||||
't_from.account_id', 'budget_transaction_journal.budget_id',
|
||||
DB::Raw('SUM(`t_from`.`amount`) AS `spent`'),
|
||||
DB::raw('SUM(`t_from`.`amount`) AS `spent`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -643,13 +643,13 @@ class BudgetRepository extends ComponentRepository implements BudgetRepositoryIn
|
||||
public function spentPerDay(Budget $budget, Carbon $start, Carbon $end)
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $budget->transactionJournals()
|
||||
$query = $budget->transactionjournals()
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.amount', '<', 0)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->groupBy('dateFormatted')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
->groupBy('dateFormatted')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
|
||||
$return = [];
|
||||
foreach ($query->toArray() as $entry) {
|
||||
|
@@ -60,8 +60,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
->get(
|
||||
[
|
||||
'categories.*',
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||
DB::raw('SUM(`t_dest`.`amount`) AS `earned`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -121,9 +121,9 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
->get(
|
||||
[
|
||||
'categories.*',
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
|
||||
'transaction_types.type',
|
||||
DB::Raw('SUM(`amount`) as `sum`'),
|
||||
DB::raw('SUM(`amount`) as `sum`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -198,8 +198,8 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
$collection = $query->get(
|
||||
[
|
||||
'categories.*',
|
||||
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||
DB::Raw('SUM(`t_src`.`amount`) AS `spent`'),
|
||||
DB::raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
|
||||
DB::raw('SUM(`t_src`.`amount`) AS `spent`'),
|
||||
]
|
||||
);
|
||||
|
||||
@@ -272,7 +272,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
$single = $query->first(
|
||||
[
|
||||
DB::Raw('SUM(`transactions`.`amount`) as `sum`'),
|
||||
DB::raw('SUM(`transactions`.`amount`) as `sum`'),
|
||||
]
|
||||
);
|
||||
if (!is_null($single)) {
|
||||
|
@@ -72,13 +72,13 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionJournals()
|
||||
$query = $category->transactionjournals()
|
||||
->transactionTypes([TransactionType::DEPOSIT])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.amount', '>', 0)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
|
||||
$return = [];
|
||||
foreach ($query->toArray() as $entry) {
|
||||
@@ -115,7 +115,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
{
|
||||
$offset = $page > 0 ? $page * 50 : 0;
|
||||
|
||||
return $category->transactionJournals()->withRelevantData()->take(50)->offset($offset)
|
||||
return $category->transactionjournals()->withRelevantData()->take(50)->offset($offset)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
@@ -137,7 +137,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
{
|
||||
$offset = $page > 0 ? $page * 50 : 0;
|
||||
|
||||
return $category->transactionJournals()
|
||||
return $category->transactionjournals()
|
||||
->after($start)
|
||||
->before($end)
|
||||
->withRelevantData()->take(50)->offset($offset)
|
||||
@@ -186,13 +186,13 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionJournals()
|
||||
$query = $category->transactionjournals()
|
||||
->transactionTypes([TransactionType::WITHDRAWAL])
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('transactions.amount', '<', 0)
|
||||
->before($end)
|
||||
->after($start)
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::Raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
->groupBy('date')->get(['transaction_journals.date as dateFormatted', DB::raw('SUM(`transactions`.`amount`) AS `sum`')]);
|
||||
|
||||
$return = [];
|
||||
foreach ($query->toArray() as $entry) {
|
||||
|
@@ -48,7 +48,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
*/
|
||||
public function getEventSummarySet(PiggyBank $piggyBank)
|
||||
{
|
||||
return DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::Raw('SUM(`amount`) AS `sum`')]);
|
||||
return DB::table('piggy_bank_events')->where('piggy_bank_id', $piggyBank->id)->groupBy('date')->get(['date', DB::raw('SUM(`amount`) AS `sum`')]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -58,7 +58,7 @@ class TagRepository implements TagRepositoryInterface
|
||||
->get(
|
||||
[
|
||||
't_to.account_id',
|
||||
DB::Raw('SUM(`t_to`.`amount`) as `sum`'),
|
||||
DB::raw('SUM(`t_to`.`amount`) as `sum`'),
|
||||
]
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user