[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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user