diff --git a/app/Models/Payment.php b/app/Models/Payment.php index a3fe116..3434074 100644 --- a/app/Models/Payment.php +++ b/app/Models/Payment.php @@ -95,7 +95,7 @@ class Payment extends Model implements IDs public function scopeUnapplied($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']) ->groupBy(['payments.id','paid_at','total_amt','account_id','checkout_id']) ->having(DB::raw('ROUND(total_amt-IFNULL(allocated,0),2)'),'>',self::threshold);