mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Remove complicated no longer used methods #524
This commit is contained in:
parent
a79b2a7773
commit
1be49876df
@ -466,124 +466,4 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $categories
|
||||
* @param Collection $accounts
|
||||
* @param string $type
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function sumInPeriod(Collection $categories, Collection $accounts, string $type, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$categoryIds = $categories->pluck('id')->toArray();
|
||||
$query = $this->user
|
||||
->transactionJournals()
|
||||
->leftJoin( // join source transaction
|
||||
'transactions as source_transactions', function (JoinClause $join) {
|
||||
$join->on('source_transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('source_transactions.amount', '<', 0);
|
||||
|
||||
}
|
||||
)
|
||||
->leftJoin( // join destination transaction (slighly more complex)
|
||||
'transactions as destination_transactions', function (JoinClause $join) {
|
||||
$join->on('destination_transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->where('destination_transactions.amount', '>', 0)
|
||||
->where('destination_transactions.identifier', '=', DB::raw('source_transactions.identifier'));
|
||||
}
|
||||
)
|
||||
// left join source category:
|
||||
->leftJoin('category_transaction as source_cat_trans', 'source_transactions.id', '=', 'source_cat_trans.transaction_id')
|
||||
// left join destination category:
|
||||
->leftJoin('category_transaction as dest_cat_trans', 'source_transactions.id', '=', 'dest_cat_trans.transaction_id')
|
||||
// left join journal category:
|
||||
->leftJoin('category_transaction_journal as journal_category', 'journal_category.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
// left join transaction type:
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
// where nothing is deleted:
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('source_transactions.deleted_at')
|
||||
->whereNull('destination_transactions.deleted_at')
|
||||
// in correct date range:
|
||||
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
|
||||
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
|
||||
// correct categories (complex)
|
||||
->where(
|
||||
function ($q1) use ($categoryIds) {
|
||||
$q1->where(
|
||||
function ($q2) use ($categoryIds) {
|
||||
// source and destination transaction have categories, journal does not.
|
||||
$q2->whereIn('source_cat_trans.category_id', $categoryIds);
|
||||
$q2->whereIn('dest_cat_trans.category_id', $categoryIds);
|
||||
$q2->whereNull('journal_category.category_id');
|
||||
}
|
||||
);
|
||||
$q1->orWhere(
|
||||
function ($q3) use ($categoryIds) {
|
||||
// journal has category, source and destination have not
|
||||
$q3->whereNull('source_cat_trans.category_id');
|
||||
$q3->whereNull('dest_cat_trans.category_id');
|
||||
$q3->whereIn('journal_category.category_id', $categoryIds);
|
||||
}
|
||||
);
|
||||
}
|
||||
)
|
||||
// type:
|
||||
->where('transaction_types.type', $type);
|
||||
// accounts, if present:
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$query->where(
|
||||
function ($q) use ($accountIds) {
|
||||
$q->whereIn('source_transactions.account_id', $accountIds);
|
||||
$q->orWhereIn('destination_transactions.account_id', $accountIds);
|
||||
}
|
||||
);
|
||||
}
|
||||
$sum = strval($query->sum('destination_transactions.amount'));
|
||||
if ($sum === '') {
|
||||
$sum = '0';
|
||||
}
|
||||
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $accounts
|
||||
* @param array $types
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function sumInPeriodWithoutCategory(Collection $accounts, array $types, Carbon $start, Carbon $end): string
|
||||
{
|
||||
$query = $this->user->transactionJournals()
|
||||
->distinct()
|
||||
->transactionTypes($types)
|
||||
->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin(
|
||||
'transactions as t', function (JoinClause $join) {
|
||||
$join->on('t.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin('category_transaction', 't.id', '=', 'category_transaction.transaction_id')
|
||||
->whereNull('category_transaction_journal.id')
|
||||
->whereNull('category_transaction.id')
|
||||
->before($end)
|
||||
->after($start);
|
||||
|
||||
if ($accounts->count() > 0) {
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
|
||||
$query->whereIn('t.account_id', $accountIds);
|
||||
}
|
||||
$sum = strval($query->sum('t.amount'));
|
||||
|
||||
return $sum;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user