Feature #17 : Module Permohonan
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
{
|
||||
return [
|
||||
$row->id,
|
||||
$row->branch->name .
|
||||
$row->branch->name,
|
||||
$row->cif,
|
||||
$row->nomor_rekening,
|
||||
$row->name,
|
||||
|
||||
67
app/Exports/PermohonanExport.php
Normal file
67
app/Exports/PermohonanExport.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Exports;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class PermohonanExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
|
||||
{
|
||||
public function collection()
|
||||
{
|
||||
return Permohonan::get();
|
||||
}
|
||||
|
||||
public function map($row)
|
||||
: array
|
||||
{
|
||||
return [
|
||||
$row->id,
|
||||
$row->nomor_registrasi,
|
||||
$row->tanggal_permohonan,
|
||||
$row->user->name,
|
||||
$row->branch->name,
|
||||
$row->tujuanPenilaian->name,
|
||||
$row->debiture->name,
|
||||
$row->status,
|
||||
$row->authorized_at,
|
||||
$row->authorized_status,
|
||||
$row->authorized_by,
|
||||
$row->created_at
|
||||
];
|
||||
}
|
||||
|
||||
public function headings()
|
||||
: array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'Nomor Registrasi',
|
||||
'Tanggal Permohonan',
|
||||
'User Pemohon',
|
||||
'Branch Pemohon',
|
||||
'Tujuan Penilaian',
|
||||
'Debitur',
|
||||
'Status',
|
||||
'Tanggal Pengesahan',
|
||||
'Status Pengesahan',
|
||||
'Pengesah',
|
||||
'Tanggal Dibuat'
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats()
|
||||
: array
|
||||
{
|
||||
return [
|
||||
'A' => NumberFormat::FORMAT_NUMBER,
|
||||
'C' => NumberFormat::FORMAT_DATE_DATETIME,
|
||||
'L' => NumberFormat::FORMAT_DATE_DATETIME
|
||||
];
|
||||
}
|
||||
}
|
||||
201
app/Http/Controllers/PermohonanController.php
Normal file
201
app/Http/Controllers/PermohonanController.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\PermohonanExport;
|
||||
use Modules\Lpj\Http\Requests\PermohonanRequest;
|
||||
use Modules\Lpj\Models\Branch;
|
||||
use Modules\Lpj\Models\Debiture;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
use Modules\Lpj\Models\TujuanPenilaian;
|
||||
|
||||
class PermohonanController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::permohonan.index');
|
||||
}
|
||||
|
||||
public function store(PermohonanRequest $request)
|
||||
{
|
||||
|
||||
$validate = $request->validated();
|
||||
|
||||
if ($validate) {
|
||||
try {
|
||||
// Save to database
|
||||
Permohonan::create($validate);
|
||||
return redirect()
|
||||
->route('permohonan.index')
|
||||
->with('success', 'Permohonan created successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect()
|
||||
->route('permohonan.create')
|
||||
->with('error', 'Failed to create permohonan'. $e->getMessage());
|
||||
}
|
||||
} else {
|
||||
return redirect()
|
||||
->route('permohonan.create')
|
||||
->with('success', 'error naon iye')
|
||||
->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$branches = Branch::all();
|
||||
$debitures = Debiture::all();
|
||||
$tujuanPenilaian = TujuanPenilaian::all();
|
||||
$status = [
|
||||
'order' => 'Order',
|
||||
'revisi' => 'Revisi',
|
||||
'register' => 'Register',
|
||||
'assign' => 'Assign',
|
||||
'survey' => 'Survey',
|
||||
'finalisasi' => 'Proses Laporan',
|
||||
'approved' => 'Diterima',
|
||||
'rejected' => 'Ditolak',
|
||||
'cancel' => 'Dibatalkan',
|
||||
'finished' => 'Selesai',
|
||||
'not_started' => 'Belum dimulai',
|
||||
];
|
||||
|
||||
return view('lpj::permohonan.form', compact('branches', 'debitures', 'tujuanPenilaian','status'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$permohonan = Permohonan::find($id);
|
||||
$branches = Branch::all();
|
||||
$debitures = Debiture::all();
|
||||
$tujuanPenilaian = TujuanPenilaian::all();
|
||||
$status = [
|
||||
'order' => 'Order',
|
||||
'revisi' => 'Revisi',
|
||||
'register' => 'Register',
|
||||
'assign' => 'Assign',
|
||||
'survey' => 'Survey',
|
||||
'finalisasi' => 'Proses Laporan',
|
||||
'approved' => 'Diterima',
|
||||
'rejected' => 'Ditolak',
|
||||
'cancel' => 'Dibatalkan',
|
||||
'finished' => 'Selesai',
|
||||
'not_started' => 'Belum dimulai',
|
||||
];
|
||||
|
||||
return view(
|
||||
'lpj::permohonan.form',
|
||||
compact('permohonan', 'branches', 'debitures', 'tujuanPenilaian','status'),
|
||||
);
|
||||
}
|
||||
|
||||
public function update(PermohonanRequest $request, $id)
|
||||
{
|
||||
$validate = $request->validated();
|
||||
|
||||
if ($validate) {
|
||||
try {
|
||||
// Update in database
|
||||
$permohonan = Permohonan::find($id);
|
||||
$permohonan->update($validate);
|
||||
return redirect()
|
||||
->route('permohonan.index')
|
||||
->with('success', 'Permohonan updated successfully');
|
||||
} catch (Exception $e) {
|
||||
return redirect()
|
||||
->route('permohonan.edit', $id)
|
||||
->with('error', 'Failed to update permohonan');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
// Delete from database
|
||||
$permohonan = Permohonan::find($id);
|
||||
$permohonan->delete();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Permohonan deleted successfully']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to delete permohonan']);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
$query = Permohonan::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_registrasi', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('branch', 'name', '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();
|
||||
|
||||
// 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(['user', 'debiture', 'branch', 'tujuanPenilaian'])->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,
|
||||
]);
|
||||
}
|
||||
|
||||
public function export()
|
||||
{
|
||||
return Excel::download(new PermohonanExport, 'permohonan.xlsx');
|
||||
}
|
||||
}
|
||||
50
app/Http/Requests/PermohonanRequest.php
Normal file
50
app/Http/Requests/PermohonanRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Requests;
|
||||
|
||||
use daengdeni\LaravelIdGenerator\IdGenerator;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class PermohonanRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules()
|
||||
: array
|
||||
{
|
||||
$rules = [
|
||||
'nomor_registrasi' => 'nullable|string|max:10',
|
||||
'tanggal_permohonan' => 'nullable|date',
|
||||
'user_id' => 'nullable|exists:users,id',
|
||||
'branch_id' => 'required|exists:branches,id',
|
||||
'tujuan_penilaian_id' => 'required|exists:tujuan_penilaian,id',
|
||||
'debiture_id' => 'required|exists:debitures,id',
|
||||
'status' => 'required|string',
|
||||
];
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize()
|
||||
: bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
if (!$this->id) {
|
||||
$this->merge([
|
||||
'nomor_registrasi' => IdGenerator::generate(
|
||||
['table' => 'permohonan', 'length' => 10, 'prefix'=>'REG', 'field' => 'nomor_registrasi'],
|
||||
),
|
||||
'tanggal_permohonan' => date('Y-m-d'),
|
||||
'user_id' => auth()->user()->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
app/Models/Permohonan.php
Normal file
45
app/Models/Permohonan.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Lpj\Database\Factories\PermohonanFactory;
|
||||
use Modules\Usermanagement\Models\User;
|
||||
|
||||
class Permohonan extends Base
|
||||
{
|
||||
protected $table = 'permohonan';
|
||||
protected $fillable = [
|
||||
'nomor_registrasi',
|
||||
'tanggal_permohonan',
|
||||
'user_id',
|
||||
'branch_id',
|
||||
'tujuan_penilaian_id',
|
||||
'debiture_id',
|
||||
'status',
|
||||
'authorized_at',
|
||||
'authorized_status',
|
||||
'authorized_by',
|
||||
];
|
||||
|
||||
public function user(){
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function branch(){
|
||||
return $this->belongsTo(Branch::class);
|
||||
}
|
||||
|
||||
public function tujuanPenilaian(){
|
||||
return $this->belongsTo(TujuanPenilaian::class);
|
||||
}
|
||||
|
||||
public function debiture(){
|
||||
return $this->belongsTo(Debiture::class);
|
||||
}
|
||||
|
||||
public function documents(){
|
||||
return $this->hasMany(DokumenJaminan::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user