Add transaction group filter
This commit is contained in:
parent
2eb0f76f32
commit
454b2b488b
@ -105,16 +105,17 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
|
||||
/**
|
||||
* Get the credit only balance of the journal based on a given date.
|
||||
* @param Journal $journal
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getCreditBalanceBetween(
|
||||
Carbon $date,
|
||||
Journal $journal=null,
|
||||
Carbon $start_date=null
|
||||
Carbon $start_date=null,
|
||||
$transaction_group=null
|
||||
): Money {
|
||||
|
||||
$where = [
|
||||
@ -129,6 +130,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
$where[] = ['post_date', '>=', $start_date];
|
||||
}
|
||||
|
||||
if ($transaction_group) {
|
||||
$where['transaction_group'] = $transaction_group;
|
||||
}
|
||||
|
||||
$balance = $this
|
||||
->findWhere($where, ['id', 'credit'])
|
||||
->sum('credit') ?: 0;
|
||||
@ -140,14 +145,14 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
* @param Carbon $date
|
||||
* @param Journal $journal
|
||||
* @param Carbon|null $start_date
|
||||
* @param null $transaction_group
|
||||
* @return Money
|
||||
* @throws \UnexpectedValueException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function getDebitBalanceBetween(
|
||||
Carbon $date,
|
||||
Journal $journal=null,
|
||||
Carbon $start_date=null
|
||||
Carbon $start_date=null,
|
||||
$transaction_group=null
|
||||
): Money {
|
||||
|
||||
$where = [
|
||||
@ -162,6 +167,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
|
||||
$where[] = ['post_date', '>=', $start_date];
|
||||
}
|
||||
|
||||
if($transaction_group) {
|
||||
$where['transaction_group'] = $transaction_group;
|
||||
}
|
||||
|
||||
$balance = $this
|
||||
->findWhere($where, ['id', 'debit'])
|
||||
->sum('debit') ?: 0;
|
||||
|
Loading…
Reference in New Issue
Block a user