@php use App\Http\Controllers\GlobalMethods as SuperM; use App\Models\Loan\Loan; use Carbon\Carbon; $status = $_GET['status']; $date1 = Carbon::parse($_GET['start_date']); $date2 = Carbon::parse($_GET['end_date']); $type = $_GET['type']; $request_type = $_GET['request_type']; $with = $_GET['with']; $files = Loan::whereBetween('created_at', [$date1, $date2]) ->orderBy('id', 'asc') ->with('repayments', 'top_ups', 'offer', 'agents', 'status', 'topped_up', 'user'); if ($status != 'all') { $files = $files->whereHas('status', function ($query) use ($status) { $query->where('status', $status); }); } if ($type != 'all') { $files = $files->where('type', $type); } if ($request_type != 'all') { $files = $files->where('request_type', $request_type); } $files = $files->get(); if ($with == 'over') { $files = SuperM::sortOverDeductions($files); } elseif ($with == 'under') { $files = SuperM::sortUnderDeductions($files); } elseif ($with == 'allcompleted') { $files = SuperM::sortFullPayDeductions($files); } elseif ($with == 'failed') { $files = SuperM::sortFailedDeductions($files); } $data = "
USER DETAILS | LOAN DETAILS | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SN | UNIQUE ID | FIRST NAME | LAST NAME | OTHER NAME | PHONE NUMBER | STAFF ID | DATE JOINED | ACCOUNT OFFICER | STATUS | TENOR (MONTH) | AMOUNT (N) | INTEREST (%) | LOAN TYPE | REQUEST TYPE | LOAN TYPE (AGENCY) | MONTHLY REPAYMENT | FIRST REPAYMENT | LAST REPAYMENT | SUCCESSFUL DEDUCTIONS | SUCCESSFUL DEDUCTIONS SUM (N) | FAILED DEDUCTIONS | UNDER DEDUCTIONS | OVER DEDUCTIONS | TOPUP BALANCE | TOPUP STATUS | LIQUIDATION BALANCE | DATE APPROVED | DATE IMPORTED | |||||||||||
' . $i++ . ' | '; $data .= '' . $file->unique_id . ' | '; $data .= '' . ucwords($file->more->account_info->first_name) . ' | '; $data .= '' . ucwords($file->more->account_info->last_name) . ' | '; $data .= '' . ucwords($file->more->account_info->other_name) . ' | '; $data .= '' . $file->more->account_info->phone_number . ' | '; if (isset($file->more->account_info->email)) { $data .= '' . strtolower($file->more->account_info->email) . ' | '; } else { $data .= '- | '; } $data .= '' . $file->more->account_info->staff_id . ' | '; $data .= '' . $file->created_at->format('l F d, Y h:i A') . ' | '; if ($agent) { $data .= '' . strtoupper($agent->first_name . ' ' . $agent->last_name) . ' | '; } else { if ($file->user->referred_by) { $ref = $file->user->referred_by; $data .= '' . strtoupper($ref->first_name . ' ' . $ref->last_name) . ' | '; } else { $data .= '- | '; } } $data .= '' . $file->status->status . ' | '; if ($offer) { $data .= '' . $offer->more->tenor . ' | '; $data .= '' . number_format($offer->more->amount, 2) . ' | '; $data .= '' . number_format($offer->more->interest, 1) . '% | '; } else { $data .= '- | '; $data .= '- | '; $data .= '- | '; } $data .= '' . strtoupper($file->type) . ' | '; $data .= '' . strtoupper($file->request_type) . ' | '; if ($file->type == 'public') { $data .= '' . strtoupper($file->more->loan_type) . ' | '; } else { $data .= '- | '; } $data .= '' . number_format(SuperM::getMonthlyRepayment($file), 2) . ' | '; $firstRepay = SuperM::getFirstRepayment($file); if ($firstRepay) { $data .= '' . $firstRepay->format('Y-m-d') . ' | '; } else { $data .= '- | '; } $lastRepay = SuperM::getLastRepayment($file); if ($lastRepay) { $data .= '' . $lastRepay->format('Y-m-d') . ' | '; } else { $data .= '- | '; } $data .= '' . $file->repayments()->count() . ' | '; $data .= '' . number_format($file->repayments()->sum('amount'), 2) . ' | '; $data .= '' . SuperM::getFailedDeductions($file) . ' | '; $data .= '' . SuperM::getUnderDeductions($file) . ' | '; $data .= '' . SuperM::getOverDeductions($file) . ' | '; $data .= '' . number_format(SuperM::getTopUpBalance($file), 2) . ' | '; $data .= '' . SuperM::getTopUpStatus($file) . ' | '; $data .= '' . number_format(SuperM::getLiquidation($file), 2) . ' | '; if ($offer) { $data .= '' . Carbon::parse($offer->created_at)->format('Y-m-d') . ' | '; } else { $data .= '- | '; } $data .= '' . $file->created_at->format('Y-m-d') . ' | '; $data .= '