mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-27 17:31:09 -06:00
List of categories will check transactions as well. #142
This commit is contained in:
parent
9baadd3793
commit
e4f45b5370
@ -209,20 +209,36 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
|||||||
/**
|
/**
|
||||||
* @param Category $category
|
* @param Category $category
|
||||||
*
|
*
|
||||||
* @return Carbon|null
|
* @return Carbon
|
||||||
*/
|
*/
|
||||||
public function getLatestActivity(Category $category): Carbon
|
public function getLatestActivity(Category $category): Carbon
|
||||||
{
|
{
|
||||||
|
$first = new Carbon('1900-01-01');
|
||||||
|
$second = new Carbon('1900-01-01');
|
||||||
$latest = $category->transactionjournals()
|
$latest = $category->transactionjournals()
|
||||||
->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')
|
||||||
->first();
|
->first();
|
||||||
if ($latest) {
|
if ($latest) {
|
||||||
return $latest->date;
|
$first = $latest->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Carbon('1900-01-01');
|
// could also be a transaction, nowadays:
|
||||||
|
$latestTransaction = $category->transactions()
|
||||||
|
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||||
|
->orderBy('transaction_journals.date', 'DESC')
|
||||||
|
->orderBy('transaction_journals.order', 'ASC')
|
||||||
|
->orderBy('transaction_journals.id', 'DESC')
|
||||||
|
->first(['transactions.*', 'transaction_journals.date']);
|
||||||
|
if ($latestTransaction) {
|
||||||
|
$second = new Carbon($latestTransaction->date);
|
||||||
|
}
|
||||||
|
if ($first > $second) {
|
||||||
|
return $first;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user