public static function billadjustment($account_id, $for_month, $amount, $bill) { $bill_info = Billinformation::where('bill_no', $bill->bill_no)->get(); foreach ($bill_info as $key) { $amount_id[] = $key->adjustment_id; } if (count($bill_info) == 0) { $amount_id[] = NULL; } $bill_amount = Adjustment::whereIn('id', $amount_id)->sum('amount'); if ($bill->adjustments == $bill_amount) { return $bill_amount; } else { if ($bill->adjustments && $bill_amount == 0) { $adjustment = new Adjustment(); $adjustment->account_id = $account_id; $adjustment->for_month = $for_month; $adjustment->amount = $amount; $adjustment->date = date('Y-m-d'); $adjustment->remarks = "billadjustment retransaction"; $adjustment->is_considered = 1; $adjustment->save(); $bill_info = Adjustment::adjustments($adjustment->id, $adjustment->account_id, $adjustment->for_month); return $adjustment->amount; } else { if ($bill->adjustments != $bill_amount) { return false; } } } }