Format kode dan tambahkan relasi histories
Mengformat ulang kode model Permohonan untuk konsistensi indentasi dan keterbacaan. Menambahkan relasi `histories` untuk menghubungkan dengan model PermohonanHistory, berguna untuk melacak riwayat perubahan permohonan.
This commit is contained in:
@@ -1,150 +1,156 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Modules\Lpj\Models;
|
namespace Modules\Lpj\Models;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Modules\Lpj\Database\Factories\PermohonanFactory;
|
use Modules\Lpj\Database\Factories\PermohonanFactory;
|
||||||
use Modules\Lpj\Services\PermohonanHistoryService;
|
use Modules\Lpj\Services\PermohonanHistoryService;
|
||||||
use Modules\Usermanagement\Models\User;
|
use Modules\Usermanagement\Models\User;
|
||||||
|
|
||||||
class Permohonan extends Base
|
class Permohonan extends Base
|
||||||
{
|
|
||||||
protected $table = 'permohonan';
|
|
||||||
protected $fillable = [
|
|
||||||
'nomor_registrasi',
|
|
||||||
'tanggal_permohonan',
|
|
||||||
'user_id',
|
|
||||||
'branch_id',
|
|
||||||
'tujuan_penilaian_id',
|
|
||||||
'debiture_id',
|
|
||||||
'keterangan',
|
|
||||||
'dokumen',
|
|
||||||
'jenis_fasilitas_kredit_id',
|
|
||||||
'nilai_plafond_id',
|
|
||||||
'status',
|
|
||||||
'authorized_at',
|
|
||||||
'authorized_status',
|
|
||||||
'authorized_by',
|
|
||||||
// andy add
|
|
||||||
'registrasi_catatan',
|
|
||||||
'registrasi_by',
|
|
||||||
'registrasi_at',
|
|
||||||
'jenis_penilaian_id',
|
|
||||||
'region_id',
|
|
||||||
// andy add
|
|
||||||
'status_bayar',
|
|
||||||
'nilai_njop',
|
|
||||||
// andy add
|
|
||||||
'registrasi_catatan',
|
|
||||||
'registrasi_by',
|
|
||||||
'registrasi_at',
|
|
||||||
'jenis_penilaian_id',
|
|
||||||
'region_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected static function boot()
|
|
||||||
{
|
{
|
||||||
parent::boot();
|
protected $table = 'permohonan';
|
||||||
|
protected $fillable = [
|
||||||
|
'nomor_registrasi',
|
||||||
|
'tanggal_permohonan',
|
||||||
|
'user_id',
|
||||||
|
'branch_id',
|
||||||
|
'tujuan_penilaian_id',
|
||||||
|
'debiture_id',
|
||||||
|
'keterangan',
|
||||||
|
'dokumen',
|
||||||
|
'jenis_fasilitas_kredit_id',
|
||||||
|
'nilai_plafond_id',
|
||||||
|
'status',
|
||||||
|
'authorized_at',
|
||||||
|
'authorized_status',
|
||||||
|
'authorized_by',
|
||||||
|
// andy add
|
||||||
|
'registrasi_catatan',
|
||||||
|
'registrasi_by',
|
||||||
|
'registrasi_at',
|
||||||
|
'jenis_penilaian_id',
|
||||||
|
'region_id',
|
||||||
|
// andy add
|
||||||
|
'status_bayar',
|
||||||
|
'nilai_njop',
|
||||||
|
// andy add
|
||||||
|
'registrasi_catatan',
|
||||||
|
'registrasi_by',
|
||||||
|
'registrasi_at',
|
||||||
|
'jenis_penilaian_id',
|
||||||
|
'region_id',
|
||||||
|
];
|
||||||
|
|
||||||
static::creating(function ($permohonan) {
|
protected static function boot()
|
||||||
static::handleFileUpload($permohonan);
|
{
|
||||||
});
|
parent::boot();
|
||||||
|
|
||||||
static::updating(function ($permohonan) {
|
static::creating(function ($permohonan) {
|
||||||
static::handleFileUpload($permohonan);
|
static::handleFileUpload($permohonan);
|
||||||
});
|
});
|
||||||
|
|
||||||
static::created(function ($permohonan) {
|
static::updating(function ($permohonan) {
|
||||||
static::createHistory($permohonan, 'created');
|
static::handleFileUpload($permohonan);
|
||||||
});
|
});
|
||||||
|
|
||||||
static::updated(function ($permohonan) {
|
static::created(function ($permohonan) {
|
||||||
static::createHistory($permohonan, 'updated');
|
static::createHistory($permohonan, 'created');
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
protected static function handleFileUpload($permohonan)
|
static::updated(function ($permohonan) {
|
||||||
{
|
static::createHistory($permohonan, 'updated');
|
||||||
if (request()->hasFile('attachment')) {
|
});
|
||||||
$file = request()->file('attachment');
|
}
|
||||||
$fileName = time() . '_' . $file->getClientOriginalName();
|
|
||||||
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
|
|
||||||
|
|
||||||
$permohonan->dokumen = $filePath;
|
protected static function handleFileUpload($permohonan)
|
||||||
|
{
|
||||||
|
if (request()->hasFile('attachment')) {
|
||||||
|
$file = request()->file('attachment');
|
||||||
|
$fileName = time() . '_' . $file->getClientOriginalName();
|
||||||
|
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
|
||||||
|
|
||||||
|
$permohonan->dokumen = $filePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function createHistory($permohonan, $action)
|
||||||
|
{
|
||||||
|
$historyService = app(PermohonanHistoryService::class);
|
||||||
|
|
||||||
|
$status = $permohonan->status;
|
||||||
|
$keterangan = request()->input('keterangan'); // Get keterangan from request
|
||||||
|
$beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : [];
|
||||||
|
$afterRequest = $permohonan->toArray();
|
||||||
|
$file = $permohonan->dokumen ?? null;
|
||||||
|
|
||||||
|
$historyService->createHistory(
|
||||||
|
$permohonan,
|
||||||
|
$status,
|
||||||
|
$keterangan,
|
||||||
|
$beforeRequest,
|
||||||
|
$afterRequest,
|
||||||
|
$file,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nilaiPlafond()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(NilaiPlafond::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jenisFasilitasKredit()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(JenisFasilitasKredit::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function penilaian()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Penilaian::class, 'nomor_registrasi', 'nomor_registrasi');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function penawaranTender()
|
||||||
|
{
|
||||||
|
return $this->hasMany(PenawaranTender::class, 'nomor_registrasi');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function region()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Regions::class, 'region_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function penawaran()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(PenawaranTender::class, 'nomor_registrasi', 'nomor_registrasi');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function histories()
|
||||||
|
{
|
||||||
|
return $this->hasMany(PermohonanHistory::class, 'permohonan_id', 'id')->orderBy('created_at', 'desc');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function createHistory($permohonan, $action)
|
|
||||||
{
|
|
||||||
$historyService = app(PermohonanHistoryService::class);
|
|
||||||
|
|
||||||
$status = $permohonan->status;
|
|
||||||
$keterangan = request()->input('keterangan'); // Get keterangan from request
|
|
||||||
$beforeRequest = $action === 'updated' ? $permohonan->getOriginal() : [];
|
|
||||||
$afterRequest = $permohonan->toArray();
|
|
||||||
$file = $permohonan->dokumen ? Storage::disk('public')->path($permohonan->dokumen) : null;
|
|
||||||
|
|
||||||
$historyService->createHistory(
|
|
||||||
$permohonan,
|
|
||||||
$status,
|
|
||||||
$keterangan,
|
|
||||||
$beforeRequest,
|
|
||||||
$afterRequest,
|
|
||||||
$file
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nilaiPlafond()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(NilaiPlafond::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jenisFasilitasKredit()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(JenisFasilitasKredit::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function penilaian()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Penilaian::class, 'nomor_registrasi', 'nomor_registrasi');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function penawaranTender()
|
|
||||||
{
|
|
||||||
return $this->hasMany(PenawaranTender::class, 'nomor_registrasi');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function region()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Regions::class, 'region_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function penawaran(){
|
|
||||||
return $this->belongsTo(PenawaranTender::class, 'nomor_registrasi', 'nomor_registrasi');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user