2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Domain\Services;
|
|
|
|
|
|
|
|
|
|
use Domain\Models\Entities\Shop;
|
|
|
|
|
use Domain\Models\Entities\Shopper;
|
|
|
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
|
|
|
|
use Domain\Ports\Repositories\ShopperRepository;
|
|
|
|
|
use Domain\Ports\Repositories\ShopRepository;
|
|
|
|
|
|
|
|
|
|
class ShopperService
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly ShopRepository $shopRepository,
|
|
|
|
|
private readonly ShopperRepository $shopperRepository
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getShopperFor(ShopperId $shopperId): ?Shopper
|
|
|
|
|
{
|
|
|
|
|
return $this->shopperRepository->find($shopperId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve the shop assigned to a customer through their employee record.
|
|
|
|
|
*
|
|
|
|
|
* Resolution order:
|
|
|
|
|
* 1. Direct exception override (shop_employee_exception table)
|
|
|
|
|
* 2. Site + service mapping (shop_employees table, with service_code)
|
|
|
|
|
* 3. Site-only mapping (shop_employees table, service_code IS NULL)
|
|
|
|
|
* 4. Default shop (shops.default = true)
|
|
|
|
|
*/
|
|
|
|
|
public function getShopFor(ShopperId $shopperId): ?Shop
|
|
|
|
|
{
|
|
|
|
|
$shopper = $this->getShopperFor($shopperId);
|
|
|
|
|
|
2026-10-29 20:35:13 +01:00
|
|
|
return $shopper !== null ? $this->resolveShopForEmployee($shopper) : null;
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function resolveShopForEmployee(Shopper $shopper): Shop
|
|
|
|
|
{
|
|
|
|
|
// 1. Check for a direct exception override
|
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
|
|
|
$exceptionShop = $this->shopRepository
|
|
|
|
|
->findExceptionShopFor($shopper->matricule);
|
2026-06-14 21:32:07 +02:00
|
|
|
if ($exceptionShop !== null) {
|
|
|
|
|
return $exceptionShop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Try matching on site_code + service_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
|
|
|
$serviceShop = $this->shopRepository
|
|
|
|
|
->findShopForSiteAndService($shopper->site, $shopper->service);
|
2026-06-14 21:32:07 +02:00
|
|
|
if ($serviceShop !== null) {
|
|
|
|
|
return $serviceShop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. Fall back to site_code only (service_code IS NULL)
|
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
|
|
|
$siteShop = $this->shopRepository
|
|
|
|
|
->findShopForSiteAndService($shopper->site, null);
|
2026-06-14 21:32:07 +02:00
|
|
|
if ($siteShop !== null) {
|
|
|
|
|
return $siteShop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 4. Ultimate fallback: the default shop
|
|
|
|
|
return $this->shopRepository->getDefaultShop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function canCustomerPassOrdersApp(ShopperId $shopperId): bool
|
|
|
|
|
{
|
2026-10-29 20:35:13 +01:00
|
|
|
return $this->getShopperFor($shopperId)?->isActive() ?? false;
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
}
|