@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 = " "; $i = 1; foreach ($files as $file) { $offer = $file->offer; $agent = $file->agents()->first(); $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; if (isset($file->more->account_info->email)) { $data .= ''; } else { $data .= ''; } $data .= ''; $data .= ''; if ($agent) { $data .= ''; } else { if ($file->user->referred_by) { $ref = $file->user->referred_by; $data .= ''; } else { $data .= ''; } } $data .= ''; if ($offer) { $data .= ''; $data .= ''; $data .= ''; } else { $data .= ''; $data .= ''; $data .= ''; } $data .= ''; $data .= ''; if ($file->type == 'public') { $data .= ''; } else { $data .= ''; } $data .= ''; $firstRepay = SuperM::getFirstRepayment($file); if ($firstRepay) { $data .= ''; } else { $data .= ''; } $lastRepay = SuperM::getLastRepayment($file); if ($lastRepay) { $data .= ''; } else { $data .= ''; } $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; $data .= ''; if ($offer) { $data .= ''; } else { $data .= ''; } $data .= ''; $data .= ''; } $data .= '
USER DETAILS LOAN DETAILS
SN UNIQUE ID FIRST NAME LAST NAME OTHER NAME PHONE NUMBER E-MAIL 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++ . '' . $file->unique_id . '' . ucwords($file->more->account_info->first_name) . '' . ucwords($file->more->account_info->last_name) . '' . ucwords($file->more->account_info->other_name) . '' . $file->more->account_info->phone_number . '' . strtolower($file->more->account_info->email) . '-' . $file->more->account_info->staff_id . '' . $file->created_at->format('l F d, Y h:i A') . '' . strtoupper($agent->first_name . ' ' . $agent->last_name) . '' . strtoupper($ref->first_name . ' ' . $ref->last_name) . '-' . $file->status->status . '' . $offer->more->tenor . '' . number_format($offer->more->amount, 2) . '' . number_format($offer->more->interest, 1) . '%---' . strtoupper($file->type) . '' . strtoupper($file->request_type) . '' . strtoupper($file->more->loan_type) . '-' . number_format(SuperM::getMonthlyRepayment($file), 2) . '' . $firstRepay->format('Y-m-d') . '-' . $lastRepay->format('Y-m-d') . '-' . $file->repayments()->count() . '' . number_format($file->repayments()->sum('amount'), 2) . '' . SuperM::getFailedDeductions($file) . '' . SuperM::getUnderDeductions($file) . '' . SuperM::getOverDeductions($file) . '' . number_format(SuperM::getTopUpBalance($file), 2) . '' . SuperM::getTopUpStatus($file) . '' . number_format(SuperM::getLiquidation($file), 2) . '' . Carbon::parse($offer->created_at)->format('Y-m-d') . '-' . $file->created_at->format('Y-m-d') . '
'; @endphp {!! $data !!}