Moved code to relate transfers to another class. Still needs some work.

This commit is contained in:
James Cole
2015-01-02 10:53:18 +01:00
parent fb58bf1bf5
commit 9a3aed8038
9 changed files with 262 additions and 183 deletions

View File

@@ -571,37 +571,4 @@ class TransactionJournal implements TransactionJournalInterface, CUDInterface, C
return \Paginator::make($items, $count, $limit);
}
/**
* @param string $query
* @param \TransactionJournal $journal
*
* @return Collection
*/
public function searchRelated($query, \TransactionJournal $journal)
{
$start = clone $journal->date;
$end = clone $journal->date;
$start->startOfMonth();
$end->endOfMonth();
// get already related transactions:
$exclude = [$journal->id];
foreach ($journal->transactiongroups()->get() as $group) {
foreach ($group->transactionjournals() as $current) {
$exclude[] = $current->id;
}
}
$exclude = array_unique($exclude);
$query = $this->getUser()->transactionjournals()
->withRelevantData()
->before($end)
->after($start)
->whereNotIn('id', $exclude)
->where('description', 'LIKE', '%' . $query . '%')
->get();
return $query;
}
}