[WIP] A
This commit is contained in:
@@ -18,8 +18,11 @@ use Illuminate\Support\Str;
|
||||
class Claim extends Model
|
||||
{
|
||||
use HasFactory, Blameable, SoftDeletes;
|
||||
|
||||
protected static $code_prefix = 'CLM';
|
||||
|
||||
protected $fillable = [
|
||||
'claim_request_id',
|
||||
'code',
|
||||
'member_id',
|
||||
'total_claim',
|
||||
@@ -54,7 +57,8 @@ class Claim extends Model
|
||||
|
||||
static::creating(function ($model) {
|
||||
try {
|
||||
$model->code = (string) Str::orderedUuid(); // generate uuid
|
||||
$model->uuid = (string) Str::orderedUuid(); // generate uuid
|
||||
$model->code = self::getNextCode();
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
@@ -78,9 +82,9 @@ class Claim extends Model
|
||||
'status' => $model->status
|
||||
]);
|
||||
|
||||
if ($model->status == 'requested') {
|
||||
ClaimRequested::dispatch($model);
|
||||
}
|
||||
// if ($model->status == 'requested') {
|
||||
// ClaimRequested::dispatch($model);
|
||||
// }
|
||||
|
||||
if ($model->status == 'received') {
|
||||
ClaimReceived::dispatch($model);
|
||||
@@ -104,6 +108,20 @@ class Claim extends Model
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static function makeCode($next_number)
|
||||
{
|
||||
return (string) self::$code_prefix .'-'. str_pad($next_number, 5, 0, STR_PAD_LEFT);
|
||||
}
|
||||
|
||||
|
||||
public function files()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user