Add transaction group filter

This commit is contained in:
Nabeel Shahzad 2018-03-04 09:45:23 -06:00
parent 2eb0f76f32
commit 454b2b488b

View File

@ -105,16 +105,17 @@ class JournalRepository extends BaseRepository implements CacheableInterface
/** /**
* Get the credit only balance of the journal based on a given date. * Get the credit only balance of the journal based on a given date.
* @param Journal $journal
* @param Carbon $date * @param Carbon $date
* @param Journal $journal
* @param Carbon|null $start_date
* @param null $transaction_group
* @return Money * @return Money
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/ */
public function getCreditBalanceBetween( public function getCreditBalanceBetween(
Carbon $date, Carbon $date,
Journal $journal=null, Journal $journal=null,
Carbon $start_date=null Carbon $start_date=null,
$transaction_group=null
): Money { ): Money {
$where = [ $where = [
@ -129,6 +130,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
$where[] = ['post_date', '>=', $start_date]; $where[] = ['post_date', '>=', $start_date];
} }
if ($transaction_group) {
$where['transaction_group'] = $transaction_group;
}
$balance = $this $balance = $this
->findWhere($where, ['id', 'credit']) ->findWhere($where, ['id', 'credit'])
->sum('credit') ?: 0; ->sum('credit') ?: 0;
@ -140,14 +145,14 @@ class JournalRepository extends BaseRepository implements CacheableInterface
* @param Carbon $date * @param Carbon $date
* @param Journal $journal * @param Journal $journal
* @param Carbon|null $start_date * @param Carbon|null $start_date
* @param null $transaction_group
* @return Money * @return Money
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*/ */
public function getDebitBalanceBetween( public function getDebitBalanceBetween(
Carbon $date, Carbon $date,
Journal $journal=null, Journal $journal=null,
Carbon $start_date=null Carbon $start_date=null,
$transaction_group=null
): Money { ): Money {
$where = [ $where = [
@ -162,6 +167,10 @@ class JournalRepository extends BaseRepository implements CacheableInterface
$where[] = ['post_date', '>=', $start_date]; $where[] = ['post_date', '>=', $start_date];
} }
if($transaction_group) {
$where['transaction_group'] = $transaction_group;
}
$balance = $this $balance = $this
->findWhere($where, ['id', 'debit']) ->findWhere($where, ['id', 'debit'])
->sum('debit') ?: 0; ->sum('debit') ?: 0;