update form apartemen dan foto

This commit is contained in:
majid
2024-11-14 00:08:45 +07:00
committed by putrakuningan
parent d3d918b838
commit 3f8475f418
7 changed files with 221 additions and 140 deletions

View File

@@ -94,7 +94,6 @@ class SurveyorController extends Controller
$saranaPelengkap = SaranaPelengkap::all();
$arahMataAngin = ArahMataAngin::all();
$jenisJaminanIds = $permohonan->debiture->documents;
@@ -104,7 +103,15 @@ class SurveyorController extends Controller
->where('permohonan_id', $id)
->get();
$inpeksi = Inspeksi::where('permohonan_id', $id)->first();
$jenisJaminanIds = $permohonan->debiture->documents->pluck('jenisJaminan.id')->toArray(); // Convert to array
$jaminanId = $jenisJaminanIds[0];
$inpeksi = Inspeksi::where('permohonan_id', $id)
->whereIn('jenis_jaminan_id', $jenisJaminanIds)
->first();
if ($inpeksi) {
$forminspeksi = json_decode($inpeksi->data_form, true);
$formFoto = json_decode($inpeksi->foto_form, true);
@@ -139,6 +146,7 @@ class SurveyorController extends Controller
'forminspeksi',
'formDenah',
'formFoto',
'jaminanId'
));
}
/**
@@ -158,15 +166,15 @@ class SurveyorController extends Controller
$action = $request->input('type');
$rules = $this->getActionSpecificRules($data, $action, $request);
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first();
if ($inspeksi) {
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first();
if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) {
$inspeksi->update(['data_form' => json_encode($rules)]);
} else {
Inspeksi::create([
'permohonan_id' => $request->permohonan_id,
'data_form' => json_encode($rules),
'name' => $request->type,
'jenis_jaminan_id' => $request->input('jenis_jaminan_id'),
]);
}
@@ -236,8 +244,8 @@ class SurveyorController extends Controller
];
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first();
if ($request->input('permohonan_id') == $inspeksi->permohonan_id) {
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first();
if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) {
$inspeksi->update([
'denah_form' => json_encode($formatJsonDenah)
]);
@@ -262,7 +270,6 @@ class SurveyorController extends Controller
$validatedData = $request->validate([
'permohonan_id' => 'required',
'jenis_jaminan_id' => 'required',
'analisa_type' => 'required|in:tanah_bangunan,unit',
'pendamping' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'foto_objek.*' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
'name_objek.*' => 'required|string|max:255',
@@ -366,8 +373,8 @@ class SurveyorController extends Controller
'pendamping' => $pendamping
];
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->first();
if ($request->input('permohonan_id') == $inspeksi->permohonan_id) {
$inspeksi = Inspeksi::where('permohonan_id', $request->input('permohonan_id'))->where('jenis_jaminan_id', $request->input('jenis_jaminan_id'))->first();
if ($request->input('permohonan_id') == $inspeksi->permohonan_id && $request->input('jenis_jaminan_id') == $inspeksi->jenis_jaminan_id) {
$inspeksi->update([
'foto_form' => json_encode($formatFotojson)
]);
@@ -384,7 +391,7 @@ class SurveyorController extends Controller
}
}
public function submitSurveyor($id)
public function submitSurveyor($id,$jaminanId)
{
try {
$cekButton = $this->checkButtonStatus($id)->getData();
@@ -407,6 +414,7 @@ class SurveyorController extends Controller
public function checkButtonStatus($id)
{
try {
$inpeksi = Inspeksi::where('permohonan_id', $id)->first();
if ($inpeksi) {
@@ -428,64 +436,64 @@ class SurveyorController extends Controller
return response()->json(['buttonDisable' => true]);
}
} catch (\Exception $e) {
return response()->json(['error' => 'Something went wrong', 'message' => $e->getMessage()], 500);
return response()->json(['buttonDisable' => true]);
}
}
public function storeJadwal(Request $request)
{
try {
{
try {
$validate = $request->validate([
'id' => 'required',
'waktu_penilaian' => 'required',
'deskripsi_penilaian' => 'required'
]);
$validate = $request->validate([
'id' => 'required',
'waktu_penilaian' => 'required',
'deskripsi_penilaian' => 'required'
]);
// return response()->json([
// 'daa'=>$validate
// ]);
$id = $request->input('id');
$penilaian = Penilaian::findOrFail($id);
// return response()->json([
// 'daa'=>$validate
// ]);
$id = $request->input('id');
$penilaian = Penilaian::findOrFail($id);
$penilaian->update([
'waktu_penilaian' => $validate['waktu_penilaian'],
'deskripsi_penilaian' => $validate['deskripsi_penilaian'],
]);
$penilaian->update([
'waktu_penilaian' => $validate['waktu_penilaian'],
'deskripsi_penilaian' => $validate['deskripsi_penilaian'],
return redirect()
->route('surveyor.index')
->with('success', 'Jadwal berhasil dibuat.');
} catch (\Exception $e) {
return redirect()
->route('surveyor.index')
->with('error', 'Gagal membuat jadwal: ' . $e->getMessage());
]);
return redirect()
->route('surveyor.index')
->with('success', 'Jadwal berhasil dibuat.');
} catch (\Exception $e) {
return redirect()
->route('surveyor.index')
->with('error', 'Gagal membuat jadwal: ' . $e->getMessage());
}
}
}
public function storeAproved($id)
{
try {
public function storeAproved($id)
{
try {
$penilaian = Penilaian::findOrFail($id);
$penilaian = Penilaian::findOrFail($id);
$penilaian->update([
'authorized_status' => 1,
]);
$penilaian->update([
'authorized_status' => 1,
]);
return redirect()
->route('permohonan.index')
->with('success', 'Jadwal berhasil di aprove.');
} catch (\Exception $e) {
return redirect()
->route('permohonan.index')
->with('error', 'Gagal membuat jadwal: ' . $e->getMessage());
return redirect()
->route('permohonan.index')
->with('success', 'Jadwal berhasil di aprove.');
} catch (\Exception $e) {
return redirect()
->route('permohonan.index')
->with('error', 'Gagal membuat jadwal: ' . $e->getMessage());
}
}
}
/**
* Form inspeksi.
*/
@@ -534,7 +542,7 @@ public function storeAproved($id)
$inpeksi = Inspeksi::where('permohonan_id', $id)->first();
$inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first();
$forminspeksi = null;
if ($inpeksi) {
$forminspeksi = json_decode($inpeksi->data_form, true);
@@ -577,8 +585,7 @@ public function storeAproved($id)
$denah = null;
$inpeksi = Inspeksi::where('permohonan_id', $id)->first();
$inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first();
$formDenah = null;
if ($inpeksi) {
$formDenah = json_decode($inpeksi->denah_form, true);
@@ -601,7 +608,8 @@ public function storeAproved($id)
$inpeksi = Inspeksi::where('permohonan_id', $id)->first();
$inpeksi = Inspeksi::where('permohonan_id', $id)->where('jenis_jaminan_id', $jaminanId)->first();
$formFoto = null;
if ($inpeksi) {
$formFoto = json_decode($inpeksi->foto_form, true);
@@ -1074,7 +1082,7 @@ public function storeAproved($id)
}
private function getTanahData($data,$request): array
private function getTanahData($data, $request): array
{
return [
'luas_tanah' => $data['luas_tanah'] ?? null,

View File

@@ -14,7 +14,17 @@ class Inspeksi extends Model
/**
* The attributes that are mass assignable.
*/
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by'];
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by','jenis_jaminan_id'];
public function permohonan()
{
return $this->belongsTo(Permohonan::class, 'permohonan_id');
}
public function jenis_jaminan()
{
return $this->belongsTo(JenisJaminan::class, 'jenis_jaminan_id');
}
// protected static function newFactory(): InspeksiFactory
// {

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('inspeksi', function (Blueprint $table) {
$table->unsignedBigInteger('jenis_jaminan_id')->nullable()->after('permohonan_id');
$table->foreign('jenis_jaminan_id')->references('id')->on('jenis_jaminan')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('inspeksi', function (Blueprint $table) {
$table->dropColumn('jenis_jaminan_id');
});
}
};

View File

@@ -17,12 +17,12 @@
<div class="flex flex-wrap items-baseline w-full">
<div class="grid grid-cols-2 md:grid-cols-3 gap-4 mt-2">
<label class="form-label flex items-center gap-3 text-nowrap">
<input type="radio" class="radio" name="luas" value="sesuai"
<input type="radio" class="radio" name="luas_unit" value="sesuai"
{{ old('luas', isset($analisa) && optional($analisa)->luas) == 'sesuai' ? 'checked' : '' }}>
<span class="ml-2">Sesuai</span>
</label>
<label class="form-label flex items-center gap-2.5 text-nowrap">
<input type="radio" class="radio" name="luas" value="tidak sesuai"
<input type="radio" class="radio" name="luas_unit" value="tidak sesuai"
{{ old('luas', isset($analisa) && optional($analisa)->luas) == 'tidak sesuai' ? 'checked' : '' }}>
<span class="ml-2">Tidak Sesuai</span>
</label>

View File

@@ -89,24 +89,6 @@
<input type="hidden" name="jenis_jaminan_id" value="{{ request('jenis_jaminan') }}">
@foreach ($permohonan->debiture->documents as $dokumen)
@if ($dokumen->jenisJaminan)
@php
$formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true);
@endphp
<input type="hidden" name="action"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
<input type="hidden" name="type"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
@if (is_array($formKategori))
@foreach ($formKategori as $kategori)
@include('lpj::surveyor.components.' . str_replace('-', '_', $kategori), [
'dokumen' => $dokumen,
])
@endforeach
@endif
@endif
@endforeach
<div class="card bg-white rounded-lg shadow-md">
@@ -226,61 +208,110 @@
<div class=" text-white py-4 px-6 flex items-center justify-between">
<h1 class="text-md font-medium text-gray-900">Objek Jaminan</h1>
</div>
@php
$objekViews = [];
if ($analisaType === 'tanah_bangunan') {
$objekViews = [
['label' => 'Tampak Samping Kiri', 'index' => 0],
['label' => 'Tampak Samping Kanan', 'index' => 1],
['label' => 'Nomor Rumah/Unit', 'index' => 2],
];
} elseif ($analisaType === 'unit') {
$objekViews = [
['label' => 'Tampak Loby', 'index' => 0],
['label' => 'Tampak Lift', 'index' => 1],
['label' => 'Tampak Samping Kiri Unit', 'index' => 2],
['label' => 'Tampak Samping Kanan Unit', 'index' => 3],
['label' => 'Tampak Depan Unit', 'index' => 4],
['label' => 'Nomor Unit', 'index' => 5],
];
}
@endphp
@if (count($objekViews) > 0)
@foreach ($objekViews as $view)
<div class="flex flex-wrap gap-4 {{ !$loop->first ? 'mt-2' : '' }}">
<div class="flex w-full gap-4">
<label class="form-label max-w-56"><span class="form-label">{{ $view['label'] }}</span>
</label>
<input type="hidden" class="form-control" name="name_objek[]"
value="{{ $view['label'] }}" />
<div class="w-full grid gap-5">
<img id="foto_object_jaminan_preview_{{ $view['index'] }}"
src="{{ isset($formFoto['object_jaminan'][$view['index']]['foto_object']) ? asset('storage/' . $formFoto['object_jaminan'][$view['index']]['foto_object']) : '' }}"
alt="{{ $view['label'] }}" class="mb-2 w-48 h-auto"
onchange="previewImage(this, 'foto_object_jaminan_preview_{{ $view['index'] }}')" style="{{ isset($formFoto['foto_object']) ? '' : 'display: none;' }} width: 30rem;">
@foreach ($permohonan->debiture->documents as $dokumen)
@if ($dokumen->jenisJaminan)
@php
$formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true);
@endphp
@if (isset($formKategori) && $formKategori)
<input type="hidden" name="action"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
<input type="hidden" name="type"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
@if (is_array($formKategori))
@foreach ($formKategori as $kategori)
@if ($kategori === 'tanah' || $kategori === 'bangunan')
@php
$objekViews = [
['label' => 'Tampak Samping Kiri', 'index' => 0],
['label' => 'Tampak Samping Kanan', 'index' => 1],
['label' => 'Nomor Rumah/Unit', 'index' => 2],
];
@endphp
@elseif ($kategori === 'apartemen-kantor')
@php
$objekViews = [
['label' => 'Tampak Loby', 'index' => 0],
['label' => 'Tampak Lift', 'index' => 1],
['label' => 'Tampak Samping Kiri Unit', 'index' => 2],
['label' => 'Tampak Samping Kanan Unit', 'index' => 3],
['label' => 'Tampak Depan Unit', 'index' => 4],
['label' => 'Nomor Unit', 'index' => 5],
];
@endphp
@elseif ($kategori === 'kendaraan')
@php
$objekViews = [
['label' => 'Tampak Depan Objek', 'index' => 0],
['label' => 'Tampak Kanan Objek', 'index' => 1],
['label' => 'Tampak Samping Kiri Objek', 'index' => 2],
['label' => 'Tampak Belakang Objek', 'index' => 3],
['label' => 'Tampak Bagian Dalam', 'index' => 4],
['label' => 'Nomor Panel Instrument', 'index' => 5],
['label' => 'Tampak Odometer', 'index' => 6],
['label' => 'Tampak Aksesoris Tambahan', 'index' => 7],
['label' => 'Tampak Nomor Rangka', 'index' => 8],
['label' => 'Tampak Nomor Mesin', 'index' => 9],
['label' => 'Tampak Penilai dan Pendamping di lapangan', 'index' => 10],
];
@endphp
@elseif ($kategori === 'kapal')
@php
$objekViews = [
['label' => 'Tampak Depan', 'index' => 0],
['label' => 'Tampak Kanan', 'index' => 1],
['label' => 'Tampak Samping Kiri', 'index' => 2],
['label' => 'Tampak Belakang', 'index' => 3],
['label' => 'Tampak Bagian Dalam', 'index' => 4],
['label' => 'Nomor Panel Instrument', 'index' => 5],
['label' => 'Tampak Hours Meters', 'index' => 6],
['label' => 'Tampak Aksesoris Tambahan', 'index' => 7],
['label' => 'Tampak Nomor Rangka', 'index' => 8],
['label' => 'Tampak Nomor Mesin', 'index' => 9],
['label' => 'Tampak Penilai dan Pendamping di lapangan', 'index' => 10],
];
@endphp
@endif
<div class="input-group w-full flex gap-2">
<input type="file" name="foto_objek[]"
class="file-input file-input-bordered w-full" accept="image/*" capture="camera">
<button type="button" id="btnCamera" class="btn btn-light"
data-modal-toggle="#cameraModal">
<i class="ki-outline ki-abstract-33"></i> Camera
</button>
</div>
<textarea name="deskripsi_objek[]" class="textarea" rows="3" placeholder="Deskripsi">{{ isset($formFoto) && isset($formFoto['object_jaminan'][$view['index']]) ? str_replace($view['label'] . ': ', '', $formFoto['object_jaminan'][$view['index']]['deskripsi_objek']) : '' }}</textarea>
</div>
</div>
<span class="alert text-danger text-sm"></span>
</div>
@endforeach
@else
<div class="p-4">
<p class="text-gray-500">Tipe analisa tidak valid atau belum dipilih.</p>
</div>
@if (count($objekViews) > 0)
@foreach ($objekViews as $view)
<div class="flex flex-wrap gap-4 {{ !$loop->first ? 'mt-2' : '' }}">
<div class="flex w-full gap-4">
<label class="form-label max-w-56"><span class="form-label">{{ $view['label'] }}</span>
</label>
<input type="hidden" class="form-control" name="name_objek[]"
value="{{ $view['label'] }}" />
<div class="w-full grid gap-5">
<img id="foto_object_jaminan_preview_{{ $view['index'] }}"
src="{{ isset($formFoto['object_jaminan'][$view['index']]['foto_object']) ? asset('storage/' . $formFoto['object_jaminan'][$view['index']]['foto_object']) : '' }}"
alt="{{ $view['label'] }}" class="mb-2 w-48 h-auto"
onchange="previewImage(this, 'foto_object_jaminan_preview_{{ $view['index'] }}')"
style="{{ isset($formFoto['foto_object']) ? '' : 'display: none;' }} width: 30rem;">
<div class="input-group w-full flex gap-2">
<input type="file" name="foto_objek[]"
class="file-input file-input-bordered w-full" accept="image/*" capture="camera">
<button type="button" id="btnCamera" class="btn btn-light"
data-modal-toggle="#cameraModal">
<i class="ki-outline ki-abstract-33"></i> Camera
</button>
</div>
<textarea name="deskripsi_objek[]" class="textarea" rows="3" placeholder="Deskripsi">{{ isset($formFoto) && isset($formFoto['object_jaminan'][$view['index']]) ? str_replace($view['label'] . ': ', '', $formFoto['object_jaminan'][$view['index']]['deskripsi_objek']) : '' }}</textarea>
</div>
</div>
<span class="alert text-danger text-sm"></span>
</div>
@endforeach
@endif
@endforeach
@endif
@endif
@endif
@endforeach
<div class="flex flex-wrap gap-4 w-full">
@@ -656,10 +687,10 @@
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
success: function(response) {
// if (response.success) {
// window.location.href =
// '{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto';
// }
if (response.success) {
window.location.href =
'{{ route('surveyor.show', ['id' => $permohonan->id]) }}?form=foto';
}
console.log(response);
},
error: function(xhr, status, error) {

View File

@@ -30,27 +30,30 @@
@csrf
<input type="hidden" name="permohonan_id" value="{{ $permohonan->id }}">
<input type="hidden" name="jenis_jaminan_id" value="{{ request('jenis_jaminan') }}">
<input type="text
" name="jenis_jaminan_id" value="{{ request('jenis_jaminan') }}">
@foreach ($permohonan->debiture->documents as $dokumen)
@if ($dokumen->jenisJaminan)
@php
$formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true);
@endphp
@if ($dokumen->jenisJaminan)
@php
$formKategori = json_decode($dokumen->jenisJaminan->form_kategori, true);
@endphp
@if (isset($formKategori) && $formKategori)
<input type="hidden" name="action"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
<input type="hidden" name="type"
value="{{ is_array($formKategori) ? implode(',', $formKategori) : $formKategori }}">
@if (is_array($formKategori))
@foreach ($formKategori as $kategori)
@include('lpj::surveyor.components.' . str_replace('-', '_', $kategori), [
@include('lpj::surveyor.components.' . str_replace('-', '-', $kategori), [
'dokumen' => $dokumen,
])
@endforeach
@endif
@endif
@endforeach
@endif
@endforeach
<div class="flex justify-end gap-2" style="margin-right: 20px; margin-top: 20px">
<button type="button" class="btn btn-success" id="saveButton" onclick="submitData()">

View File

@@ -460,7 +460,7 @@ Route::middleware(['auth'])->group(function () {
Route::get('/', [SurveyorController::class, 'index'])->name('index');
Route::get('{id}/show', [SurveyorController::class, 'show'])->name('show');
Route::post('store', [SurveyorController::class, 'store'])->name('store');
Route::post('storeDenah/{id}', [SurveyorController::class, 'storeDenah'])->name('storeDenah');
Route::post('storeDenah', [SurveyorController::class, 'storeDenah'])->name('storeDenah');
Route::put('storeJadwal', [SurveyorController::class, 'storeJadwal'])->name('storeJadwal');
Route::get('storeAproved/{id}', [SurveyorController::class, 'storeAproved'])->name('storeAproved');
Route::post('storeFoto', [SurveyorController::class, 'storeFoto'])->name('storeFoto');