You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
578 B
26 lines
578 B
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\Application;
|
|
|
|
class ProjectCode
|
|
{
|
|
public static function forApplication(Application $application): string
|
|
{
|
|
$year = $application->created_at?->format('Y') ?? date('Y');
|
|
|
|
return sprintf('P%s-%04d', $year, (int) $application->id);
|
|
}
|
|
|
|
public static function resolve(Application $application): string
|
|
{
|
|
$stored = trim((string) ($application->project_code ?? ''));
|
|
if ($stored !== '') {
|
|
return $stored;
|
|
}
|
|
|
|
return self::forApplication($application);
|
|
}
|
|
}
|