diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index 0d6ebb0..8cf40fb 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -353,4 +353,38 @@ // $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); // return $pdf->stream(); } + + public function showPembatalan($id) + { + $permohonan = Permohonan::with(['pembatalan','debiture'])->findOrFail($id); + return view('lpj::permohonan.pembatalan-form', compact('permohonan')); + } + + + public function pembatalan(Request $request) + { + // Validate the request + $validatedData = $request->validate([ + 'permohonan_id' => 'required|exists:permohonan,id', + 'alasan_pembatalan' => 'required|string', + 'file_pembatalan' => 'required|file|mimes:pdf,doc,docx|max:2048', + ]); + + // Handle file upload + if ($request->hasFile('file_pembatalan')) { + $file = $request->file('file_pembatalan'); + $filename = time() . '_' . $file->getClientOriginalName(); + $filePath = $file->storeAs('pembatalan', $filename, 'public'); + $validatedData['file_pembatalan'] = $filePath; + } + + // Add created_by + $validatedData['created_by'] = auth()->id(); + + // Create new PermohonanPembatalan + $pembatalan = PermohonanPembatalan::create($validatedData); + + return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval'); + } + } diff --git a/app/Models/Permohonan.php b/app/Models/Permohonan.php index f8d57da..cd76646 100644 --- a/app/Models/Permohonan.php +++ b/app/Models/Permohonan.php @@ -159,4 +159,8 @@ { return $this->hasMany(DokumenJaminan::class); } + + public function pembatalan(){ + return $this->hasMany(PermohonanPembatalan::class); + } } diff --git a/app/Models/PermohonanPembatalan.php b/app/Models/PermohonanPembatalan.php new file mode 100644 index 0000000..1197b2f --- /dev/null +++ b/app/Models/PermohonanPembatalan.php @@ -0,0 +1,50 @@ + 'string', + ]; + + // Relationship with Permohonan + public function permohonan() + { + return $this->belongsTo(Permohonan::class, 'permohonan_id'); + } + + public function creator(){ + return $this->belongsTo(User::class, 'created_by'); + } + } diff --git a/database/migrations/2024_12_22_140000_create_permohonan_pembatalans_table.php b/database/migrations/2024_12_22_140000_create_permohonan_pembatalans_table.php new file mode 100644 index 0000000..0046d05 --- /dev/null +++ b/database/migrations/2024_12_22_140000_create_permohonan_pembatalans_table.php @@ -0,0 +1,35 @@ +id(); + $table->unsignedBigInteger('permohonan_id'); + $table->text('alasan_pembatalan'); + $table->string('file_pembatalan'); + $table->enum('status', ['pending', 'approved', 'rejected'])->default('pending'); + $table->text('keterangan')->nullable(); + $table->timestamps(); + $table->timestamp('authorized_at')->nullable(); + $table->char('authorized_status', 1)->nullable(); + $table->softDeletes(); + $table->unsignedBigInteger('created_by')->nullable(); + $table->unsignedBigInteger('updated_by')->nullable(); + $table->unsignedBigInteger('deleted_by')->nullable(); + $table->unsignedBigInteger('authorized_by')->nullable(); + + $table->foreign('permohonan_id')->references('id')->on('permohonan')->onDelete('cascade'); + }); + } + + public function down() + { + Schema::dropIfExists('permohonan_pembatalan'); + } +} diff --git a/resources/views/permohonan/index.blade.php b/resources/views/permohonan/index.blade.php index 095752d..eccb166 100644 --- a/resources/views/permohonan/index.blade.php +++ b/resources/views/permohonan/index.blade.php @@ -8,7 +8,7 @@
| @@ -91,15 +91,15 @@ @push('scripts') |
|---|