190 lines
5.2 KiB
PHP
190 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Rules\NikRule;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use App\Models\Corporate;
|
|
use App\Models\CorporateFormularium;
|
|
use App\Models\CorporateService;
|
|
use App\Models\CorporatePlan;
|
|
use App\Models\CorporateBenefit;
|
|
use App\Models\Member;
|
|
use App\Models\ExclusionRules;
|
|
use App\Models\ExclusionImport;
|
|
use App\Models\Icd;
|
|
use App\Models\IcdTemplate;
|
|
use App\Models\FormulariumTemplate;
|
|
use App\Models\AuditTrail;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Str;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
Schema::defaultStringLength(191);
|
|
|
|
Str::macro('initials', fn($value, $sep = ' ', $glue = '') => trim(collect(explode($sep, $value))->map(function ($segment) {
|
|
return $segment[0] ?? '';
|
|
})->join($glue)));
|
|
|
|
// Menambahkan event listener untuk jejak audit pada model yang ingin di-audit
|
|
// Corporate::created(function ($model) {
|
|
// $this->logAuditTrail($model, 'created');
|
|
// });
|
|
|
|
Corporate::updated(function ($model) {
|
|
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
Corporate::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
Member::updated(function ($model) {
|
|
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
Member::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
|
|
// Corporate Service
|
|
CorporateService::updated(function ($model) {
|
|
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
CorporateService::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
// Corporate Plans
|
|
CorporatePlan::updated(function ($model) {
|
|
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
CorporatePlan::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
// Corporate Benefits
|
|
CorporateBenefit::updated(function ($model) {
|
|
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
CorporateBenefit::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
|
|
// Corporate Exclusion
|
|
ExclusionRules::updated(function ($model) {
|
|
|
|
$this->logAuditTrailExclusion($model, 'updated');
|
|
});
|
|
|
|
ExclusionRules::deleted(function ($model) {
|
|
$this->logAuditTrailExclusion($model, 'deleted');
|
|
});
|
|
|
|
ExclusionImport::updated(function ($model) {
|
|
|
|
$this->logAuditTrailExclusion($model, 'updated');
|
|
});
|
|
|
|
ExclusionImport::deleted(function ($model) {
|
|
$this->logAuditTrailExclusion($model, 'deleted');
|
|
});
|
|
|
|
// ICD or exlusion
|
|
Icd::updated(function ($model) {
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
|
|
Icd::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
// ICD or exlusion
|
|
IcdTemplate::updated(function ($model) {
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
IcdTemplate::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
// Formualrium Template
|
|
FormulariumTemplate::updated(function ($model) {
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
FormulariumTemplate::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
// Formualrium Template
|
|
CorporateFormularium::updated(function ($model) {
|
|
$this->logAuditTrail($model, 'updated');
|
|
});
|
|
CorporateFormularium::deleted(function ($model) {
|
|
$this->logAuditTrail($model, 'deleted');
|
|
});
|
|
|
|
|
|
}
|
|
|
|
private function logAuditTrail($model, $action)
|
|
{
|
|
// Membuat jejak audit baru
|
|
$auditTrail = new AuditTrail([
|
|
'model' => get_class($model),
|
|
'model_id' => $model->getKey(),
|
|
'action' => $action,
|
|
'old_values' => json_encode($model->getOriginal()),
|
|
'new_values' => json_encode($model->getAttributes()),
|
|
'user_id' => Auth::id(),
|
|
]);
|
|
|
|
// Simpan jejak audit
|
|
$auditTrail->save();
|
|
}
|
|
private function logAuditTrailExclusion($model, $action)
|
|
{
|
|
// Membuat jejak audit baru
|
|
$auditTrail = new AuditTrail([
|
|
'model' => get_class($model),
|
|
'model_id' => $model->corporate_id,
|
|
'action' => $action,
|
|
'old_values' => json_encode($model->getOriginal()),
|
|
'new_values' => json_encode($model->getAttributes()),
|
|
'user_id' => Auth::id(),
|
|
]);
|
|
|
|
// Simpan jejak audit
|
|
$auditTrail->save();
|
|
}
|
|
}
|