541 lines
18 KiB
PHP
541 lines
18 KiB
PHP
<?php
|
|
|
|
namespace Modules\Lpj\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use Modules\Lpj\Models\Permohonan;
|
|
use Modules\Lpj\Models\Branch;
|
|
use Modules\Lpj\Models\Surveyor;
|
|
use Modules\Lpj\Models\BentukTanah;
|
|
use Modules\Lpj\Models\KonturTanah;
|
|
use Modules\Location\Models\Province;
|
|
use Modules\Lpj\Models\PosisiKavling;
|
|
use Modules\Lpj\Models\KondisiFisikTanah;
|
|
use Modules\Lpj\Models\KetinggianTanah;
|
|
use Modules\Lpj\Models\SifatBangunan;
|
|
use Modules\Lpj\Models\JenisBangunan;
|
|
use Modules\Lpj\Models\KondisiBangunan;
|
|
use Modules\Lpj\Models\SpekBangunan;
|
|
use Modules\Lpj\Models\SpekKategoritBangunan;
|
|
use Modules\Lpj\Models\SaranaPelengkap;
|
|
use Modules\Lpj\Models\ArahMataAngin;
|
|
use Modules\Lpj\Http\Requests\SurveyorRequest;
|
|
|
|
class SurveyorController extends Controller
|
|
{
|
|
public $user;
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('lpj::surveyor.index');
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
$permohonan = Permohonan::with(
|
|
[
|
|
'user',
|
|
'debiture.province',
|
|
'debiture.city',
|
|
'debiture.district',
|
|
'debiture.village',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'penilaian',
|
|
'documents',
|
|
],
|
|
)->findOrFail($id);
|
|
|
|
$surveyor = $id;
|
|
$branches = Branch::all();
|
|
$provinces = Province::all();
|
|
$bentukTanah = BentukTanah::all();
|
|
$konturTanah = KonturTanah::all();
|
|
$posisiKavling = PosisiKavling::all();
|
|
$ketinggianTanah = KetinggianTanah::all();
|
|
$kondisiFisikTanah = KondisiFisikTanah::all();
|
|
$jenisBangunan = JenisBangunan::all();
|
|
$kondisiBangunan = KondisiBangunan::all();
|
|
$sifatBangunan = SifatBangunan::all();
|
|
$spekKategoriBagunan = SpekKategoritBangunan::all();
|
|
$spekBangunan = SpekBangunan::all();
|
|
$saranaPelengkap = SaranaPelengkap::all();
|
|
$arahMataAngin = ArahMataAngin::all();
|
|
|
|
|
|
return view('lpj::surveyor.detail', compact(
|
|
'permohonan',
|
|
'surveyor',
|
|
'branches',
|
|
'provinces',
|
|
'bentukTanah',
|
|
'konturTanah',
|
|
'posisiKavling',
|
|
'kondisiFisikTanah',
|
|
'ketinggianTanah',
|
|
'kondisiBangunan',
|
|
'jenisBangunan',
|
|
'sifatBangunan',
|
|
'spekKategoriBagunan',
|
|
'spekBangunan',
|
|
'saranaPelengkap',
|
|
'arahMataAngin',
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('lpj::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id): RedirectResponse
|
|
{
|
|
//
|
|
}
|
|
|
|
public function dataForDatatables(Request $request)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
|
// abort(403, 'Sorry! You are not allowed to view users.');
|
|
}
|
|
|
|
$query = Permohonan::query();
|
|
|
|
if ($request->has('search') && !empty($request->get('search'))) {
|
|
$search = $request->get('search');
|
|
$query->where(function ($q) use ($search) {
|
|
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
|
|
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
|
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
|
$q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%');
|
|
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
|
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
|
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
|
});
|
|
}
|
|
|
|
$query->whereRaw('LOWER(status) = ?', ['assign']);
|
|
|
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
|
$order = $request->get('sortOrder');
|
|
$column = $request->get('sortField');
|
|
$query->orderBy($column, $order);
|
|
}
|
|
|
|
$totalRecords = $query->count();
|
|
|
|
$size = $request->get('size', 10);
|
|
if ($size == 0) {
|
|
$size = 10;
|
|
}
|
|
|
|
if ($request->has('page') && $request->has('size')) {
|
|
$page = $request->get('page', 1);
|
|
$offset = ($page - 1) * $size;
|
|
|
|
$query->skip($offset)->take($size);
|
|
}
|
|
|
|
$filteredRecords = $query->count();
|
|
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian', 'jenisFasilitasKredit'])->get();
|
|
|
|
$pageCount = ceil($totalRecords / $size);
|
|
|
|
$currentPage = max(1, $request->get('page', 1));
|
|
return response()->json([
|
|
'draw' => $request->get('draw'),
|
|
'recordsTotal' => $totalRecords,
|
|
'recordsFiltered' => $filteredRecords,
|
|
'pageCount' => $pageCount,
|
|
'page' => $currentPage,
|
|
'totalCount' => $totalRecords,
|
|
'data' => $data,
|
|
]);
|
|
}
|
|
/**
|
|
* Form inspeksi.
|
|
*/
|
|
|
|
public function formInspeksi($id)
|
|
{
|
|
$permohonan = Permohonan::with(
|
|
[
|
|
'user',
|
|
'debiture.province',
|
|
'debiture.city',
|
|
'debiture.district',
|
|
'debiture.village',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'penilaian'
|
|
],
|
|
)->findOrFail($id);
|
|
$branches = Branch::all();
|
|
$provinces = Province::all();
|
|
|
|
return view('lpj::surveyor.detail', compact('permohonan', 'branches', 'provinces'));
|
|
}
|
|
|
|
/**
|
|
* Denah.
|
|
*/
|
|
|
|
public function denah($id)
|
|
{
|
|
$permohonan = Permohonan::with(
|
|
[
|
|
'user',
|
|
'debiture.province',
|
|
'debiture.city',
|
|
'debiture.district',
|
|
'debiture.village',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'penilaian'
|
|
],
|
|
)->findOrFail($id);
|
|
$surveyor = $id;
|
|
$branches = Branch::all();
|
|
$provinces = Province::all();
|
|
|
|
return view('lpj::surveyor.detail', compact('permohonan', 'surveyor', 'branches', 'provinces'));
|
|
}
|
|
|
|
/**
|
|
* Foto.
|
|
*/
|
|
|
|
public function foto($id)
|
|
{
|
|
$permohonan = Permohonan::with(
|
|
[
|
|
'user',
|
|
'debiture.province',
|
|
'debiture.city',
|
|
'debiture.district',
|
|
'debiture.village',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'penilaian'
|
|
],
|
|
)->findOrFail($id);
|
|
$surveyor = $id;
|
|
$branches = Branch::all();
|
|
$provinces = Province::all();
|
|
|
|
return view('lpj::surveyor.detail', compact('permohonan', 'surveyor', 'branches', 'provinces'));
|
|
}
|
|
|
|
/**
|
|
* Data pembanding.
|
|
*/
|
|
|
|
public function dataPembanding($id)
|
|
{
|
|
$permohonan = Permohonan::with(
|
|
[
|
|
'user',
|
|
'debiture.province',
|
|
'debiture.city',
|
|
'debiture.district',
|
|
'debiture.village',
|
|
'branch',
|
|
'tujuanPenilaian',
|
|
'penilaian'
|
|
],
|
|
)->findOrFail($id);
|
|
$surveyor = $id;
|
|
$branches = Branch::all();
|
|
$provinces = Province::all();
|
|
|
|
return view('lpj::surveyor.detail', compact('permohonan', 'surveyor', 'branches', 'provinces'));
|
|
}
|
|
|
|
|
|
public function data(Request $request)
|
|
{
|
|
|
|
$type = $request->route('type');
|
|
|
|
$headers = [
|
|
'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah'],
|
|
'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah'],
|
|
'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling'],
|
|
'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah'],
|
|
'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah'],
|
|
'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan'],
|
|
'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan'],
|
|
'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan'],
|
|
'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap'],
|
|
];
|
|
|
|
$header = $headers[$type] ?? '';
|
|
|
|
return view('lpj::surveyor.data.index', compact('header'));
|
|
}
|
|
|
|
|
|
public function createData($type)
|
|
{
|
|
|
|
$headers = [
|
|
'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah'],
|
|
'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah'],
|
|
'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling'],
|
|
'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah'],
|
|
'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah'],
|
|
'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan'],
|
|
'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan'],
|
|
'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan'],
|
|
'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap'],
|
|
];
|
|
|
|
|
|
$header = $headers[$type] ?? '';
|
|
return view('lpj::surveyor.data.form', compact('header'));
|
|
}
|
|
|
|
|
|
public function storeData(SurveyorRequest $request, $type)
|
|
{
|
|
|
|
$validate = $request->validated();
|
|
if ($validate) {
|
|
|
|
$type = $request->route('type');
|
|
|
|
$modelClasses = [
|
|
'bentuk-tanah' => BentukTanah::class,
|
|
'kontur-tanah' => KonturTanah::class,
|
|
'posisi-kavling' => PosisiKavling::class,
|
|
'bentuk-tanah' => BentukTanah::class,
|
|
'kontur-tanah' => KonturTanah::class,
|
|
'posisi-kavling' => PosisiKavling::class,
|
|
'ketinggian-tanah' => KetinggianTanah::class,
|
|
'kondisi-fisik-tanah' => KondisiFisikTanah::class,
|
|
'jenis-bangunan' => JenisBangunan::class,
|
|
'kondisi-bangunan' => KondisiBangunan::class,
|
|
'sifat-bangunan' => SifatBangunan::class,
|
|
'sarana-pelengkap' => SaranaPelengkap::class,
|
|
];
|
|
|
|
if (!array_key_exists($type, $modelClasses)) {
|
|
return redirect()
|
|
->route('basicdata.'. $type .'.index')
|
|
->with('error', 'Invalid type specified.');
|
|
}
|
|
|
|
$modelClass = $modelClasses[$type];
|
|
$data = $request->all();
|
|
$data['status'] = true;
|
|
$modelClass::create($data);
|
|
|
|
return redirect()
|
|
->route('basicdata.' . $type .'.index')
|
|
->with('success', 'created successfully');
|
|
}
|
|
}
|
|
|
|
|
|
public function editData($type, $id)
|
|
{
|
|
$dataMap = [
|
|
'bentuk-tanah' => ['Bentuk Tanah', 'bentuk-tanah', BentukTanah::class],
|
|
'kontur-tanah' => ['Kontur Tanah', 'kontur-tanah', KonturTanah::class],
|
|
'posisi-kavling' => ['Posisi Kavling', 'posisi-kavling', PosisiKavling::class],
|
|
'ketinggian-tanah' => ['Ketinggian Tanah', 'ketinggian-tanah', KetinggianTanah::class],
|
|
'kondisi-fisik-tanah' => ['Kondisi Fisik Tanah', 'kondisi-fisik-tanah', KondisiFisikTanah::class],
|
|
'jenis-bangunan' => ['Jenis Bangunan', 'jenis-bangunan', JenisBangunan::class],
|
|
'kondisi-bangunan' => ['Kondisi Bangunan', 'kondisi-bangunan', KondisiBangunan::class],
|
|
'sifat-bangunan' => ['Sifat Bangunan', 'sifat-bangunan', SifatBangunan::class],
|
|
'spek-bangunan' => ['Spek Bangunan', 'spek-bangunan', SpekBangunan::class],
|
|
'spek-kategori-bangunan' => ['Spek Kategori Bangunan', 'spek-kategori-bangunan', SpekKategoritBangunan::class],
|
|
'sarana-pelengkap' => ['Sarana Pelengkap', 'sarana-pelengkap', SaranaPelengkap::class],
|
|
];
|
|
|
|
|
|
if (!array_key_exists($type, $dataMap)) {
|
|
return redirect()->back()->with('error', 'Invalid type specified.');
|
|
}
|
|
|
|
[$headers, $routeName, $modelClass] = $dataMap[$type];
|
|
|
|
$header = $dataMap[$type] ?? '';
|
|
$model = $modelClass::findOrFail($id);
|
|
|
|
return view('lpj::surveyor.data.form', compact('header', 'model'));
|
|
}
|
|
|
|
|
|
public function updateData(SurveyorRequest $request, $type, $id)
|
|
{
|
|
$validate = $request->validated();
|
|
if ($validate) {
|
|
$modelClasses = [
|
|
'bentuk-tanah' => BentukTanah::class,
|
|
'kontur-tanah' => KonturTanah::class,
|
|
'posisi-kavling' => PosisiKavling::class,
|
|
'ketinggian-tanah' => KetinggianTanah::class,
|
|
'kondisi-fisik-tanah' => KondisiFisikTanah::class,
|
|
'jenis-bangunan' => JenisBangunan::class,
|
|
'kondisi-bangunan' => KondisiBangunan::class,
|
|
'sifat-bangunan' => SifatBangunan::class,
|
|
'sarana-pelengkap' => SaranaPelengkap::class,
|
|
|
|
];
|
|
|
|
// Check if the provided type exists in the modelClasses
|
|
if (!array_key_exists($type, $modelClasses)) {
|
|
return redirect()
|
|
->route('basicdata.' . $type . '.index')
|
|
->with('error', 'Invalid type specified.');
|
|
}
|
|
$modelClass = $modelClasses[$type];
|
|
$model = $modelClass::findOrFail($id);
|
|
$model->update($validate);
|
|
|
|
// Redirect back with a success message
|
|
return redirect()
|
|
->route('basicdata.' . $type . '.index')
|
|
->with('success', 'Updated successfully');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataForDatatablesData(Request $request, $type)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('jenis_aset.view')) {
|
|
//abort(403, 'Sorry! You are not allowed to view users.');
|
|
}
|
|
|
|
// Retrieve data from the database
|
|
|
|
$models = [
|
|
'Bentuk Tanah' => BentukTanah::class,
|
|
'Kontur Tanah' => KonturTanah::class,
|
|
'Posisi Kavling' => PosisiKavling::class,
|
|
'Ketinggian Tanah' => KetinggianTanah::class,
|
|
'Kondisi Fisik Tanah' => KondisiFisikTanah::class,
|
|
'Jenis Bangunan' => JenisBangunan::class,
|
|
'Kondisi Bangunan' => KondisiBangunan::class,
|
|
'Sifat Bangunan' => SifatBangunan::class,
|
|
// 'Spek Kategori Bangunan' => SpekKategoritBangunan::class,
|
|
// 'Spek Bangunan' => SpekBangunan::class,
|
|
'Sarana Pelengkap' => SaranaPelengkap::class,
|
|
];
|
|
|
|
|
|
if (array_key_exists($type, $models)) {
|
|
$query = $models[$type]::query();
|
|
} else {
|
|
throw new InvalidArgumentException("Invalid type: $type");
|
|
}
|
|
|
|
|
|
// 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('code', 'LIKE', "%$search%");
|
|
$q->orWhere('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->get();
|
|
|
|
// Calculate the page count
|
|
$pageCount = ceil($totalRecords / $request->get('size'));
|
|
|
|
// Calculate the current page number
|
|
$currentPage = 0 + 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,
|
|
]);
|
|
}
|
|
|
|
public function destroy($id, $type)
|
|
{
|
|
try {
|
|
|
|
$modelClasses = [
|
|
'bentuk-tanah' => BentukTanah::class,
|
|
'kontur-tanah' => KonturTanah::class,
|
|
'posisi-kavling' => PosisiKavling::class,
|
|
'ketinggian-tanah' => KetinggianTanah::class,
|
|
'kondisi-fisik-tanah' => KondisiFisikTanah::class,
|
|
'jenis-bangunan' => JenisBangunan::class,
|
|
'kondisi-bangunan' => KondisiBangunan::class,
|
|
'sifat-bangunan' => SifatBangunan::class,
|
|
'sarana-pelengkap' => SaranaPelengkap::class,
|
|
];
|
|
|
|
|
|
if (!array_key_exists($type, $modelClasses)) {
|
|
return response()->json(['success' => false, 'message' => 'Invalid type specified.'], 400);
|
|
}
|
|
|
|
$modelClass = $modelClasses[$type];
|
|
$model = $modelClass::findOrFail($id);
|
|
|
|
$model->delete();
|
|
return response()->json(['success' => true, 'message' => 'deleted successfully']);
|
|
} catch (ModelNotFoundException $e) {
|
|
return response()->json(['success' => false, 'message' => 'not found.'], 404);
|
|
} catch (Exception $e) {
|
|
return response()->json(['success' => false, 'message' => 'Failed to delete.'], 500);
|
|
}
|
|
}
|
|
|
|
|
|
}
|