2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-11-16 01:58:43 +01:00
|
|
|
use App\Casts\CalendarDateCast;
|
2026-06-14 21:32:07 +02:00
|
|
|
use App\Casts\CodeCast;
|
|
|
|
|
use App\Casts\MatriculeCast;
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- 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
2026-10-01 17:26:30 +02:00
|
|
|
use App\Casts\ShopperEstablishmentCodeCast;
|
|
|
|
|
use App\Casts\ShopperServiceCodeCast;
|
|
|
|
|
use App\Casts\ShopperSiteCodeCast;
|
2026-11-16 01:58:43 +01:00
|
|
|
use App\Casts\UtcDatetimeCast;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
2026-06-25 15:33:11 +02:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property string|null $customer_id
|
|
|
|
|
* @property \Domain\Models\ValueObjects\Matricule $matricule
|
|
|
|
|
* @property string $nom
|
|
|
|
|
* @property string $prenom
|
|
|
|
|
* @property \Illuminate\Support\Carbon|null $start_date
|
|
|
|
|
* @property \Illuminate\Support\Carbon|null $end_date
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- 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
2026-10-01 17:26:30 +02:00
|
|
|
* @property \Domain\Models\ValueObjects\ShopperEstablishmentCode $etablissement
|
|
|
|
|
* @property \Domain\Models\ValueObjects\ShopperSiteCode $site
|
|
|
|
|
* @property \Domain\Models\ValueObjects\ShopperServiceCode $service
|
2026-06-14 21:32:07 +02:00
|
|
|
* @property \Domain\Models\ValueObjects\Code $code
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- 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
2026-10-01 17:26:30 +02:00
|
|
|
* @property \Illuminate\Support\Carbon|null $last_sync
|
2026-06-14 21:32:07 +02:00
|
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
|
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
|
|
|
* @property-read \App\Models\Customer|null $customer
|
|
|
|
|
* @property-read mixed $full_name
|
|
|
|
|
* @property-read bool $is_active
|
|
|
|
|
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
|
|
|
|
|
*
|
2026-06-25 15:33:11 +02:00
|
|
|
* @method static Builder<static>|Employee active()
|
|
|
|
|
*
|
2026-06-14 21:32:07 +02:00
|
|
|
* @mixin \Eloquent
|
|
|
|
|
*/
|
|
|
|
|
#[Fillable([
|
|
|
|
|
'matricule',
|
|
|
|
|
'nom',
|
|
|
|
|
'prenom',
|
|
|
|
|
'code',
|
|
|
|
|
'start_date',
|
|
|
|
|
'end_date',
|
|
|
|
|
'etablissement',
|
|
|
|
|
'site',
|
|
|
|
|
'service',
|
|
|
|
|
])]
|
|
|
|
|
class Employee extends Model
|
|
|
|
|
{
|
|
|
|
|
use Notifiable;
|
|
|
|
|
|
2026-11-16 02:10:50 +01:00
|
|
|
private const string BUSINESS_TIMEZONE = 'Europe/Paris';
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
/** @return \Illuminate\Database\Eloquent\Casts\Attribute<string,never> */
|
|
|
|
|
protected function fullName(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(get: fn () => Str::title("{$this->nom} {$this->prenom}"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\Customer,$this> */
|
|
|
|
|
public function customer(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Customer::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- 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
2026-10-01 17:26:30 +02:00
|
|
|
'code' => CodeCast::class,
|
|
|
|
|
'matricule' => MatriculeCast::class,
|
2026-11-16 01:58:43 +01:00
|
|
|
'last_sync' => UtcDatetimeCast::class,
|
|
|
|
|
'start_date' => CalendarDateCast::class,
|
|
|
|
|
'end_date' => CalendarDateCast::class,
|
feat(employees): automated sync with Arcadia API, BO settings, Shopper value objects, and pagination migration
- 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
2026-10-01 17:26:30 +02:00
|
|
|
'etablissement' => ShopperEstablishmentCodeCast::class,
|
|
|
|
|
'site' => ShopperSiteCodeCast::class,
|
|
|
|
|
'service' => ShopperServiceCodeCast::class,
|
2026-06-14 21:32:07 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return \Illuminate\Database\Eloquent\Casts\Attribute<bool,never> */
|
|
|
|
|
protected function isActive(): Attribute
|
|
|
|
|
{
|
|
|
|
|
return Attribute::make(
|
2026-11-15 16:40:00 +01:00
|
|
|
get: function (): bool {
|
2026-11-16 02:10:50 +01:00
|
|
|
$today = Date::now(self::BUSINESS_TIMEZONE)->format('Y-m-d');
|
2026-11-15 16:40:00 +01:00
|
|
|
|
2026-11-16 02:10:50 +01:00
|
|
|
$hasStarted = $this->start_date === null || $this->start_date->format('Y-m-d') <= $today;
|
|
|
|
|
$hasNotEnded = $this->end_date === null || $this->end_date->format('Y-m-d') > $today;
|
2026-11-15 16:40:00 +01:00
|
|
|
|
|
|
|
|
return $hasStarted && $hasNotEnded;
|
|
|
|
|
}
|
2026-06-25 15:33:11 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Illuminate\Database\Eloquent\Builder<static> $query
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder<static>
|
|
|
|
|
*/
|
|
|
|
|
protected function scopeActive(Builder $query): Builder
|
|
|
|
|
{
|
2026-11-16 02:10:50 +01:00
|
|
|
$today = Date::now(self::BUSINESS_TIMEZONE)->format('Y-m-d');
|
2026-11-15 16:40:00 +01:00
|
|
|
|
|
|
|
|
return $query
|
|
|
|
|
->where(
|
|
|
|
|
fn (Builder $q): Builder => $q
|
2026-11-16 02:10:50 +01:00
|
|
|
->where('start_date', '<=', $today)
|
2026-11-15 16:40:00 +01:00
|
|
|
->orWhereNull('start_date')
|
|
|
|
|
)
|
|
|
|
|
->where(
|
|
|
|
|
fn (Builder $q): Builder => $q
|
2026-11-16 02:10:50 +01:00
|
|
|
->where('end_date', '>', $today)
|
2026-11-15 16:40:00 +01:00
|
|
|
->orWhereNull('end_date')
|
|
|
|
|
);
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function routeNotificationForMail(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->customer?->email->value ?? '';
|
|
|
|
|
}
|
|
|
|
|
}
|