Feat: Meningkatkan PermohonanController dengan fitur-fitur baru dan meningkatkan penanganan data
- Merombak PermohonanController agar struktur dan keterbacaannya lebih baik. - Menambahkan penanganan unggahan file dalam metode penyimpanan. - Menerapkan validasi data dan penanganan kesalahan untuk membuat dan memperbarui Permohonan. - Memperkenalkan pagination dan sorting dalam metode dataForDatatables dan dataForAuthorization. - Menambahkan fungsi ekspor untuk data Permohonan. - Membuat migrasi baru untuk menambahkan kolom 'nomor_registrasi' ke tabel 'persetujuan_penawaran'.
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
|
||||
class PembatalanController extends Controller
|
||||
{
|
||||
public $user;
|
||||
protected $historyService;
|
||||
|
||||
public function __construct(PermohonanHistoryService $historyService)
|
||||
@@ -36,23 +35,27 @@
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::pembatalan.index');
|
||||
$user = auth()->user();
|
||||
return view('lpj::pembatalan.index', compact('user'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture', 'permohonan.branch'])->find($id);
|
||||
|
||||
return view(
|
||||
'lpj::pembatalan.form',
|
||||
compact(
|
||||
'pembatalan'
|
||||
'pembatalan',
|
||||
'user'
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
||||
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
||||
$beforeRequest = $permohonan->toArray();
|
||||
@@ -62,7 +65,7 @@
|
||||
if ($request->status == 'approved') {
|
||||
$pembatalan->status = 'approved';
|
||||
$pembatalan->authorized_at = now();
|
||||
$pembatalan->authorized_by = auth()->user()->id;
|
||||
$pembatalan->authorized_by = $user->id;
|
||||
$pembatalan->authorized_status = 1;
|
||||
$pembatalan->save();
|
||||
|
||||
@@ -71,7 +74,7 @@
|
||||
} else {
|
||||
$pembatalan->status = 'rejected';
|
||||
$pembatalan->authorized_at = now();
|
||||
$pembatalan->authorized_by = auth()->user()->id;
|
||||
$pembatalan->authorized_by = $user->id;
|
||||
$pembatalan->authorized_status = 3;
|
||||
$pembatalan->save();
|
||||
}
|
||||
@@ -86,12 +89,13 @@
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
||||
$user = auth()->user();
|
||||
if (is_null($user) || !$user->can('debitur.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = PermohonanPembatalan::query();
|
||||
$query = PermohonanPembatalan::query()->with(['permohonan']);
|
||||
$query = $query->orderBy('created_at', 'desc');
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
@@ -108,8 +112,11 @@
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
// Only allow sorting by existing columns
|
||||
if (in_array($column, ['created_at', 'status', 'alasan_pembatalan'])) {
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
@@ -168,7 +170,7 @@
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query();
|
||||
|
||||
if (!Auth::user()->hasAnyRole(['administrator'])) {
|
||||
if (Auth::check() && !empty(Auth::user()->branch_id)) {
|
||||
$query = $query->where('branch_id', Auth::user()->branch_id);
|
||||
}
|
||||
|
||||
@@ -188,12 +190,36 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Log sorting parameters for debugging
|
||||
Log::debug('Sorting parameters', [
|
||||
'sortField' => $request->get('sortField'),
|
||||
'sortOrder' => $request->get('sortOrder')
|
||||
]);
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
|
||||
// Define allowed columns for sorting
|
||||
$allowedColumns = [
|
||||
'nomor_registrasi',
|
||||
'mig_mst_lpj_nomor_jaminan',
|
||||
'tanggal_permohonan',
|
||||
'status',
|
||||
'user_id',
|
||||
'branch_id'
|
||||
];
|
||||
|
||||
// Handle special cases for sorting
|
||||
if ($column === 'pemohon') {
|
||||
$query->orderBy('user_id', $order);
|
||||
} elseif ($column === 'branch') {
|
||||
$query->orderBy('branch_id', $order);
|
||||
} elseif (in_array($column, $allowedColumns)) {
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
@@ -284,7 +310,7 @@
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query()->with('documents')->has('documents', '>', 0)->where('status', '=', 'order');
|
||||
|
||||
if (!Auth::user()->hasAnyRole(['administrator'])) {
|
||||
if (Auth::check() && !empty(Auth::user()->branch_id)) {
|
||||
$query = $query->where('branch_id', Auth::user()->branch_id);
|
||||
}
|
||||
|
||||
@@ -405,7 +431,7 @@
|
||||
}
|
||||
|
||||
// Add created_by
|
||||
$validatedData['created_by'] = auth()->id();
|
||||
$validatedData['created_by'] = Auth::check() ? Auth::id() : null;
|
||||
|
||||
// Create new PermohonanPembatalan
|
||||
$pembatalan = PermohonanPembatalan::create($validatedData);
|
||||
@@ -413,8 +439,8 @@
|
||||
return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval');
|
||||
}
|
||||
|
||||
public function storeAproved(Request $request, $id)
|
||||
: JsonResponse {
|
||||
public function storeAproved(Request $request, $id): JsonResponse
|
||||
{
|
||||
$data = [];
|
||||
if (request()->ajax()) {
|
||||
try {
|
||||
@@ -514,5 +540,4 @@
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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('persetujuan_penawaran', function (Blueprint $table) {
|
||||
$table->string('nomor_registrasi')->nullable()->after('penawaran_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('persetujuan_penawaran', function (Blueprint $table) {
|
||||
$table->dropColumn('nomor_registrasi');
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user