public static function BillBalance($account_id) { $amount_before_date = Bill::orderBy('bill_no', 'desc')->where('account_id', '=', $account_id)->get()->first(); if (count($amount_before_date) != 0) { $amount_before_due_date = $amount_before_date->amount_before_due_date; $amount_paid = Bill::orderBy('bill_no', 'desc')->where('account_id', '=', $account_id)->get()->first()->amount_paid; $bal = $amount_paid - $amount_before_due_date; if ($amount_paid == 0) { $bal = 0; } return $bal; } else { return 0; } }