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
|
class PembatalanController extends Controller
|
||||||
{
|
{
|
||||||
public $user;
|
|
||||||
protected $historyService;
|
protected $historyService;
|
||||||
|
|
||||||
public function __construct(PermohonanHistoryService $historyService)
|
public function __construct(PermohonanHistoryService $historyService)
|
||||||
@@ -36,23 +35,27 @@
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
return view('lpj::pembatalan.index');
|
$user = auth()->user();
|
||||||
|
return view('lpj::pembatalan.index', compact('user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
{
|
{
|
||||||
|
$user = auth()->user();
|
||||||
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture', 'permohonan.branch'])->find($id);
|
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture', 'permohonan.branch'])->find($id);
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'lpj::pembatalan.form',
|
'lpj::pembatalan.form',
|
||||||
compact(
|
compact(
|
||||||
'pembatalan'
|
'pembatalan',
|
||||||
|
'user'
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
{
|
{
|
||||||
|
$user = auth()->user();
|
||||||
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
||||||
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
||||||
$beforeRequest = $permohonan->toArray();
|
$beforeRequest = $permohonan->toArray();
|
||||||
@@ -62,7 +65,7 @@
|
|||||||
if ($request->status == 'approved') {
|
if ($request->status == 'approved') {
|
||||||
$pembatalan->status = 'approved';
|
$pembatalan->status = 'approved';
|
||||||
$pembatalan->authorized_at = now();
|
$pembatalan->authorized_at = now();
|
||||||
$pembatalan->authorized_by = auth()->user()->id;
|
$pembatalan->authorized_by = $user->id;
|
||||||
$pembatalan->authorized_status = 1;
|
$pembatalan->authorized_status = 1;
|
||||||
$pembatalan->save();
|
$pembatalan->save();
|
||||||
|
|
||||||
@@ -71,7 +74,7 @@
|
|||||||
} else {
|
} else {
|
||||||
$pembatalan->status = 'rejected';
|
$pembatalan->status = 'rejected';
|
||||||
$pembatalan->authorized_at = now();
|
$pembatalan->authorized_at = now();
|
||||||
$pembatalan->authorized_by = auth()->user()->id;
|
$pembatalan->authorized_by = $user->id;
|
||||||
$pembatalan->authorized_status = 3;
|
$pembatalan->authorized_status = 3;
|
||||||
$pembatalan->save();
|
$pembatalan->save();
|
||||||
}
|
}
|
||||||
@@ -86,12 +89,13 @@
|
|||||||
|
|
||||||
public function dataForDatatables(Request $request)
|
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.');
|
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = PermohonanPembatalan::query();
|
$query = PermohonanPembatalan::query()->with(['permohonan']);
|
||||||
$query = $query->orderBy('created_at', 'desc');
|
$query = $query->orderBy('created_at', 'desc');
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
@@ -108,8 +112,11 @@
|
|||||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||||
$order = $request->get('sortOrder');
|
$order = $request->get('sortOrder');
|
||||||
$column = $request->get('sortField');
|
$column = $request->get('sortField');
|
||||||
|
// Only allow sorting by existing columns
|
||||||
|
if (in_array($column, ['created_at', 'status', 'alasan_pembatalan'])) {
|
||||||
$query->orderBy($column, $order);
|
$query->orderBy($column, $order);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the total count of records
|
// Get the total count of records
|
||||||
$totalRecords = $query->count();
|
$totalRecords = $query->count();
|
||||||
|
|||||||
@@ -3,9 +3,11 @@
|
|||||||
namespace Modules\Lpj\Http\Controllers;
|
namespace Modules\Lpj\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\User;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
@@ -168,7 +170,7 @@
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = Permohonan::query();
|
$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);
|
$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
|
// Apply sorting if provided
|
||||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||||
$order = $request->get('sortOrder');
|
$order = $request->get('sortOrder');
|
||||||
$column = $request->get('sortField');
|
$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);
|
$query->orderBy($column, $order);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get the total count of records
|
// Get the total count of records
|
||||||
$totalRecords = $query->count();
|
$totalRecords = $query->count();
|
||||||
@@ -284,7 +310,7 @@
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = Permohonan::query()->with('documents')->has('documents', '>', 0)->where('status', '=', 'order');
|
$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);
|
$query = $query->where('branch_id', Auth::user()->branch_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,7 +431,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add created_by
|
// Add created_by
|
||||||
$validatedData['created_by'] = auth()->id();
|
$validatedData['created_by'] = Auth::check() ? Auth::id() : null;
|
||||||
|
|
||||||
// Create new PermohonanPembatalan
|
// Create new PermohonanPembatalan
|
||||||
$pembatalan = PermohonanPembatalan::create($validatedData);
|
$pembatalan = PermohonanPembatalan::create($validatedData);
|
||||||
@@ -413,8 +439,8 @@
|
|||||||
return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval');
|
return redirect()->route('permohonan.index')->with('success', 'Pembatalan Permohonan Menunggu Approval');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function storeAproved(Request $request, $id)
|
public function storeAproved(Request $request, $id): JsonResponse
|
||||||
: JsonResponse {
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
if (request()->ajax()) {
|
if (request()->ajax()) {
|
||||||
try {
|
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