- Implement automated synchronization of employees via Arcadia API (EmployeeSyncService, SynchronizeEmployeesWithArcadiaApi, FetchAndUpsertArcadiaEmployees) - Add Back-Office application settings for employee sites (Setting singleton, GetSettingsQuery, UpdateSettings, SettingsController, EmployeeSitesInputComponent.vue) - Strongly type Employee attributes using Domain Value Objects (ShopperEstablishmentCode, ShopperSiteCode, ShopperServiceCode) and Eloquent Casts - Migrate pagination from Domain to Shared\Pagination namespace across queries and inputs - Remove legacy and dead CSV employee import/export code - Restore Domain\Ports\Services\CsvGenerator interface for Regate order generation - Add comprehensive Pest unit, integration, and feature test coverage
78 lines
1.6 KiB
PHP
78 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property array<string>|null $employee_sites
|
|
* @property array<string>|null $arcadia_sites
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
*/
|
|
class Setting extends Model
|
|
{
|
|
public const int SINGLETON_ID = 1;
|
|
|
|
protected $fillable = [
|
|
'employee_sites',
|
|
];
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
#[\Override]
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'employee_sites' => 'array',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Backward-compatibility accessor
|
|
*
|
|
* @return array<string>|null
|
|
*/
|
|
public function getArcadiaSitesAttribute(): ?array
|
|
{
|
|
return $this->employee_sites;
|
|
}
|
|
|
|
/**
|
|
* Backward-compatibility mutator
|
|
*
|
|
* @param array<string>|null $value
|
|
*/
|
|
public function setArcadiaSitesAttribute(?array $value): void
|
|
{
|
|
$this->employee_sites = $value;
|
|
}
|
|
|
|
public static function getSingleton(): self
|
|
{
|
|
/** @var self $setting */
|
|
$setting = self::query()->firstOrCreate(['id' => self::SINGLETON_ID], [
|
|
'employee_sites' => [],
|
|
]);
|
|
|
|
return $setting;
|
|
}
|
|
|
|
/**
|
|
* @return array<int, ShopperSiteCode>
|
|
*/
|
|
public function getShopperSiteCodes(): array
|
|
{
|
|
$sites = $this->employee_sites ?? [];
|
|
|
|
return array_map(
|
|
static fn (string $site): ShopperSiteCode => new ShopperSiteCode($site),
|
|
$sites
|
|
);
|
|
}
|
|
}
|