Merge branch 'staging' of https://git.putrakuningan.com/daengdeni/lpj into tender

This commit is contained in:
2024-11-14 08:32:29 +07:00
34 changed files with 1956 additions and 2344 deletions

View File

@@ -60,4 +60,8 @@
return $this->hasMany(DokumenJaminan::class);
}
public function permohonan(){
return $this->hasOne(Permohonan::class, 'debiture_id', 'id' );
}
}

View File

@@ -14,7 +14,17 @@ class Inspeksi extends Model
/**
* The attributes that are mass assignable.
*/
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by'];
protected $fillable = ['data_form', 'foto_form', 'denah_form','permohonan_id', 'name', 'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_by', 'updated_by', 'deleted_by','jenis_jaminan_id'];
public function permohonan()
{
return $this->belongsTo(Permohonan::class, 'permohonan_id');
}
public function jenis_jaminan()
{
return $this->belongsTo(JenisJaminan::class, 'jenis_jaminan_id');
}
// protected static function newFactory(): InspeksiFactory
// {

View File

@@ -5,5 +5,5 @@ namespace Modules\Lpj\Models;
class JenisJaminan extends Base
{
protected $table = 'jenis_jaminan';
protected $fillable = ['code', 'name', 'slug', 'jenis_legalitas_jaminan_id'];
protected $fillable = ['code', 'name', 'slug', 'jenis_legalitas_jaminan_id', 'form_kategori'];
}

View File

@@ -19,7 +19,7 @@ class Penilaian extends Model
protected $fillable = [
'jenis_penilaian_id', 'penilaian_id', 'tanggal_kunjungan', 'keterangan','nomor_registrasi',
'status', 'authorized_status', 'authorized_at', 'authorized_by', 'created_at',
'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by'
'created_by', 'updated_at', 'updated_by', 'deleted_at', 'deleted_by','waktu_penilaian', 'deskripsi_penilaian'
];
public function jenis_penilaian()

View File

@@ -3,6 +3,7 @@
namespace Modules\Lpj\Models;
use Modules\Lpj\Database\Factories\PermohonanFactory;
use Modules\Lpj\Services\PermohonanHistoryService;
use Modules\Usermanagement\Models\User;
class Permohonan extends Base
@@ -38,8 +39,66 @@ class Permohonan extends Base
'registrasi_at',
'jenis_penilaian_id',
'region_id',
'attachment'
];
protected static function boot()
{
parent::boot();
static::creating(function ($permohonan) {
static::handleFileUpload($permohonan);
});
static::updating(function ($permohonan) {
static::handleFileUpload($permohonan);
});
static::created(function ($permohonan) {
static::createHistory($permohonan, 'created');
});
static::updated(function ($permohonan) {
static::createHistory($permohonan, 'updated');
});
}
protected static function handleFileUpload($permohonan)
{
if (request()->hasFile('attachment')) {
$file = request()->file('attachment');
$fileName = time() . '_' . $file->getClientOriginalName();
$filePath = $file->storeAs('permohonan_attachments', $fileName, 'public');
// Delete old file if it exists
if ($permohonan->attachment) {
Storage::disk('public')->delete($permohonan->attachment);
}
$permohonan->attachment = $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->attachment ? Storage::disk('public')->path($permohonan->attachment) : null;
$historyService->createHistory(
$permohonan,
$status,
$keterangan,
$beforeRequest,
$afterRequest,
$file
);
}
public function user()
{
return $this->belongsTo(User::class);