[WIP] A
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
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\Database\Eloquent\SoftDeletes;
|
||||
use Str;
|
||||
|
||||
class ClaimRequest extends Model
|
||||
{
|
||||
@@ -13,17 +16,91 @@ class ClaimRequest extends Model
|
||||
|
||||
protected static $code_prefix = 'CRQ';
|
||||
|
||||
public $fillable = [
|
||||
'submission_date',
|
||||
'member_id',
|
||||
'status',
|
||||
'claim_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
// 'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public static $status = [
|
||||
'draft' => 'Draft',
|
||||
'requested' => 'Requested',
|
||||
'received' => 'Received',
|
||||
'approved' => 'Approved',
|
||||
'postpone' => 'Postpone',
|
||||
'paid' => 'Paid',
|
||||
'declined' => 'Declined'
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
try {
|
||||
$model->uuid = (string) Str::orderedUuid(); // generate uuid
|
||||
$model->code = self::getNextCode();
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
static::created(function ($model) {
|
||||
// try {
|
||||
// if (!empty($model->status) && $model->status == 'requested') {
|
||||
// $model->histories()->create([
|
||||
// 'title' => 'New Claim Requested',
|
||||
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
|
||||
// 'type' => 'info'
|
||||
// ]);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// abort(500, $e->getMessage());
|
||||
// }
|
||||
});
|
||||
|
||||
static::updated(function ($model) {
|
||||
if ($model->hasChanges(['status'])) {
|
||||
|
||||
// if ($model->status == 'requested') {
|
||||
// $model->histories()->create([
|
||||
// 'title' => 'New Claim Requested',
|
||||
// 'description' => "Claim Requested for Member : {$model->member->member_id} - ({$model->member->full_name})",
|
||||
// 'type' => 'info'
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// 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 static function getNextCode()
|
||||
@@ -39,17 +116,26 @@ class ClaimRequest extends Model
|
||||
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
public $fillable = [
|
||||
'submission_date',
|
||||
'member_id',
|
||||
'status'
|
||||
];
|
||||
public function claims()
|
||||
{
|
||||
return $this->hasMany(Claim::class, 'claim_request_id');
|
||||
}
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->morphMany(File::class, 'fileable');
|
||||
}
|
||||
|
||||
public function generatedDocuments()
|
||||
{
|
||||
return $this->morphMany(GeneratedDocument::class, 'generated_documentable');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->morphMany(ClaimHistory::class, 'historiable');
|
||||
}
|
||||
|
||||
public function member()
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
|
||||
Reference in New Issue
Block a user