|
|
@@ -23,6 +23,7 @@ use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
|
|
|
use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Enum\Person\AddressPostalPersonTypeEnum;
|
|
|
use App\Repository\Core\CountryRepository;
|
|
|
+use App\Repository\Organization\OrganizationIdentificationRepository;
|
|
|
use App\Repository\Organization\OrganizationRepository;
|
|
|
use App\Repository\Person\PersonRepository;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
@@ -50,15 +51,16 @@ class OrganizationFactory
|
|
|
private LoggerInterface $logger;
|
|
|
|
|
|
public function __construct(
|
|
|
- private readonly SubdomainService $subdomainService,
|
|
|
- private readonly OrganizationRepository $organizationRepository,
|
|
|
- private readonly CountryRepository $countryRepository,
|
|
|
- private readonly OrganizationUtils $organizationUtils,
|
|
|
- private readonly Typo3Service $typo3Service,
|
|
|
- private readonly DolibarrApiService $dolibarrApiService,
|
|
|
- private readonly EntityManagerInterface $entityManager,
|
|
|
- private readonly PersonRepository $personRepository,
|
|
|
- private readonly BindFileService $bindFileService,
|
|
|
+ private readonly SubdomainService $subdomainService,
|
|
|
+ private readonly OrganizationRepository $organizationRepository,
|
|
|
+ private readonly CountryRepository $countryRepository,
|
|
|
+ private readonly OrganizationUtils $organizationUtils,
|
|
|
+ private readonly Typo3Service $typo3Service,
|
|
|
+ private readonly DolibarrApiService $dolibarrApiService,
|
|
|
+ private readonly EntityManagerInterface $entityManager,
|
|
|
+ private readonly PersonRepository $personRepository,
|
|
|
+ private readonly BindFileService $bindFileService,
|
|
|
+ private readonly OrganizationIdentificationRepository $organizationIdentificationRepository
|
|
|
) {}
|
|
|
|
|
|
#[Required]
|
|
|
@@ -86,9 +88,7 @@ class OrganizationFactory
|
|
|
|
|
|
try {
|
|
|
// On vérifie si cette organisation n'existe pas déjà
|
|
|
- if ($this->isExistingOrganization($organizationCreationRequest)) {
|
|
|
- throw new \RuntimeException('An organization named ' . $organizationCreationRequest->getName() . ' already exists');
|
|
|
- }
|
|
|
+ $this->interruptIfOrganizationExists($organizationCreationRequest);
|
|
|
|
|
|
// On vérifie la validité et la disponibilité du sous domaine
|
|
|
$this->validateSubdomain($organizationCreationRequest->getSubdomain());
|
|
|
@@ -163,20 +163,81 @@ class OrganizationFactory
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Une organisation du même nom existe-t-elle déjà à la même adresse ?
|
|
|
+ * Lève une exception si cette organisation existe déjà
|
|
|
*
|
|
|
* @param OrganizationCreationRequest $organizationCreationRequest
|
|
|
- * @return bool
|
|
|
*/
|
|
|
- protected function isExistingOrganization(OrganizationCreationRequest $organizationCreationRequest): bool
|
|
|
+ protected function interruptIfOrganizationExists(OrganizationCreationRequest $organizationCreationRequest): void
|
|
|
{
|
|
|
- return $this
|
|
|
- ->organizationRepository
|
|
|
- ->count(
|
|
|
+ if (
|
|
|
+ $organizationCreationRequest->getSiretNumber() &&
|
|
|
+ $this->organizationIdentificationRepository->findOneBy(
|
|
|
+ ['siretNumber' => $organizationCreationRequest->getSiretNumber()]
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ "This siret number is already registered : '" . $organizationCreationRequest->getSiretNumber()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ $organizationCreationRequest->getWaldecNumber() &&
|
|
|
+ $this->organizationIdentificationRepository->findOneBy(
|
|
|
+ ['waldecNumber' => $organizationCreationRequest->getWaldecNumber()]
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ "This RNA identifier (waldec number) is already registered : '" . $organizationCreationRequest->getWaldecNumber()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if (
|
|
|
+ $organizationCreationRequest->getIdentifier() &&
|
|
|
+ $this->organizationIdentificationRepository->findOneBy(
|
|
|
+ ['identifier' => $organizationCreationRequest->getIdentifier()]
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ "This CMF identifier is already registered : '" . $organizationCreationRequest->getIdentifier()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $normalizedName = preg_replace(
|
|
|
+ "/[^a-z0-9]+/",
|
|
|
+ "+",
|
|
|
+ strtolower($organizationCreationRequest->getName())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (
|
|
|
+ $this->organizationIdentificationRepository->findOneBy(
|
|
|
+ ['normalizedName' => $normalizedName, 'city' => $organizationCreationRequest->getCity()]
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ "An organization named '" . $organizationCreationRequest->getName() .
|
|
|
+ "' already exists in " . $organizationCreationRequest->getCity()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ $address = implode(' ', [
|
|
|
+ $organizationCreationRequest->getStreetAddress1(),
|
|
|
+ $organizationCreationRequest->getStreetAddress2(),
|
|
|
+ $organizationCreationRequest->getStreetAddress3()
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (
|
|
|
+ $this->organizationIdentificationRepository->findOneBy(
|
|
|
[
|
|
|
- 'name' => $organizationCreationRequest->getName(),
|
|
|
+ 'address' => $address,
|
|
|
+ 'city' => $organizationCreationRequest->getCity(),
|
|
|
+ 'postalCode' => $organizationCreationRequest->getPostalCode()
|
|
|
]
|
|
|
- ) > 0;
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ throw new \RuntimeException(
|
|
|
+ 'An organization already exists at this address.'
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|