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