feat(laporan_external): tambahkan fitur laporan eksternal
- Menambahkan controller LaporanExternalController untuk mengelola laporan eksternal. - Menambahkan request LaporanExternalRequest untuk validasi data laporan eksternal. - Menambahkan model LaporanExternal untuk interaksi dengan database. - Menambahkan migrasi untuk tabel laporan_externals dengan kolom yang diperlukan.
This commit is contained in:
171
app/Http/Controllers/LaporanExternalController.php
Normal file
171
app/Http/Controllers/LaporanExternalController.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\LaporanExternal;
|
||||
use Modules\Lpj\Http\Requests\LaporanExternalRequest;
|
||||
|
||||
class LaporanExternalController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$laporanExternals = LaporanExternal::with('permohonan')->paginate(10);
|
||||
return view('lpj::laporan_external.index', compact('laporanExternals'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('lpj::laporan_external.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(LaporanExternalRequest $request)
|
||||
{
|
||||
$validatedData = $request->validated();
|
||||
|
||||
if ($request->hasFile('file_resume')) {
|
||||
$validatedData['file_resume'] = $request->file('file_resume')->store('laporan_external/resume', 'public');
|
||||
}
|
||||
|
||||
if ($request->hasFile('file_laporan')) {
|
||||
$validatedData['file_laporan'] = $request->file('file_laporan')->store('laporan_external/laporan', 'public');
|
||||
}
|
||||
|
||||
LaporanExternal::create($validatedData);
|
||||
|
||||
return redirect()->route('lpj.laporan_external.index')->with('success', 'Laporan External berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show(LaporanExternal $laporanExternal)
|
||||
{
|
||||
return view('lpj::laporan_external.show', compact('laporanExternal'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(LaporanExternal $laporanExternal)
|
||||
{
|
||||
return view('lpj::laporan_external.edit', compact('laporanExternal'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(LaporanExternalRequest $request, LaporanExternal $laporanExternal)
|
||||
{
|
||||
$validatedData = $request->validated();
|
||||
|
||||
if ($request->hasFile('file_resume')) {
|
||||
$validatedData['file_resume'] = $request->file('file_resume')->store('laporan_external/resume', 'public');
|
||||
}
|
||||
|
||||
if ($request->hasFile('file_laporan')) {
|
||||
$validatedData['file_laporan'] = $request->file('file_laporan')->store('laporan_external/laporan', 'public');
|
||||
}
|
||||
|
||||
$laporanExternal->update($validatedData);
|
||||
|
||||
return redirect()->route('lpj.laporan_external.index')->with('success', 'Laporan External berhasil diperbarui.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(LaporanExternal $laporanExternal)
|
||||
{
|
||||
$laporanExternal->delete();
|
||||
|
||||
return redirect()->route('lpj.laporan_external.index')->with('success', 'Laporan External berhasil dihapus.');
|
||||
}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('jenis_aset.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = LaporanExternal::query();
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_laporan', 'LIKE', "%$search%")
|
||||
->orWhere('tanggal_laporan', 'LIKE', "%$search%")
|
||||
->orWhereHas('permohonan', function($q) use ($search) {
|
||||
$q->where('nomor_permohonan', 'LIKE', "%$search%");
|
||||
})
|
||||
->orWhere('tgl_final_laporan', 'LIKE', "%$search%")
|
||||
->orWhere('nilai_pasar', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_likuidasi', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_pasar_tanah', 'LIKE', "%$search%")
|
||||
->orWhere('estimasi_harga_tanah', 'LIKE', "%$search%")
|
||||
->orWhere('estimasi_harga_bangunan', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_pasar_bangunan', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_pasar_sarana_pelengkap', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_pasar_mesin', 'LIKE', "%$search%")
|
||||
->orWhere('indikasi_nilai_pasar_kendaraan_alat_berat', 'LIKE', "%$search%")
|
||||
->orWhere('file_resume', 'LIKE', "%$search%")
|
||||
->orWhere('file_laporan', 'LIKE', "%$search%");
|
||||
->orWhere('tanggal_laporan', '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();
|
||||
|
||||
// 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->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = 0 + 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
41
app/Http/Requests/LaporanExternalRequest.php
Normal file
41
app/Http/Requests/LaporanExternalRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LaporanExternalRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules()
|
||||
: array
|
||||
{
|
||||
return [
|
||||
'permohonan_id' => 'required|exists:permohonans,id',
|
||||
'nomor_laporan' => 'required|string|max:255',
|
||||
'tgl_final_laporan' => 'required|date',
|
||||
'nilai_pasar' => 'required|numeric',
|
||||
'indikasi_nilai_likuidasi' => 'required|numeric',
|
||||
'indikasi_nilai_pasar_tanah' => 'required|numeric',
|
||||
'estimasi_harga_tanah' => 'required|numeric',
|
||||
'estimasi_harga_bangunan' => 'required|numeric',
|
||||
'indikasi_nilai_pasar_bangunan' => 'required|numeric',
|
||||
'indikasi_nilai_pasar_sarana_pelengkap' => 'required|numeric',
|
||||
'indikasi_nilai_pasar_mesin' => 'required|numeric',
|
||||
'indikasi_nilai_pasar_kendaraan_alat_berat' => 'required|numeric',
|
||||
'file_resume' => 'nullable|file|mimes:pdf|max:10240', // 10MB max
|
||||
'file_laporan' => 'nullable|file|mimes:pdf|max:10240',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize()
|
||||
: bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
32
app/Models/LaporanExternal.php
Normal file
32
app/Models/LaporanExternal.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
// use Modules\Lpj\Database\Factories\LaporanExternalFactory;
|
||||
|
||||
class LaporanExternal extends Base
|
||||
{
|
||||
protected $fillable = [
|
||||
'permohonan_id',
|
||||
'nomor_laporan',
|
||||
'tgl_final_laporan',
|
||||
'nilai_pasar',
|
||||
'indikasi_nilai_likuidasi',
|
||||
'indikasi_nilai_pasar_tanah',
|
||||
'estimasi_harga_tanah',
|
||||
'estimasi_harga_bangunan',
|
||||
'indikasi_nilai_pasar_bangunan',
|
||||
'indikasi_nilai_pasar_sarana_pelengkap',
|
||||
'indikasi_nilai_pasar_mesin',
|
||||
'indikasi_nilai_pasar_kendaraan_alat_berat',
|
||||
'file_resume',
|
||||
'file_laporan',
|
||||
];
|
||||
|
||||
public function permohonan()
|
||||
{
|
||||
return $this->belongsTo(Permohonan::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?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::create('laporan_externals', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('permohonan_id')->constrained('permohonans')->onDelete('cascade');
|
||||
$table->string('nomor_laporan');
|
||||
$table->date('tgl_final_laporan');
|
||||
$table->decimal('nilai_pasar', 15, 2);
|
||||
$table->decimal('indikasi_nilai_likuidasi', 15, 2);
|
||||
$table->decimal('indikasi_nilai_pasar_tanah', 15, 2);
|
||||
$table->decimal('estimasi_harga_tanah', 15, 2);
|
||||
$table->decimal('estimasi_harga_bangunan', 15, 2);
|
||||
$table->decimal('indikasi_nilai_pasar_bangunan', 15, 2);
|
||||
$table->decimal('indikasi_nilai_pasar_sarana_pelengkap', 15, 2);
|
||||
$table->decimal('indikasi_nilai_pasar_mesin', 15, 2);
|
||||
$table->decimal('indikasi_nilai_pasar_kendaraan_alat_berat', 15, 2);
|
||||
$table->string('file_resume')->nullable(); // New field for resume file
|
||||
$table->string('file_laporan')->nullable(); // New field for report file
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->unsignedBigInteger('created_by')->nullable();
|
||||
$table->unsignedBigInteger('updated_by')->nullable();
|
||||
$table->unsignedBigInteger('deleted_by')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('laporan_externals');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user