From ad4d8cf7407bfeff2d77349a26d2113096603d3d Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 11 Sep 2024 10:50:46 +0700 Subject: [PATCH 1/3] update detail dokumen jaminan, --- app/Http/Controllers/DebitureController.php | 6 --- .../Controllers/DokumenJaminanController.php | 7 ++- app/Models/DokumenJaminan.php | 4 ++ .../debitur/components/jaminan.blade.php | 51 +++++++++++-------- routes/web.php | 2 +- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/DebitureController.php b/app/Http/Controllers/DebitureController.php index 7929578..e6762e3 100644 --- a/app/Http/Controllers/DebitureController.php +++ b/app/Http/Controllers/DebitureController.php @@ -174,10 +174,4 @@ { return Excel::download(new DebitureExport, 'debitur.xlsx'); } - - public function download($id) - { - $document = DokumenJaminan::find($id); - return response()->download(storage_path('app/public/' . $document->dokumen_jaminan)); - } } diff --git a/app/Http/Controllers/DokumenJaminanController.php b/app/Http/Controllers/DokumenJaminanController.php index 520c20e..9fe5d85 100644 --- a/app/Http/Controllers/DokumenJaminanController.php +++ b/app/Http/Controllers/DokumenJaminanController.php @@ -25,7 +25,7 @@ public function index($id) { $debitur = Debiture::find($id); - $documents = DokumenJaminan::with('pemilik')->where('debiture_id', $id)->get(); + $documents = DokumenJaminan::with('pemilik','detail')->where('debiture_id', $id)->get(); return view( 'lpj::debitur.edit', @@ -218,4 +218,9 @@ echo json_encode(['success' => false, 'message' => 'Failed to delete Dokumen Jaminan']); } } + + public function download($id){ + $document = DetailDokumenJaminan::find($id); + return response()->download(storage_path('app/public/' . $document->dokumen_jaminan)); + } } diff --git a/app/Models/DokumenJaminan.php b/app/Models/DokumenJaminan.php index 274f3c8..3454dc9 100644 --- a/app/Models/DokumenJaminan.php +++ b/app/Models/DokumenJaminan.php @@ -63,4 +63,8 @@ public function permohonan(){ return $this->belongsTo(Permohonan::class, 'permohonan_id', 'id'); } + + public function detail(){ + return $this->hasMany(DetailDokumenJaminan::class, 'dokumen_jaminan_id', 'id'); + } } diff --git a/resources/views/debitur/components/jaminan.blade.php b/resources/views/debitur/components/jaminan.blade.php index 4cfeb65..f06dea1 100644 --- a/resources/views/debitur/components/jaminan.blade.php +++ b/resources/views/debitur/components/jaminan.blade.php @@ -1,4 +1,4 @@ -
+
@foreach($documents as $document)
@@ -43,27 +43,7 @@
- @if($document->dokumen_jaminan) - -
-
- @endif
- - keterangan - -

- {{ $document->keterangan }} -

-
-
-
-
alamat @@ -71,6 +51,35 @@ {{ $document->address.', '.$document->village->name.', '.$document->city->name.', '.$document->province->name.', '.$document->postal_code }}

+
+
+
+ + dokumen jaminan + +
+
+
+ @foreach($document->detail as $detail) +
+ + {{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }} + + {{ basename($detail->dokumen_jaminan) }} +
+
+
+
+ + keterangan + +

+ {{ $detail->keterangan }} +

+
+
+
+ @endforeach
@endforeach diff --git a/routes/web.php b/routes/web.php index d1737ef..dad4309 100644 --- a/routes/web.php +++ b/routes/web.php @@ -173,7 +173,6 @@ Route::resource('permohonan', PermohonanController::class); Route::name('debitur.')->prefix('debitur')->group(function () { - Route::get('download/{id}', [DebitureController::class, 'download'])->name('download'); Route::get('restore/{id}', [DebitureController::class, 'restore'])->name('restore'); Route::get('datatables', [DebitureController::class, 'dataForDatatables']) ->name('datatables'); @@ -181,6 +180,7 @@ Route::name('jaminan.')->prefix('{id}/jaminan')->group(function () { + Route::get('download/{id}', [DebitureController::class, 'download'])->name('download'); Route::get('/', [DokumenJaminanController::class, 'index'])->name('index'); Route::get('create', [DokumenJaminanController::class, 'create'])->name('create'); Route::get('{jaminan}/edit', [DokumenJaminanController::class, 'edit'])->name('edit'); From bce89c2055d50f6d34c417f822533f4f1b45e7fb Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 11 Sep 2024 11:03:11 +0700 Subject: [PATCH 2/3] Fix Download Document --- resources/views/debitur/components/jaminan.blade.php | 2 +- routes/web.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/debitur/components/jaminan.blade.php b/resources/views/debitur/components/jaminan.blade.php index f06dea1..568d940 100644 --- a/resources/views/debitur/components/jaminan.blade.php +++ b/resources/views/debitur/components/jaminan.blade.php @@ -65,7 +65,7 @@ {{ $loop->index+1 }}. {{ $detail->jenisLegalitasJaminan->name }} - {{ basename($detail->dokumen_jaminan) }} + {{ basename($detail->dokumen_jaminan) }}
diff --git a/routes/web.php b/routes/web.php index dad4309..92a5cd3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -180,7 +180,7 @@ Route::name('jaminan.')->prefix('{id}/jaminan')->group(function () { - Route::get('download/{id}', [DebitureController::class, 'download'])->name('download'); + Route::get('download/{dokumen}', [DokumenJaminanController::class, 'download'])->name('download'); Route::get('/', [DokumenJaminanController::class, 'index'])->name('index'); Route::get('create', [DokumenJaminanController::class, 'create'])->name('create'); Route::get('{jaminan}/edit', [DokumenJaminanController::class, 'edit'])->name('edit'); From a6e90229d8c7b2d993d0e07c96fe15229e41378e Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 11 Sep 2024 12:00:50 +0700 Subject: [PATCH 3/3] Fix Update and Delete Dokumen Jaminan --- .../Controllers/DokumenJaminanController.php | 101 ++++++++++++++---- .../debitur/components/dokumen.blade.php | 55 +++++++++- 2 files changed, 131 insertions(+), 25 deletions(-) diff --git a/app/Http/Controllers/DokumenJaminanController.php b/app/Http/Controllers/DokumenJaminanController.php index 9fe5d85..dca91a5 100644 --- a/app/Http/Controllers/DokumenJaminanController.php +++ b/app/Http/Controllers/DokumenJaminanController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use Exception; use Illuminate\Support\Facades\DB; + use Illuminate\Support\Facades\Storage; use Modules\Location\Models\City; use Modules\Location\Models\District; use Modules\Location\Models\Province; @@ -25,7 +26,7 @@ public function index($id) { $debitur = Debiture::find($id); - $documents = DokumenJaminan::with('pemilik','detail')->where('debiture_id', $id)->get(); + $documents = DokumenJaminan::with('pemilik', 'detail')->where('debiture_id', $id)->get(); return view( 'lpj::debitur.edit', @@ -68,7 +69,6 @@ $document = DokumenJaminan::create($validate); try { - foreach ($request->dokumen_jaminan as $key => $value) { $file_name = $value->getClientOriginalName(); @@ -77,7 +77,7 @@ $file_name = $value->getClientOriginalName(); $value->storeAs( 'public/jaminan/' . $debitur->id . '/' . $document->id . '/', - $file_name + $file_name, ); $detail = [ @@ -92,17 +92,17 @@ DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with( 'error', - 'Gagal upload file dokumen jaminan '. $key. ': '. $e->getMessage(), + 'Gagal upload file dokumen jaminan ' . $key . ': ' . $e->getMessage(), ); } } } DB::commit(); - }catch (Exception $e) { + } catch (Exception $e) { DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with( 'error', - 'gg'.$e->getMessage(), + 'gg' . $e->getMessage(), ); } @@ -112,7 +112,7 @@ ); } catch (Exception $e) { DB::rollBack(); - return redirect()->route('debitur.jaminan.index', $id)->with('error','ggl'. $e->getMessage()); + return redirect()->route('debitur.jaminan.index', $id)->with('error', 'ggl' . $e->getMessage()); } } } @@ -138,6 +138,7 @@ $validate = $request->validated(); if ($validate) { try { + DB::beginTransaction(); $validate['debiture_id'] = $id; if ($validate['pemilik_jaminan_id'] == 0) { @@ -160,29 +161,77 @@ ], $pemilik_jaminan); } - if ($request->hasFile('dokumen_jaminan')) { - $file = $request->file('dokumen_jaminan'); - $file_name = $file->getClientOriginalName(); - $file->storeAs('public/jaminan/' . $debitur->id, $file_name); - $validate['dokumen_jaminan'] = 'jaminan/' . $debitur->id . '/' . $file_name; - } - $document = DokumenJaminan::find($jaminan); $document->update($validate); + if ($request->detail_dokumen_jaminan_id) { + foreach ($request->detail_dokumen_jaminan_id as $key => $value) { + if (isset($request->dokumen_jaminan[$key])) { + $file = $request->dokumen_jaminan[$key]; + if ($file) { + $file_name = $file->getClientOriginalName(); + } + + if (isset($file_name)) { + $file->storeAs( + 'public/jaminan/' . $debitur->id . '/' . $document->id . '/', + $file_name, + ); + + $detail = [ + 'dokumen_jaminan_id' => $document->id, + 'jenis_legalitas_jaminan_id' => $request->jenis_legalitas_jaminan_id[$key], + 'dokumen_jaminan' => 'jaminan/' . $debitur->id . '/' . $document->id . '/' . $file_name, + 'name' => $request->name[$key], + 'keterangan' => $request->keterangan[$key], + ]; + if (isset($request->detail_dokumen_jaminan_id[$key])) { + $detailDocument = DetailDokumenJaminan::find( + $request->detail_dokumen_jaminan_id[$key], + ); + + $detailDocument->update($detail); + $detailDocument->save(); + } + } + } else { + $detail = [ + 'dokumen_jaminan_id' => $document->id, + 'jenis_legalitas_jaminan_id' => $request->jenis_legalitas_jaminan_id[$key], + 'name' => $request->name[$key], + 'keterangan' => $request->keterangan[$key], + ]; + + if (isset($request->detail_dokumen_jaminan_id[$key])) { + $detailDocument = DetailDokumenJaminan::find( + $request->detail_dokumen_jaminan_id[$key], + ); + $detailDocument->update($detail); + } + } + } + } + + DB::commit(); return redirect()->route('debitur.jaminan.index', $id)->with( 'success', 'Dokumen Jaminan berhasil diubah', ); - } catch (Exception $e) { + } catch + (Exception $e) { + DB::rollBack(); return redirect()->route('debitur.jaminan.index', $id)->with('error', $e->getMessage()); } } } - public function edit($id, $jaminan) - { + public + function edit( + $id, + $jaminan, + ) { $document = DokumenJaminan::find($jaminan); + $details = DetailDokumenJaminan::where('dokumen_jaminan_id', $document->id)->get(); $debitur = Debiture::find($document->debiture_id); $provinces = Province::all(); $cities = City::where('province_code', $document->province_code)->get(); @@ -200,6 +249,7 @@ 'jenisJaminan', 'jenisLegalitasJaminan', 'document', + 'details', 'cities', 'districts', 'villages', @@ -208,10 +258,18 @@ ); } - public function destroy($id, $jaminan_id) - { + public + function destroy( + $id, + $jaminan_id, + ) { try { $jaminan = DokumenJaminan::find($jaminan_id); + $details = DetailDokumenJaminan::where('dokumen_jaminan_id',$jaminan->id)->get(); + foreach ($details as $detail){ + Storage::delete('public/'. $detail->dokumen_jaminan); + $detail->delete(); + } $jaminan->delete(); echo json_encode(['success' => true, 'message' => 'Dokumen Jaminan deleted successfully']); } catch (Exception $e) { @@ -219,7 +277,10 @@ } } - public function download($id){ + public + function download( + $id, + ) { $document = DetailDokumenJaminan::find($id); return response()->download(storage_path('app/public/' . $document->dokumen_jaminan)); } diff --git a/resources/views/debitur/components/dokumen.blade.php b/resources/views/debitur/components/dokumen.blade.php index 67063bf..0dfcc6f 100644 --- a/resources/views/debitur/components/dokumen.blade.php +++ b/resources/views/debitur/components/dokumen.blade.php @@ -56,7 +56,10 @@ Jenis Jaminan
- + @endif + +
+ + +
-
+
+ +
+ +
+
+ +
+ +
+ + @if(isset($detail->dokumen_jaminan)) + {{ basename($detail->dokumen_jaminan) }} + @endif +
+
+ +
+ +
+ +
+
+ @endforeach + @else +
+ +
+ @endif