feat(laporan-admin-kredit): tambahkan fitur laporan admin kredit
- Menambahkan model LaporanAdminKredit. - Menambahkan controller LaporanAdminKreditController dengan metode untuk menampilkan dan mengelola data. - Menambahkan rute untuk laporan admin kredit. - Menambahkan breadcrumb untuk navigasi laporan admin kredit. - Menambahkan migrasi untuk tabel laporan_admin_kredit. - Menambahkan relasi di model Debiture untuk laporan admin kredit.
This commit is contained in:
87
app/Http/Controllers/LaporanAdminKreditController.php
Normal file
87
app/Http/Controllers/LaporanAdminKreditController.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Modules\Lpj\Models\LaporanAdminKredit;
|
||||
|
||||
class LaporanAdminKreditController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$laporans = LaporanAdminKredit::with('debiture')->paginate(10);
|
||||
return view('lpj::laporan_admin_kredit.index', compact('laporans'));
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('laporan-admin-kredit.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view laporan admin kredit.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = LaporanAdminKredit::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('kode_register_t24', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('jenis_agunan', 'LIKE', '%' . $search . '%')
|
||||
->orWhere('nama_pemilik', 'LIKE', '%' . $search . '%')
|
||||
->orWhereHas('debiture', function ($query) use ($search) {
|
||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with(['debiture.branch'])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = $request->get('page', 1);
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -64,4 +64,9 @@
|
||||
return $this->hasOne(Permohonan::class, 'debiture_id', 'id' );
|
||||
}
|
||||
|
||||
public function laporanAdminKredit(): HasMany
|
||||
{
|
||||
return $this->hasMany(LaporanAdminKredit::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
37
app/Models/LaporanAdminKredit.php
Normal file
37
app/Models/LaporanAdminKredit.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class LaporanAdminKredit extends Base
|
||||
{
|
||||
protected $table = 'laporan_admin_kredit';
|
||||
|
||||
protected $fillable = [
|
||||
'debiture_id',
|
||||
'kode_register_t24',
|
||||
'jenis_agunan',
|
||||
'bukti_kepemilikan',
|
||||
'alamat_agunan',
|
||||
'nama_pemilik',
|
||||
'tanggal_kunjungan',
|
||||
'nilai_pasar_wajar',
|
||||
'nilai_likuidasi',
|
||||
'nama_penilai'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'tanggal_kunjungan' => 'date',
|
||||
'nilai_pasar_wajar' => 'decimal:2',
|
||||
'nilai_likuidasi' => 'decimal:2',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the debiture that owns the laporan admin kredit.
|
||||
*/
|
||||
public function debiture(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Debiture::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user