[WIP] ASO Payment
This commit is contained in:
@@ -2,33 +2,30 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\ClaimApproved;
|
||||
use App\Events\ClaimDeclined;
|
||||
use App\Events\ClaimPaid;
|
||||
use App\Events\ClaimPostpone;
|
||||
use App\Events\ClaimReceived;
|
||||
use App\Events\ClaimRequested;
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Claim extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasFactory, Blameable;
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'member_id',
|
||||
'diagnosis_id',
|
||||
'total_claim',
|
||||
'currency',
|
||||
'plan_id',
|
||||
'benefit_id',
|
||||
'status',
|
||||
'requested_at',
|
||||
'requested_by',
|
||||
'received_at',
|
||||
'received_by',
|
||||
'approved_at',
|
||||
'approved_by',
|
||||
'declined',
|
||||
'declined_by',
|
||||
'paid_at',
|
||||
'paid_by',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -45,6 +42,7 @@ class Claim extends Model
|
||||
'requested' => 'Requested',
|
||||
'received' => 'Received',
|
||||
'approved' => 'Approved',
|
||||
'postpone' => 'Postpone',
|
||||
'paid' => 'Paid',
|
||||
'declined' => 'Declined'
|
||||
];
|
||||
@@ -60,6 +58,50 @@ class Claim extends Model
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
static::created(function ($model) {
|
||||
try {
|
||||
if (!empty($model->status)) {
|
||||
$model->statusHistories()->create([
|
||||
'status' => $model->status
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
static::updated(function ($model) {
|
||||
if ($model->hasChanges(['status'])) {
|
||||
$model->statusHistories()->create([
|
||||
'status' => $model->status
|
||||
]);
|
||||
|
||||
if ($model->status == 'requested') {
|
||||
ClaimRequested::dispatch($model);
|
||||
}
|
||||
|
||||
if ($model->status == 'received') {
|
||||
ClaimReceived::dispatch($model);
|
||||
}
|
||||
|
||||
if ($model->status == 'approved') {
|
||||
ClaimApproved::dispatch($model);
|
||||
}
|
||||
|
||||
if ($model->status == 'postpone') {
|
||||
ClaimPostpone::dispatch($model);
|
||||
}
|
||||
|
||||
if ($model->status == 'paid') {
|
||||
ClaimPaid::dispatch($model);
|
||||
}
|
||||
|
||||
if ($model->status == 'declined') {
|
||||
ClaimDeclined::dispatch($model);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function files()
|
||||
@@ -72,9 +114,19 @@ class Claim extends Model
|
||||
return $this->belongsTo(Member::class, 'member_id');
|
||||
}
|
||||
|
||||
public function diagnoses()
|
||||
{
|
||||
return $this->hasMany(ClaimDiagnosis::class, 'claim_id');
|
||||
}
|
||||
|
||||
// TODO Remove this !, Sementara
|
||||
public function diagnosis()
|
||||
{
|
||||
return $this->belongsTo(Icd::class, 'diagnosis_id');
|
||||
return $this->hasOne(ClaimDiagnosis::class, 'claim_id')->ofMany([
|
||||
'id' => 'min',
|
||||
], function ($query) {
|
||||
$query->where('type', 'primary');
|
||||
});
|
||||
}
|
||||
|
||||
public function plan()
|
||||
@@ -87,11 +139,16 @@ class Claim extends Model
|
||||
return $this->belongsTo(Benefit::class, 'benefit_id');
|
||||
}
|
||||
|
||||
public function statusHistories()
|
||||
{
|
||||
return $this->morphMany(StatusHistory::class, 'statusable');
|
||||
}
|
||||
|
||||
public function scopeUsed($query, $startDate, $endDate)
|
||||
{
|
||||
return $query
|
||||
->whereIn('status', ['approved', 'paid'])
|
||||
->whereBetween('requested_at', [$startDate, $endDate]);
|
||||
->whereIn('status', ['approved', 'paid']);
|
||||
// ->whereBetween('requested_at', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
13
app/Models/ClaimDiagnosis.php
Normal file
13
app/Models/ClaimDiagnosis.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaimDiagnosis extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'claim_diagnosis';
|
||||
}
|
||||
@@ -29,6 +29,15 @@ class Corporate extends Model
|
||||
protected $appends = [
|
||||
'avatar_url',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function imports()
|
||||
{
|
||||
|
||||
@@ -28,6 +28,15 @@ class CorporatePolicy extends Model
|
||||
'end',
|
||||
'active',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'latestLimitJournal'
|
||||
|
||||
@@ -17,6 +17,15 @@ class CorporateService extends Model
|
||||
'status',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function corporate()
|
||||
{
|
||||
return $this->belongsTo(Corporate::class);
|
||||
@@ -33,10 +42,20 @@ class CorporateService extends Model
|
||||
}
|
||||
|
||||
public function specialities()
|
||||
{
|
||||
return $this->belongsToMany(Speciality::class, 'corporate_service_specialities', 'corporate_service_id', 'speciality_id', 'id', 'id')
|
||||
->withPivot(['active']);
|
||||
}
|
||||
|
||||
public function corporateServiceSpecialities()
|
||||
{
|
||||
return $this->hasMany(CorporateServiceSpeciality::class, 'corporate_service_id');
|
||||
}
|
||||
|
||||
public function scopeActive($query) {
|
||||
$query->where('status', 'active');
|
||||
}
|
||||
|
||||
public function scopeFilter($query, array $filters)
|
||||
{
|
||||
if (!empty($filters['search'])) {
|
||||
|
||||
@@ -16,9 +16,23 @@ class CorporateServiceConfig extends Model
|
||||
'name',
|
||||
'value'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function corporateService()
|
||||
{
|
||||
return $this->belongsTo(CorporateService::class, 'corporate_service_id');
|
||||
}
|
||||
|
||||
public function exclusions()
|
||||
{
|
||||
return $this->morphMany(Exclusion::class, 'exclusionable');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,15 @@ class CorporateServiceSpeciality extends Model
|
||||
'speciality_id',
|
||||
'active'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function corporateService()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,15 @@ class Exclusion extends Model
|
||||
'exclusionable_id',
|
||||
'exclusionable_type',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function rules()
|
||||
{
|
||||
|
||||
@@ -16,6 +16,15 @@ class ExclusionRules extends Model
|
||||
'name',
|
||||
'values',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function exclusion()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,15 @@ class LimitJournal extends Model
|
||||
'balance',
|
||||
'description',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function journalable()
|
||||
{
|
||||
|
||||
@@ -62,7 +62,6 @@ class Member extends Model
|
||||
'full_name',
|
||||
'age',
|
||||
'gender_code',
|
||||
''
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
@@ -74,13 +73,16 @@ class Member extends Model
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
|
||||
|
||||
public function claims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
public function postponedClaims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'member_id', 'id')->where('status', 'postpone');
|
||||
}
|
||||
|
||||
public function person()
|
||||
{
|
||||
return $this->belongsTo(Person::class, 'person_id', 'id');
|
||||
|
||||
@@ -40,6 +40,15 @@ class Person extends Model
|
||||
'updated_by',
|
||||
'deleted_by'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function getFullNameAttribute()
|
||||
{
|
||||
|
||||
@@ -64,6 +64,15 @@ class Plan extends Model
|
||||
"max_surgery_reinstatement_days",
|
||||
"max_surgery_periode_days",
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public static $doc_headers_to_field_map = [
|
||||
"Service" => "service_code",
|
||||
@@ -170,15 +179,15 @@ class Plan extends Model
|
||||
|
||||
public function benefits()
|
||||
{
|
||||
return $this->belongsToMany(Benefit::class, 'corporate_benefits', 'benefit_id', 'id')
|
||||
return $this->belongsToMany(Benefit::class, 'corporate_benefits', 'plan_id', 'id')
|
||||
->withTimestamps()
|
||||
->withPivot([
|
||||
// TODO corporate_benefits pivot
|
||||
]);
|
||||
}
|
||||
|
||||
public function corporateBeneftis()
|
||||
public function corporateBenefits()
|
||||
{
|
||||
return $this->hasMany(CorporateBenefit::class, 'benefit_id', 'id');
|
||||
return $this->hasMany(CorporateBenefit::class, 'plan_id', 'id');
|
||||
}
|
||||
}
|
||||
|
||||
16
app/Models/StatusHistory.php
Normal file
16
app/Models/StatusHistory.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\Blameable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StatusHistory extends Model
|
||||
{
|
||||
use HasFactory, Blameable;
|
||||
|
||||
protected $fillable = [
|
||||
'status'
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user