Tambah fitur pembatalan permohonan

- Menambahkan model, migration, dan relasi untuk tabel pembatalan permohonan.
- Mengubah fungsi delete menjadi pembatalan permohonan dengan konfirmasi pengguna.
- Menambahkan route baru untuk form dan proses pembatalan permohonan.
- Menyediakan form input alasan dan file pendukung untuk pembatalan permohonan.
- Memperbarui tampilan, fungsi controller, dan breadcrumbs terkait pembatalan permohonan.
This commit is contained in:
Daeng Deni Mardaeni
2024-12-23 15:43:53 +07:00
parent 8dde09bcfa
commit e5d4874af1
8 changed files with 227 additions and 21 deletions

View File

@@ -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');
}
}

View File

@@ -159,4 +159,8 @@
{
return $this->hasMany(DokumenJaminan::class);
}
public function pembatalan(){
return $this->hasMany(PermohonanPembatalan::class);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Modules\Lpj\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Lpj\Models\Permohonan;
use Modules\Usermanagement\Models\User;
class PermohonanPembatalan extends Base
{
protected $table = 'permohonan_pembatalan';
protected $fillable = [
'permohonan_id',
'alasan_pembatalan',
'file_pembatalan',
'status',
'keterangan',
'authorized_at',
'authorized_status',
'created_by',
'updated_by',
'deleted_by',
'authorized_by',
];
protected $dates = [
'created_at',
'updated_at',
'deleted_at',
'authorized_at',
];
protected $casts = [
'authorized_status' => 'string',
];
// Relationship with Permohonan
public function permohonan()
{
return $this->belongsTo(Permohonan::class, 'permohonan_id');
}
public function creator(){
return $this->belongsTo(User::class, 'created_by');
}
}

View File

@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePermohonanPembatalansTable extends Migration
{
public function up()
{
Schema::create('permohonan_pembatalan', function (Blueprint $table) {
$table->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');
}
}

View File

@@ -8,7 +8,7 @@
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="10"
data-datatable-state-save="false" id="permohonan-table" data-api-url="{{ route('permohonan.datatables') }}">
data-datatable-state-save="false" id="permohonan-table" data-api-url="{{ route('permohonan.datatables') }}">
<div class="card-header py-5 flex-wrap">
<h3 class="card-title">
Daftar Permohonan
@@ -29,7 +29,7 @@
<div class="card-body">
<div class="scrollable-x-auto">
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm"
data-datatable-table="true">
data-datatable-table="true">
<thead>
<tr>
<th class="w-14">
@@ -91,15 +91,15 @@
@push('scripts')
<script type="text/javascript">
function deleteData(data) {
function deleteData(data, noReg, debitur) {
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
title: 'Pembatalan Permohonan',
text: "Yakin akan membatalkan permohonan dengan nomor " + noReg + " untuk Debitur " + debitur + "?",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
confirmButtonText: 'Yes!'
}).then((result) => {
if (result.isConfirmed) {
$.ajaxSetup({
@@ -108,16 +108,7 @@
}
});
$.ajax(`permohonan/${data}`, {
type: 'DELETE'
}).then((response) => {
swal.fire('Deleted!', 'User has been deleted.', 'success').then(() => {
window.location.reload();
});
}).catch((error) => {
console.error('Error:', error);
Swal.fire('Error!', 'An error occurred while deleting the file.', 'error');
});
window.location = `permohonan/${data}/pembatalan`;
}
})
}
@@ -225,11 +216,14 @@
actionHtml += `
<a class="btn btn-sm btn-outline btn-info" href="permohonan/${data.id}/edit" title="Edit Permohonan">
<i class="ki-outline ki-notepad-edit"></i>
</a>
<a onclick="deleteData(${data.id})" class="delete btn btn-sm btn-outline btn-danger" title="Hapus Permohonan">
<i class="ki-outline ki-trash"></i>
</a>
</div>`;
</a>`;
if(data.status !== 'batal') {
actionHtml += `
<a onclick="deleteData(${data.id}, '${data.nomor_registrasi}','${data.debiture.name}')" class="delete btn btn-sm btn-outline btn-danger" title="Batalkan Permohonan">
<i class="ki-outline ki-cross-square"></i>
</a>`;
}
actionHtml += `</div>`;
return actionHtml;
},

View File

@@ -0,0 +1,73 @@
@extends('layouts.main')
@section('breadcrumbs')
{{ Breadcrumbs::render(request()->route()->getName()) }}
@endsection
@section('content')
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
<div class="card pb-2.5">
<div class="card-header">
<h3 class="card-title">Form Pembatalan Permohonan</h3>
<div class="flex items-center gap-2">
<a href="{{ route('permohonan.index') }}" class="btn btn-xs btn-info"><i class="ki-filled ki-exit-left"></i> Back</a>
</div>
</div>
<div class="card-body">
<form action="{{ route('permohonan.pembatalan', $permohonan) }}" method="POST" class="grid gap-5" enctype="multipart/form-data">
@csrf
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Nomor Registrasi
</label>
<div class="flex flex-wrap items-baseline w-full">
<input type="hidden" name="permohonan_id" value="{{ $permohonan->id }}">
<input type="text" class="input" value="{{ $permohonan->nomor_registrasi ?? '' }}" readonly>
</div>
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Nama Debitur
</label>
<div class="flex flex-wrap items-baseline w-full">
<input type="text" class="input" value="{{ $permohonan->debiture->name ?? '' }}" readonly>
</div>
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Alasan Pembatalan
</label>
<div class="flex flex-wrap items-baseline w-full">
<textarea class="textarea @error('alasan_pembatalan') border-danger bg-danger-light @enderror"
name="alasan_pembatalan"
rows="4">{{ old('alasan_pembatalan') }}</textarea>
@error('alasan_pembatalan')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
</div>
</div>
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label class="form-label max-w-56">
Dokumen Pendukung
</label>
<div class="flex flex-wrap items-baseline w-full">
<input type="file" class="file-input @error('file_pembatalan') border-danger bg-danger-light @enderror"
name="file_pembatalan">
@error('file_pembatalan')
<em class="alert text-danger text-sm">{{ $message }}</em>
@enderror
</div>
</div>
<div class="flex justify-end">
<button type="submit" class="btn btn-primary">Submit Pembatalan</button>
</div>
</form>
</div>
</div>
</div>
@endsection

View File

@@ -298,6 +298,20 @@
$trail->push('Data Permohonan');
});
Breadcrumbs::for('permohonan.show-pembatalan', function (BreadcrumbTrail $trail) {
$trail->parent('permohonan.index');
$trail->push('Show Pembatalan Permohonan');
});
Breadcrumbs::for('pembatalan', function (BreadcrumbTrail $trail) {
$trail->push('Pembatalan', route('pembatalan.index'));
});
Breadcrumbs::for('pembatalan.edit', function (BreadcrumbTrail $trail) {
$trail->parent('pembatalan');
$trail->push('Show Pembatalan');
});
Breadcrumbs::for('basicdata.region', function (BreadcrumbTrail $trail) {
$trail->parent('basicdata');
$trail->push('Region', route('basicdata.region.index'));

View File

@@ -367,6 +367,8 @@ Route::middleware(['auth'])->group(function () {
});
Route::get('authorization', [PermohonanController::class, 'authorization'])->name('authorization.index');
Route::get('permohonan/{id}/pembatalan', [PermohonanController::class, 'showPembatalan'])->name('permohonan.show-pembatalan');
Route::post('permohonan/pembatalan', [PermohonanController::class, 'pembatalan'])->name('permohonan.pembatalan');
Route::resource('permohonan', PermohonanController::class);