37 lines
835 B
PHP
37 lines
835 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Services\InsForge\InsForgeTableService;
|
|
|
|
class DriverService extends InsForgeTableService
|
|
{
|
|
protected function table(): string
|
|
{
|
|
return 'drivers';
|
|
}
|
|
|
|
protected function searchableColumns(): array
|
|
{
|
|
return ['name', 'driver_code', 'phone'];
|
|
}
|
|
|
|
protected function sortableColumns(): array
|
|
{
|
|
return ['driver_code', 'name', 'created_at'];
|
|
}
|
|
|
|
public function nextCode(): string
|
|
{
|
|
$last = $this->client->listRecords($this->table(), [
|
|
'order' => 'driver_code.desc.nullslast',
|
|
'limit' => 1,
|
|
'select' => 'driver_code',
|
|
])[0]['driver_code'] ?? null;
|
|
|
|
preg_match('/(\d+)$/', (string) $last, $matches);
|
|
|
|
return sprintf('DRV-%04d', ((int) ($matches[1] ?? 0)) + 1);
|
|
}
|
|
}
|