Count negative payment_items towards payment balance
This commit is contained in:
parent
5e82f091c0
commit
d1fbb4b42b
@ -95,7 +95,7 @@ class Payment extends Model implements IDs
|
|||||||
public function scopeUnapplied($query)
|
public function scopeUnapplied($query)
|
||||||
{
|
{
|
||||||
return $query
|
return $query
|
||||||
->select(['payments.id','paid_at','account_id','checkout_id','total_amt',DB::raw("SUM(amount) as allocated")])
|
->select(['payments.id','paid_at','account_id','checkout_id','total_amt',DB::raw("SUM(ABS(amount)) as allocated")])
|
||||||
->leftJoin('payment_items',['payment_items.payment_id'=>'payments.id'])
|
->leftJoin('payment_items',['payment_items.payment_id'=>'payments.id'])
|
||||||
->groupBy(['payments.id','paid_at','total_amt','account_id','checkout_id'])
|
->groupBy(['payments.id','paid_at','total_amt','account_id','checkout_id'])
|
||||||
->having(DB::raw('ROUND(total_amt-IFNULL(allocated,0),2)'),'>',self::threshold);
|
->having(DB::raw('ROUND(total_amt-IFNULL(allocated,0),2)'),'>',self::threshold);
|
||||||
|
Loading…
Reference in New Issue
Block a user