Fix tests and docs/better checks #130
This commit is contained in:
@@ -56,10 +56,20 @@ abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepositor
|
||||
* @param $order_by
|
||||
* @return $this
|
||||
*/
|
||||
public function whereOrder($where, $sort_by, $order_by)
|
||||
public function whereOrder($where, $sort_by, $order_by='asc')
|
||||
{
|
||||
return $this->scopeQuery(function($query) use ($where, $sort_by, $order_by) {
|
||||
return $query->where($where)->orderBy($sort_by, $order_by);
|
||||
$q = $query->where($where);
|
||||
# See if there are multi-column sorts
|
||||
if(\is_array($sort_by)) {
|
||||
foreach($sort_by as $key => $sort) {
|
||||
$q = $q->orderBy($key, $sort);
|
||||
}
|
||||
} else {
|
||||
$q = $q->orderBy($sort_by, $order_by);
|
||||
}
|
||||
|
||||
return $q;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,8 +137,9 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
@@ -173,6 +174,8 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @return array
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getAllForObject($object, $journal=null)
|
||||
{
|
||||
@@ -185,7 +188,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
$where['journal_id'] = $journal->id;
|
||||
}
|
||||
|
||||
$transactions = $this->findWhere($where);
|
||||
$transactions = $this->whereOrder($where, [
|
||||
'credit' => 'desc',
|
||||
'debit' => 'desc'
|
||||
])->get();
|
||||
|
||||
return [
|
||||
'credits' => new Money($transactions->sum('credit')),
|
||||
@@ -193,4 +199,24 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
'transactions' => $transactions,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all transactions for a given object
|
||||
* @param $object
|
||||
* @param null $journal
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAllForObject($object, $journal = null)
|
||||
{
|
||||
$where = [
|
||||
'ref_class' => \get_class($object),
|
||||
'ref_class_id' => $object->id,
|
||||
];
|
||||
|
||||
if ($journal) {
|
||||
$where['journal_id'] = $journal->id;
|
||||
}
|
||||
|
||||
$this->deleteWhere($where);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user