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:
@@ -1,153 +1,160 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Modules\Lpj\Http\Controllers;
|
namespace Modules\Lpj\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Modules\Location\Models\City;
|
use Modules\Location\Models\City;
|
||||||
use Modules\Location\Models\District;
|
use Modules\Location\Models\District;
|
||||||
use Modules\Location\Models\Province;
|
use Modules\Location\Models\Province;
|
||||||
use Modules\Location\Models\Village;
|
use Modules\Location\Models\Village;
|
||||||
use Modules\Lpj\Exports\PermohonanExport;
|
use Modules\Lpj\Exports\PermohonanExport;
|
||||||
use Modules\Lpj\Http\Requests\PermohonanRequest;
|
use Modules\Lpj\Http\Requests\PermohonanRequest;
|
||||||
use Modules\Lpj\Models\Branch;
|
use Modules\Lpj\Models\Branch;
|
||||||
use Modules\Lpj\Models\Debiture;
|
use Modules\Lpj\Models\Debiture;
|
||||||
use Modules\Lpj\Models\DokumenJaminan;
|
use Modules\Lpj\Models\DokumenJaminan;
|
||||||
use Modules\Lpj\Models\JenisFasilitasKredit;
|
use Modules\Lpj\Models\JenisFasilitasKredit;
|
||||||
use Modules\Lpj\Models\NilaiPlafond;
|
use Modules\Lpj\Models\NilaiPlafond;
|
||||||
use Modules\Lpj\Models\Permohonan;
|
use Modules\Lpj\Models\Permohonan;
|
||||||
use Modules\Lpj\Models\PermohonanPembatalan;
|
use Modules\Lpj\Models\PermohonanPembatalan;
|
||||||
use Modules\Lpj\Models\StatusPermohonan;
|
use Modules\Lpj\Models\StatusPermohonan;
|
||||||
use Modules\Lpj\Models\TujuanPenilaian;
|
use Modules\Lpj\Models\TujuanPenilaian;
|
||||||
use Modules\Lpj\Services\PermohonanHistoryService;
|
use Modules\Lpj\Services\PermohonanHistoryService;
|
||||||
|
|
||||||
class PembatalanController extends Controller
|
class PembatalanController extends Controller
|
||||||
|
{
|
||||||
|
protected $historyService;
|
||||||
|
|
||||||
|
public function __construct(PermohonanHistoryService $historyService)
|
||||||
{
|
{
|
||||||
public $user;
|
$this->historyService = $historyService;
|
||||||
protected $historyService;
|
}
|
||||||
|
|
||||||
public function __construct(PermohonanHistoryService $historyService)
|
public function index()
|
||||||
{
|
{
|
||||||
$this->historyService = $historyService;
|
$user = auth()->user();
|
||||||
}
|
return view('lpj::pembatalan.index', compact('user'));
|
||||||
|
}
|
||||||
|
|
||||||
public function index()
|
public function edit($id)
|
||||||
{
|
{
|
||||||
return view('lpj::pembatalan.index');
|
$user = auth()->user();
|
||||||
}
|
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture', 'permohonan.branch'])->find($id);
|
||||||
|
|
||||||
public function edit($id)
|
return view(
|
||||||
{
|
'lpj::pembatalan.form',
|
||||||
$pembatalan = PermohonanPembatalan::with(['permohonan.debiture','permohonan.branch'])->find($id);
|
compact(
|
||||||
|
'pembatalan',
|
||||||
|
'user'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return view(
|
public function update(Request $request, $id)
|
||||||
'lpj::pembatalan.form',
|
{
|
||||||
compact(
|
$user = auth()->user();
|
||||||
'pembatalan'
|
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
||||||
),
|
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
||||||
);
|
$beforeRequest = $permohonan->toArray();
|
||||||
}
|
|
||||||
|
|
||||||
public function update(Request $request, $id)
|
try {
|
||||||
{
|
// Update Permohonan Pembatalan
|
||||||
$pembatalan = PermohonanPembatalan::findOrFail($id);
|
if ($request->status == 'approved') {
|
||||||
$permohonan = Permohonan::find($pembatalan->permohonan_id);
|
$pembatalan->status = 'approved';
|
||||||
$beforeRequest = $permohonan->toArray();
|
$pembatalan->authorized_at = now();
|
||||||
|
$pembatalan->authorized_by = $user->id;
|
||||||
|
$pembatalan->authorized_status = 1;
|
||||||
|
$pembatalan->save();
|
||||||
|
|
||||||
try {
|
$permohonan->status = 'batal';
|
||||||
// Update Permohonan Pembatalan
|
$permohonan->save();
|
||||||
if($request->status=='approved'){
|
} else {
|
||||||
$pembatalan->status = 'approved';
|
$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 = 1;
|
$pembatalan->authorized_status = 3;
|
||||||
$pembatalan->save();
|
$pembatalan->save();
|
||||||
|
|
||||||
$permohonan->status = 'batal';
|
|
||||||
$permohonan->save();
|
|
||||||
} else{
|
|
||||||
$pembatalan->status = 'rejected';
|
|
||||||
$pembatalan->authorized_at = now();
|
|
||||||
$pembatalan->authorized_by = auth()->user()->id;
|
|
||||||
$pembatalan->authorized_status = 3;
|
|
||||||
$pembatalan->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()
|
|
||||||
->route('pembatalan.index')->with('success', 'Permohonan Pembatalan updated successfully');
|
|
||||||
} catch (Exception $e) {
|
|
||||||
return redirect()
|
|
||||||
->route('pembatalan.edit', $id)->with('error', 'Failed to update permohonan Pembatalan');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function dataForDatatables(Request $request)
|
|
||||||
{
|
|
||||||
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
|
||||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve data from the database
|
return redirect()
|
||||||
$query = PermohonanPembatalan::query();
|
->route('pembatalan.index')->with('success', 'Permohonan Pembatalan updated successfully');
|
||||||
$query = $query->orderBy('created_at', 'desc');
|
} catch (Exception $e) {
|
||||||
// Apply search filter if provided
|
return redirect()
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
->route('pembatalan.edit', $id)->with('error', 'Failed to update permohonan Pembatalan');
|
||||||
$search = $request->get('search');
|
|
||||||
$query->where(function ($q) use ($search) {
|
|
||||||
$q->orWhereRelation('permohonan', 'nomor_registrasi', 'LIKE', '%' . $search . '%');
|
|
||||||
$q->orWhereRelation('permohonan.debiture', 'name', 'LIKE', '%' . $search . '%');
|
|
||||||
$q->orWhere('alasan_pembatalan', 'LIKE', '%' . $search . '%');
|
|
||||||
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply sorting if provided
|
|
||||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
|
||||||
$order = $request->get('sortOrder');
|
|
||||||
$column = $request->get('sortField');
|
|
||||||
$query->orderBy($column, $order);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the total count of records
|
|
||||||
$totalRecords = $query->count();
|
|
||||||
$size = $request->get('size', 10);
|
|
||||||
if ($size == 0) {
|
|
||||||
$size = 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply pagination if provided
|
|
||||||
if ($request->has('page') && $request->has('size')) {
|
|
||||||
$page = $request->get('page');
|
|
||||||
$size = $request->get('size');
|
|
||||||
$offset = ($page - 1) * $size; // Calculate the offset
|
|
||||||
|
|
||||||
$query->skip($offset)->take($size);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the filtered count of records
|
|
||||||
$filteredRecords = $query->count();
|
|
||||||
|
|
||||||
// Get the data for the current page
|
|
||||||
$data = $query->with(['permohonan.debiture','permohonan.branch','creator'])->get();
|
|
||||||
|
|
||||||
// Calculate the page count
|
|
||||||
$pageCount = ceil($totalRecords / $size);
|
|
||||||
|
|
||||||
// Calculate the current page number
|
|
||||||
$currentPage = max(1, $request->get('page', 1));
|
|
||||||
|
|
||||||
// Return the response data as a JSON object
|
|
||||||
return response()->json([
|
|
||||||
'draw' => $request->get('draw'),
|
|
||||||
'recordsTotal' => $totalRecords,
|
|
||||||
'recordsFiltered' => $filteredRecords,
|
|
||||||
'pageCount' => $pageCount,
|
|
||||||
'page' => $currentPage,
|
|
||||||
'totalCount' => $totalRecords,
|
|
||||||
'data' => $data,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataForDatatables(Request $request)
|
||||||
|
{
|
||||||
|
$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()->with(['permohonan']);
|
||||||
|
$query = $query->orderBy('created_at', 'desc');
|
||||||
|
// Apply search filter if provided
|
||||||
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
|
$search = $request->get('search');
|
||||||
|
$query->where(function ($q) use ($search) {
|
||||||
|
$q->orWhereRelation('permohonan', 'nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||||
|
$q->orWhereRelation('permohonan.debiture', 'name', 'LIKE', '%' . $search . '%');
|
||||||
|
$q->orWhere('alasan_pembatalan', 'LIKE', '%' . $search . '%');
|
||||||
|
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply sorting if provided
|
||||||
|
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();
|
||||||
|
$size = $request->get('size', 10);
|
||||||
|
if ($size == 0) {
|
||||||
|
$size = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply pagination if provided
|
||||||
|
if ($request->has('page') && $request->has('size')) {
|
||||||
|
$page = $request->get('page');
|
||||||
|
$size = $request->get('size');
|
||||||
|
$offset = ($page - 1) * $size; // Calculate the offset
|
||||||
|
|
||||||
|
$query->skip($offset)->take($size);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the filtered count of records
|
||||||
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
|
// Get the data for the current page
|
||||||
|
$data = $query->with(['permohonan.debiture', 'permohonan.branch', 'creator'])->get();
|
||||||
|
|
||||||
|
// Calculate the page count
|
||||||
|
$pageCount = ceil($totalRecords / $size);
|
||||||
|
|
||||||
|
// Calculate the current page number
|
||||||
|
$currentPage = max(1, $request->get('page', 1));
|
||||||
|
|
||||||
|
// Return the response data as a JSON object
|
||||||
|
return response()->json([
|
||||||
|
'draw' => $request->get('draw'),
|
||||||
|
'recordsTotal' => $totalRecords,
|
||||||
|
'recordsFiltered' => $filteredRecords,
|
||||||
|
'pageCount' => $pageCount,
|
||||||
|
'page' => $currentPage,
|
||||||
|
'totalCount' => $totalRecords,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -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