update claim management

This commit is contained in:
2023-09-28 17:28:22 +07:00
parent 0fd79b8284
commit 601a8e5aff
8 changed files with 69 additions and 26 deletions

View File

@@ -14,7 +14,8 @@ class ClaimRequest extends Model
{
use HasFactory, SoftDeletes, Blameable;
protected static $code_prefix = 'CRQ';
// protected static $code_prefix_hospital = 'CRQ-H';
// protected static $code_prefix_client = 'CRQ-R';
public $fillable = [
'uuid',
@@ -24,7 +25,8 @@ class ClaimRequest extends Model
'service_code',
'policy_id',
'status',
'claim_id'
'claim_id',
'code'
];
protected $hidden = [
@@ -59,7 +61,7 @@ class ClaimRequest extends Model
static::creating(function ($model) {
try {
$model->uuid = (string) Str::orderedUuid(); // generate uuid
$model->code = self::getNextCode();
// $model->code = self::getNextCode();
} catch (\Exception $e) {
abort(500, $e->getMessage());
}
@@ -113,18 +115,18 @@ class ClaimRequest extends Model
});
}
public static function getNextCode()
{
$last_number = self::withTrashed()->max('code');
$next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
// public static function getNextCode()
// {
// $last_number = self::withTrashed()->max('code');
// $next_number = empty($last_number) ? 1 : ((int) explode('-', $last_number)[1] + 1);
return self::makeCode($next_number);
}
// return self::makeCode($next_number);
// }
public static function makeCode($next_number)
{
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
}
// public static function makeCode($next_number)
// {
// return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
// }
public function claim()
{