99 lines
3.4 KiB
PHP
99 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\User\Http\Controllers;
|
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller;
|
|
use Illuminate\Support\Collection;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Str;
|
|
|
|
use DataTables;
|
|
use GuzzleHttp\Client;
|
|
use Carbon\Carbon;
|
|
|
|
use App\Models\Alternatif;
|
|
use App\Models\PengajuanNasabah;
|
|
use App\Models\Nilai;
|
|
|
|
class PengajuanController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
if ($request->ajax()) {
|
|
$data = PengajuanNasabah::select('*');
|
|
// Convert the Eloquent Collection to a regular PHP array
|
|
$data->each(function ($item, $key) {
|
|
$item->rowIndex = $key + 1;
|
|
});
|
|
|
|
return Datatables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('nasabah', function($row){
|
|
return $row->nasabah->nama_alternatif;
|
|
})
|
|
->addColumn('uplink', function($row){
|
|
return 'aa';
|
|
})
|
|
->addColumn('status_pengajuan', function($row){
|
|
if ($row->status == 1) {
|
|
return '<span class="mb-1 badge font-medium badge-success py-2 px-3 fs-7">Diterima</span>';
|
|
} elseif($row->status == 0) {
|
|
return '<span class="mb-1 badge font-medium badge-primary py-2 px-3 fs-7">Menunggu Respon</span>';
|
|
} else {
|
|
return '<span class="mb-1 badge font-medium badge-danger py-2 px-3 fs-7">Tidak diterima</span>';
|
|
}
|
|
})
|
|
->rawColumns(['nasabah', 'uplink', 'status_pengajuan'])
|
|
->make(true);
|
|
}
|
|
|
|
$data = [
|
|
'subtitle' => 'Pengajuan Nasabah'
|
|
];
|
|
|
|
return view('admin.app.content.pengajuan.index', compact('data'));
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function add(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'nasabah_kode' => 'required',
|
|
'hasil_preferensi' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
return redirect()->route('pengajuan')->withInput()->with('error', 'Unexpected error, please try again. code: ' . $validator->errors()->first());
|
|
}
|
|
|
|
$input = $request->all();
|
|
|
|
$post = new PengajuanNasabah([
|
|
'id_nasabah' => $input['nasabah_kode'], // Membersihkan input judul menggunakan Purifier
|
|
'skor' => $input['hasil_preferensi'], // Membersihkan input deskripsi menggunakan Purifier
|
|
'uplink' => user()->id,
|
|
'status' => 0,
|
|
]);
|
|
|
|
$check = PengajuanNasabah::where('id_nasabah', $input['nasabah_kode'])->where('skor', $input['hasil_preferensi'])->count();
|
|
if ($check == 0) {
|
|
if ($post->save()) {
|
|
return redirect()->route('nasabah')->with('success', 'You have successfully added data');
|
|
} else {
|
|
return redirect()->route('nasabah')->with('error', 'An error occurred in the query');
|
|
}
|
|
} else {
|
|
return redirect()->route('nasabah')->with('error', 'Title already exists');
|
|
}
|
|
}
|
|
}
|