diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ef695058c1..7a766390df 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -337,12 +337,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Accounting/Form/TransactionsImportType.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Call to an undefined method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\:\\:getCompanyName\\(\\)\\.$#', - 'identifier' => 'method.notFound', - 'count' => 2, - 'path' => __DIR__ . '/sources/AppBundle/Accounting/Invoices/Generator/CompanyMemberInvoiceGenerator.php', -]; $ignoreErrors[] = [ 'message' => '#^Binary operation "\\+" between mixed and 0\\|30\\|90\\|110\\|130\\|160\\|190 results in an error\\.$#', 'identifier' => 'binaryOp.invalid', @@ -715,216 +709,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Association/Form/UserType.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setFormattedRelatedAfupOffices\\(\\) has parameter \\$relatedAfupOffices with no value type specified in iterable type array\\.$#', - 'identifier' => 'missingType.iterableValue', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/CompanyMember.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$array of function implode expects array\\, list given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/CompanyMember.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'id\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 2, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'id_personne_morale\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'nb\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset \'raison_sociale\' on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access offset 0 on mixed\\.$#', - 'identifier' => 'offsetAccess.nonOffsetAccessible', - 'count' => 3, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot access property \\$nb on mixed\\.$#', - 'identifier' => 'property.nonObject', - 'count' => 3, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method bindValue\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 2, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method cols\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getBindValues\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getStatement\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 4, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method orderBy\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method where\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 4, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot cast mixed to int\\.$#', - 'identifier' => 'cast.int', - 'count' => 5, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:findById\\(\\) has parameter \\$id with no type specified\\.$#', - 'identifier' => 'missingType.parameter', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:findById\\(\\) should return AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|null but returns mixed\\.$#', - 'identifier' => 'return.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:findDisplayableCompanies\\(\\) return type has no value type specified in iterable type array\\.$#', - 'identifier' => 'missingType.iterableValue', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:getHydratorForCompanyMember\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:getQueryBuilderWithCompleteCompanyMember\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:getQueryBuilderWithSubscriptions\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#', - 'identifier' => 'missingType.iterableValue', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:initMetadata\\(\\) should return M of CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata but returns CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\\\.$#', - 'identifier' => 'return.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:loadAll\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:search\\(\\) return type with generic interface CCMBenchmark\\\\Ting\\\\Repository\\\\CollectionInterface does not specify its types\\: T$#', - 'identifier' => 'missingType.generics', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\CompanyMemberRepository\\:\\:searchCompanyMemberSubscriptions\\(\\) has no return type specified\\.$#', - 'identifier' => 'missingType.return', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$databaseName of method CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\\\:\\:setDatabase\\(\\) expects string, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$hydrator of method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\\\:\\:getCollection\\(\\) expects CCMBenchmark\\\\Ting\\\\Repository\\\\HydratorInterface\\\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 4, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$params of method CCMBenchmark\\\\Ting\\\\Query\\\\Query\\:\\:setParams\\(\\) expects array, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$sql of method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\\\:\\:getPreparedQuery\\(\\) expects string, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$sql of method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\\\:\\:getQuery\\(\\) expects string, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 3, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(mixed\\)\\: bool\\)\\|null, Closure\\(AppBundle\\\\Association\\\\Model\\\\CompanyMember\\)\\: bool given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#3 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Unable to resolve the template type U in call to method CCMBenchmark\\\\Ting\\\\Repository\\\\Repository\\\\:\\:getCollection\\(\\)$#', - 'identifier' => 'argument.templateType', - 'count' => 5, - 'path' => __DIR__ . '/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php', -]; $ignoreErrors[] = [ 'message' => '#^Method AppBundle\\\\Association\\\\Model\\\\Repository\\\\SubscriptionRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#', 'identifier' => 'missingType.iterableValue', @@ -1741,12 +1525,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Command/TicketStatsNotificationCommand.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', - 'identifier' => 'foreach.nonIterable', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Command/UpdateCompanyMemberStateCommand.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$messages of method Symfony\\\\Component\\\\Console\\\\Output\\\\OutputInterface\\:\\:writeln\\(\\) expects iterable\\\\|string, string\\|false given\\.$#', 'identifier' => 'argument.type', @@ -2011,30 +1789,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/Journal/UploadAttachmentAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getCompanyName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getFirstName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getId\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 3, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getLastName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$datetime of method Symfony\\\\Polyfill\\\\Intl\\\\Icu\\\\IntlDateFormatter\\:\\:format\\(\\) expects DateTimeInterface\\|int\\|string, DateTime\\|null given\\.$#', 'identifier' => 'argument.type', @@ -2053,30 +1807,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/DownloadMembershipFeeInvoiceAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getCompanyName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getFirstName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getId\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getLastName\\(\\) on AppBundle\\\\Association\\\\Model\\\\CompanyMember\\|AppBundle\\\\Association\\\\Model\\\\User\\|null\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$entity of method AppBundle\\\\Doctrine\\\\EntityRepository\\\\:\\:save\\(\\) expects AppBundle\\\\MembershipFee\\\\Entity\\\\Cotisation, AppBundle\\\\MembershipFee\\\\Entity\\\\Cotisation\\|null given\\.$#', 'identifier' => 'argument.type', @@ -3649,36 +3379,12 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/ValueResolver/AdminEventSelectionValueResolver.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$callback of function usort expects callable\\(mixed, mixed\\)\\: int, Closure\\(AppBundle\\\\Association\\\\Model\\\\CompanyMember, AppBundle\\\\Association\\\\Model\\\\CompanyMember\\)\\: int\\<\\-1, 1\\> given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#', 'identifier' => 'foreach.nonIterable', 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getCompanyName\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getId\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Cannot call method getSlug\\(\\) on mixed\\.$#', - 'identifier' => 'method.nonObject', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Method AppBundle\\\\Controller\\\\Website\\\\Global\\\\HtmlSitemapAction\\:\\:buildPages\\(\\) return type has no value type specified in iterable type array\\.$#', 'identifier' => 'missingType.iterableValue', @@ -3757,54 +3463,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$careersPageUrl of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setCareersPageUrl\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$contactPageUrl of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setContactPageUrl\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$description of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setDescription\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$membershipReason of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setMembershipReason\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$publicProfileEnabled of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setPublicProfileEnabled\\(\\) expects bool, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$relatedAfupOffices of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setFormattedRelatedAfupOffices\\(\\) expects array, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$twitterHandle of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setTwitterHandle\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$websiteUrl of method AppBundle\\\\Association\\\\Model\\\\CompanyMember\\:\\:setWebsiteUrl\\(\\) expects string\\|null, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Binary operation "\\+" between int\\<0, max\\> and mixed results in an error\\.$#', 'identifier' => 'binaryOp.invalid', @@ -3853,24 +3511,6 @@ 'count' => 1, 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Member/MembersAction.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Argument of an invalid type array\\\\|null supplied for foreach, only iterables are supported\\.$#', - 'identifier' => 'foreach.nonIterable', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Membership/CompanyAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\|null given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Membership/CompanyAction.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$numberOfMembers of method AppBundle\\\\Association\\\\CompanyMembership\\\\SubscriptionManagement\\:\\:createInvoiceForInscription\\(\\) expects int, mixed given\\.$#', - 'identifier' => 'argument.type', - 'count' => 1, - 'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Membership/CompanyAction.php', -]; $ignoreErrors[] = [ 'message' => '#^Cannot access offset \'first\' on mixed\\.$#', 'identifier' => 'offsetAccess.nonOffsetAccessible', diff --git a/sources/AppBundle/Accounting/Invoices/Generator/CompanyMemberInvoiceGenerator.php b/sources/AppBundle/Accounting/Invoices/Generator/CompanyMemberInvoiceGenerator.php index 8dbab2c588..6f78947bd3 100644 --- a/sources/AppBundle/Accounting/Invoices/Generator/CompanyMemberInvoiceGenerator.php +++ b/sources/AppBundle/Accounting/Invoices/Generator/CompanyMemberInvoiceGenerator.php @@ -5,19 +5,23 @@ namespace AppBundle\Accounting\Invoices\Generator; use AppBundle\Accounting\Invoices\Dto\InvoiceData; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; class CompanyMemberInvoiceGenerator implements InvoiceGeneration { public function generate(User|CompanyMember $member): InvoiceData { + if (!$member instanceof CompanyMember) { + throw new \InvalidArgumentException('Expected a CompanyMember.'); + } + return new InvoiceData( - $member->getCompanyName(), - $member->getAddress(), - $member->getZipcode(), - $member->getCity(), - $member->getCompanyName(), + $member->companyName, + $member->address, + $member->zipCode, + $member->city, + $member->companyName, ); } diff --git a/sources/AppBundle/Accounting/Invoices/Generator/InvoiceGeneration.php b/sources/AppBundle/Accounting/Invoices/Generator/InvoiceGeneration.php index e9a0f0ca51..8b7967de56 100644 --- a/sources/AppBundle/Accounting/Invoices/Generator/InvoiceGeneration.php +++ b/sources/AppBundle/Accounting/Invoices/Generator/InvoiceGeneration.php @@ -5,7 +5,7 @@ namespace AppBundle\Accounting\Invoices\Generator; use AppBundle\Accounting\Invoices\Dto\InvoiceData; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; interface InvoiceGeneration diff --git a/sources/AppBundle/Accounting/Invoices/Generator/MemberInvoiceGenerator.php b/sources/AppBundle/Accounting/Invoices/Generator/MemberInvoiceGenerator.php index 82a4036990..3d9123bab1 100644 --- a/sources/AppBundle/Accounting/Invoices/Generator/MemberInvoiceGenerator.php +++ b/sources/AppBundle/Accounting/Invoices/Generator/MemberInvoiceGenerator.php @@ -5,13 +5,17 @@ namespace AppBundle\Accounting\Invoices\Generator; use AppBundle\Accounting\Invoices\Dto\InvoiceData; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; class MemberInvoiceGenerator implements InvoiceGeneration { public function generate(User|CompanyMember $member): InvoiceData { + if (!$member instanceof User) { + throw new \InvalidArgumentException('Expected a User.'); + } + return new InvoiceData( $member->getFirstName() . ' ' . $member->getLastName(), $member->getAddress(), diff --git a/sources/AppBundle/Accounting/Invoices/InvoiceGenerator.php b/sources/AppBundle/Accounting/Invoices/InvoiceGenerator.php index d13d024de4..22e07a68a9 100644 --- a/sources/AppBundle/Accounting/Invoices/InvoiceGenerator.php +++ b/sources/AppBundle/Accounting/Invoices/InvoiceGenerator.php @@ -6,7 +6,7 @@ use AppBundle\Accounting\Invoices\Dto\InvoiceData; use AppBundle\Accounting\Invoices\Generator\InvoiceGeneration; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; class InvoiceGenerator @@ -26,7 +26,7 @@ public function getInvoiceData(User|CompanyMember $user): InvoiceData throw new \RuntimeException(sprintf( 'No invoice generator supports member of type %s (id: %d).', $user::class, - $user->getId(), + $user instanceof CompanyMember ? $user->id : $user->getId(), )); } } diff --git a/sources/AppBundle/Accounting/SearchResultProvider.php b/sources/AppBundle/Accounting/SearchResultProvider.php index 02360f2f2e..d92edd5329 100644 --- a/sources/AppBundle/Accounting/SearchResultProvider.php +++ b/sources/AppBundle/Accounting/SearchResultProvider.php @@ -4,7 +4,7 @@ namespace AppBundle\Accounting; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\SubscriptionRepository; use AppBundle\Event\Model\Repository\InvoiceRepository; use AppBundle\Event\Model\Repository\TicketRepository; diff --git a/sources/AppBundle/Association/CompanyMembership/InvitationMail.php b/sources/AppBundle/Association/CompanyMembership/InvitationMail.php index aca4a60b98..dc76fab268 100644 --- a/sources/AppBundle/Association/CompanyMembership/InvitationMail.php +++ b/sources/AppBundle/Association/CompanyMembership/InvitationMail.php @@ -4,7 +4,7 @@ namespace AppBundle\Association\CompanyMembership; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Entity\CompanyMemberInvitation; use AppBundle\Email\Mailer\Mailer; use AppBundle\Email\Mailer\MailUser; @@ -32,8 +32,8 @@ public function sendInvitation(CompanyMember $companyMember, CompanyMemberInvita { $text = $this->translator->trans('mail.invitationMembership.text', [ - '%firstname%' => $companyMember->getFirstName(), - '%lastname%' => $companyMember->getLastName(), + '%firstname%' => $companyMember->firstName, + '%lastname%' => $companyMember->lastName, '%link%' => $this->router->generate( 'company_invitation', ['invitationId' => $invitation->id, 'token' => $invitation->token], @@ -43,7 +43,7 @@ public function sendInvitation(CompanyMember $companyMember, CompanyMemberInvita ); return $this->mailer->sendTransactional(new Message( - sprintf('%s vous invite à profiter de son compte "Membre AFUP"', $companyMember->getCompanyName()), + sprintf('%s vous invite à profiter de son compte "Membre AFUP"', $companyMember->companyName), MailUserFactory::sponsors(), new MailUser($invitation->email), ), $text); diff --git a/sources/AppBundle/Association/CompanyMembership/SubscriptionManagement.php b/sources/AppBundle/Association/CompanyMembership/SubscriptionManagement.php index c2d006564d..cd9dbe9876 100644 --- a/sources/AppBundle/Association/CompanyMembership/SubscriptionManagement.php +++ b/sources/AppBundle/Association/CompanyMembership/SubscriptionManagement.php @@ -7,7 +7,7 @@ use AppBundle\MembershipFee\MembershipFeeService; use Afup\Site\Utils\Utils; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\MembershipFee\Entity\Cotisation; final readonly class SubscriptionManagement @@ -20,12 +20,15 @@ public function __construct(private MembershipFeeService $membershipFeeService) public function createInvoiceForInscription(CompanyMember $company, int $numberOfMembers): array { + if (!isset($company->id)) { + throw new \LogicException('The company member must be persisted.'); + } $endSubscription = $this->membershipFeeService->getNextSubscriptionExpiration(null); // Create the invoice $this->membershipFeeService->ajouter( MemberType::MemberCompany, - $company->getId(), + $company->id, ceil($numberOfMembers / self::AFUP_PERSONNE_MORALE_SEUIL) * self::AFUP_COTISATION_PERSONNE_MORALE * (1 + Utils::MEMBERSHIP_FEE_VAT_RATE), null, null, @@ -33,7 +36,7 @@ public function createInvoiceForInscription(CompanyMember $company, int $numberO $endSubscription->getTimestamp(), '', ); - $subscription = $this->membershipFeeService->getLatestByUserTypeAndId(MemberType::MemberCompany, $company->getId()); + $subscription = $this->membershipFeeService->getLatestByUserTypeAndId(MemberType::MemberCompany, $company->id); if (!$subscription instanceof Cotisation) { throw new \RuntimeException('An error occured'); diff --git a/sources/AppBundle/Association/Entity/CompanyMember.php b/sources/AppBundle/Association/Entity/CompanyMember.php new file mode 100644 index 0000000000..d34a4ceb3a --- /dev/null +++ b/sources/AppBundle/Association/Entity/CompanyMember.php @@ -0,0 +1,196 @@ + true])] + public int $id; + + #[Assert\NotBlank] + #[ORM\Column(name: 'prenom', length: 40)] + public string $firstName = ''; + + #[Assert\NotBlank] + #[ORM\Column(name: 'nom', length: 40)] + public string $lastName = ''; + + #[Assert\NotBlank] + #[Assert\Email] + #[ORM\Column(length: 100)] + public string $email = ''; + + #[Assert\NotBlank(message: 'Raison sociale manquante')] + #[ORM\Column(name: 'raison_sociale', length: 100)] + public string $companyName = ''; + + #[Assert\NotBlank] + #[ORM\Column(length: 14)] + public string $siret = ''; + + #[Assert\NotBlank] + #[ORM\Column(name: 'adresse', type: 'text')] + public string $address = ''; + + #[Assert\NotBlank] + #[ORM\Column(name: 'code_postal', length: 10)] + public string $zipCode = ''; + + #[Assert\NotBlank] + #[ORM\Column(name: 'ville', length: 50)] + public string $city = ''; + + #[Assert\NotBlank] + #[ORM\Column(name: 'id_pays', length: 2, options: ['fixed' => true])] + public string $country = 'FR'; + + #[ORM\Column(name: 'telephone_fixe', length: 20, nullable: true)] + public ?string $phone = null; + + #[ORM\Column(name: 'telephone_portable', length: 20, nullable: true)] + public ?string $cellphone = null; + + #[ORM\Column(name: 'etat', type: 'smallint', enumType: PersonneMoraleEtat::class)] + public PersonneMoraleEtat $status = PersonneMoraleEtat::Active; + + #[ORM\Column(name: 'max_members', type: 'smallint', nullable: true, options: ['unsigned' => true])] + public ?int $maxMembers = 0; + + // Colonne nullable en base (tinyint DEFAULT 0) + #[ORM\Column(name: 'public_profile_enabled', nullable: true)] + public ?bool $publicProfileEnabled = false; + + #[ORM\Column(type: 'text', nullable: true)] + public ?string $description = null; + + #[ORM\Column(name: 'logo_url', nullable: true)] + public ?string $logoUrl = null; + + #[ORM\Column(name: 'website_url', nullable: true)] + public ?string $websiteUrl = null; + + #[ORM\Column(name: 'contact_page_url', nullable: true)] + public ?string $contactPageUrl = null; + + #[ORM\Column(name: 'careers_page_url', nullable: true)] + public ?string $careersPageUrl = null; + + #[ORM\Column(name: 'twitter_handle', nullable: true)] + public ?string $twitterHandle = null; + + #[ORM\Column(name: 'related_afup_offices', nullable: true)] + public ?string $relatedAfupOffices = null; + + #[ORM\Column(name: 'membership_reason', nullable: true)] + public ?string $membershipReason = null; + + /** + * Non persisté : invitations saisies dans le formulaire d'adhésion entreprise. + * + * @var array + */ + public array $invitations = []; + + /** + * Non persisté : date de fin de la dernière cotisation, renseignée par + * CompanyMemberRepository (findById, loadAll, search, findDisplayableCompanies). + */ + public ?\DateTimeImmutable $lastSubscription = null; + + /** + * Invitations réellement saisies, en conservant leur position dans le formulaire + * (l'index 0 correspond toujours au gestionnaire). + * + * @return array + */ + public function getValidInvitations(): array + { + return array_filter( + $this->invitations, + static fn($invitation): bool => $invitation instanceof CompanyMemberInvitation, + ); + } + + public function hasLogoUrl(): bool + { + return null !== $this->logoUrl; + } + + public function getCleanedTwitterHandle(): ?string + { + $twitter = (string) $this->twitterHandle; + $twitter = trim($twitter, '@'); + $twitter = preg_replace('!^https?://twitter.com/!', '', $twitter); + + if (!is_string($twitter)) { + return null; + } + + if (trim($twitter) === '') { + return null; + } + + return $twitter; + } + + /** + * @return list + */ + public function getFormattedRelatedAfupOffices(): array + { + if (null === $this->relatedAfupOffices) { + return []; + } + + return explode(',', $this->relatedAfupOffices); + } + + /** + * @param array $relatedAfupOffices + */ + public function setFormattedRelatedAfupOffices(array $relatedAfupOffices): void + { + if ($relatedAfupOffices === []) { + $this->relatedAfupOffices = null; + + return; + } + + sort($relatedAfupOffices); + $this->relatedAfupOffices = implode(',', $relatedAfupOffices); + } + + public function getSlug(): string + { + return new Slugify()->slugify($this->companyName); + } + + public function hasUpToDateMembershipFee(?\DateTimeInterface $now = null): bool + { + if (!$now instanceof \DateTimeInterface) { + $now = new \DateTime(); + } + + return $this->lastSubscription > $now; + } + + public function getMembershipFee(int $default = SubscriptionManagement::AFUP_PERSONNE_MORALE_SEUIL): float + { + $max = max((int) $this->maxMembers, $default); + + return ceil($max / SubscriptionManagement::AFUP_PERSONNE_MORALE_SEUIL) * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE; + } +} diff --git a/sources/AppBundle/Association/Entity/Repository/CompanyMemberRepository.php b/sources/AppBundle/Association/Entity/Repository/CompanyMemberRepository.php new file mode 100644 index 0000000000..ec216f18fc --- /dev/null +++ b/sources/AppBundle/Association/Entity/Repository/CompanyMemberRepository.php @@ -0,0 +1,244 @@ + + */ +final class CompanyMemberRepository extends EntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, CompanyMember::class); + } + + /** + * @return list + */ + public function findDisplayableCompanies(): array + { + $rows = $this->createQueryBuilderWithLastSubscription() + ->where('c.publicProfileEnabled = :enabled') + ->setParameter('enabled', true) + ->getQuery() + ->getResult(); + + return array_values(array_filter( + $this->hydrateLastSubscription($rows), + static fn(CompanyMember $companyMember): bool => $companyMember->hasUpToDateMembershipFee(), + )); + } + + /** + * Contrairement à find(), renseigne la date de fin de dernière cotisation (lastSubscription). + */ + public function findWithLastSubscription(int $id): ?CompanyMember + { + $rows = $this->createQueryBuilderWithLastSubscription() + ->where('c.id = :id') + ->setParameter('id', $id) + ->getQuery() + ->getResult(); + + return $this->hydrateLastSubscription($rows)[0] ?? null; + } + + /** + * @return list + */ + public function loadAll(): array + { + return $this->hydrateLastSubscription( + $this->createQueryBuilderWithLastSubscription()->getQuery()->getResult(), + ); + } + + /** + * @return list + */ + public function search(string $sort = 'name', string $direction = 'asc', ?string $filter = null, bool $onlyDisplayActive = true): array + { + if (!in_array($direction, ['asc', 'desc'], true)) { + throw new InvalidArgumentException(sprintf('Invalid sort direction "%s".', $direction)); + } + $sorts = [ + 'name' => ['c.companyName'], + 'status' => ['c.status', 'c.companyName'], + ]; + if (!array_key_exists($sort, $sorts)) { + throw new InvalidArgumentException(sprintf('Invalid sort "%s".', $sort)); + } + + $queryBuilder = $this->createQueryBuilderWithLastSubscription(); + foreach ($sorts[$sort] as $field) { + $queryBuilder->addOrderBy($field, $direction); + } + + // On filtre sur tous les mots possibles. Donc plus on a de mots dans la recherche plus on aura de résultats. + // Mais ça peut aussi permettre de trouver des personnes en entrant par exemple "Prénom email" dans le champ de recherche : + // Même si l'email ne colle pas on pourra trouver la personne. + // C'est un peu barbare mais généralement on ne met qu'un seul terme dans la recherche… du coup c'est pas bien grave. + if ($filter) { + $filters = array_filter(array_map(trim(...), explode(' ', $filter))); + $ors = $queryBuilder->expr()->orX(); + foreach (array_values($filters) as $i => $value) { + $ors->add("LOWER(c.companyName) LIKE LOWER(:filter$i) OR c.city LIKE :filter$i"); + $queryBuilder->setParameter('filter' . $i, '%' . $value . '%'); + } + if ($ors->count() > 0) { + $queryBuilder->andWhere($ors); + } + } + + if ($onlyDisplayActive) { + $queryBuilder->andWhere('c.status = :status') + ->setParameter('status', PersonneMoraleEtat::Active); + } + + return $this->hydrateLastSubscription($queryBuilder->getQuery()->getResult()); + } + + /** + * Nombre de personnes physiques rattachées à chaque personne morale. + * + * @return array + */ + public function countActiveByCompany(): array + { + $rows = $this->getEntityManager()->getConnection()->createQueryBuilder() + ->select('id_personne_morale', 'COUNT(id) AS nb') + ->from('afup_personnes_physiques') + ->groupBy('id_personne_morale') + ->executeQuery() + ->fetchAllAssociative(); + + $result = []; + foreach ($rows as $row) { + if (!is_numeric($row['id_personne_morale']) || !is_numeric($row['nb'])) { + throw new \UnexpectedValueException('Unexpected non-numeric value.'); + } + $result[(int) $row['id_personne_morale']] = (int) $row['nb']; + } + + return $result; + } + + public function remove(CompanyMember $companyMember): void + { + $nbCotisations = $this->getEntityManager()->getRepository(Cotisation::class)->count([ + 'typePersonne' => MemberType::MemberCompany, + 'idPersonne' => $companyMember->id, + ]); + if (0 < $nbCotisations) { + throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des cotisations'); + } + + $nbUsers = $this->getEntityManager()->getConnection()->createQueryBuilder() + ->select('COUNT(*)') + ->from('afup_personnes_physiques') + ->where('id_personne_morale = :id') + ->setParameter('id', $companyMember->id) + ->executeQuery() + ->fetchOne(); + if (!is_numeric($nbUsers)) { + throw new \UnexpectedValueException('Unexpected non-numeric value.'); + } + if (0 < (int) $nbUsers) { + throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des membres'); + } + + $this->delete($companyMember); + } + + /** @return array */ + public function getList(): array + { + $result = []; + foreach ($this->findBy([], ['companyName' => 'ASC']) as $companyMember) { + $result[$companyMember->id] = sprintf('%s (id : %d)', $companyMember->companyName, $companyMember->id); + } + + return $result; + } + + public function countByStatus(PersonneMoraleEtat $status): int + { + return (int) $this->createQueryBuilder('c') + ->select('COUNT(c.id)') + ->where('c.status = :status') + ->setParameter('status', $status) + ->getQuery() + ->getSingleScalarResult(); + } + + /** + * @return list> + */ + public function searchCompanyMemberSubscriptions(string $search): array + { + $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder(); + + return $queryBuilder + ->select('pers.nom', 'pers.prenom', 'pers.email', 'pers.raison_sociale', 'cotis.*') + ->from('afup_personnes_morales', 'pers') + ->leftJoin('pers', 'afup_cotisations', 'cotis', 'pers.id = cotis.id_personne') + ->where('cotis.type_personne = :memberType') + ->andWhere($queryBuilder->expr()->or( + 'cotis.informations_reglement LIKE :like', + 'cotis.numero_facture LIKE :like', + 'cotis.commentaires LIKE :like', + 'pers.email LIKE :like', + 'pers.nom LIKE :like', + 'pers.prenom LIKE :like', + )) + ->setParameter('memberType', MemberType::MemberCompany->value) + ->setParameter('like', '%' . $search . '%') + ->executeQuery() + ->fetchAllAssociative(); + } + + private function createQueryBuilderWithLastSubscription(): QueryBuilder + { + return $this->createQueryBuilder('c') + ->select('c', 'MAX(f.dateFin) AS lastSubscription') + ->leftJoin(Cotisation::class, 'f', 'WITH', 'f.typePersonne = :memberType AND f.idPersonne = c.id') + ->setParameter('memberType', MemberType::MemberCompany) + ->groupBy('c.id'); + } + + /** + * Les lignes sont de la forme [0 => CompanyMember, 'lastSubscription' => timestamp Unix|null]. + * + * @param list $rows + * + * @return list + */ + private function hydrateLastSubscription(array $rows): array + { + $companies = []; + foreach ($rows as $row) { + $company = $row[0]; + $lastSubscription = $row['lastSubscription']; + if (null !== $lastSubscription && !is_numeric($lastSubscription)) { + throw new \UnexpectedValueException('Unexpected non-numeric value.'); + } + $company->lastSubscription = $lastSubscription !== null + ? new \DateTimeImmutable('@' . (int) $lastSubscription) + : null; + $companies[] = $company; + } + + return $companies; + } +} diff --git a/sources/AppBundle/Association/Enum/PersonneMoraleEtat.php b/sources/AppBundle/Association/Enum/PersonneMoraleEtat.php new file mode 100644 index 0000000000..7bd7e41a98 --- /dev/null +++ b/sources/AppBundle/Association/Enum/PersonneMoraleEtat.php @@ -0,0 +1,12 @@ +add('companyName', TextType::class, ['label' => 'Company']) - ->add('firstName', TextType::class, ['label' => 'Firstname']) - ->add('lastName', TextType::class, ['label' => 'Lastname']) - ->add('email', EmailType::class) - ->add('siret', TextType::class) - ->add('address', TextareaType::class) - ->add('zipcode', TextType::class, ['label' => 'Zip code']) - ->add('city', TextType::class) + ->add('companyName', TextType::class, ['label' => 'Company', 'empty_data' => '']) + ->add('firstName', TextType::class, ['label' => 'Firstname', 'empty_data' => '']) + ->add('lastName', TextType::class, ['label' => 'Lastname', 'empty_data' => '']) + ->add('email', EmailType::class, ['empty_data' => '']) + ->add('siret', TextType::class, ['empty_data' => '']) + ->add('address', TextareaType::class, ['empty_data' => '']) + ->add('zipcode', TextType::class, ['label' => 'Zip code', 'property_path' => 'zipCode', 'empty_data' => '']) + ->add('city', TextType::class, ['empty_data' => '']) ->add('phone', TextType::class) ->add('save', SubmitType::class, ['label' => 'saveMembership']) ; diff --git a/sources/AppBundle/Association/Form/CompanyEditType.php b/sources/AppBundle/Association/Form/CompanyEditType.php index cf59e30972..51280f5316 100644 --- a/sources/AppBundle/Association/Form/CompanyEditType.php +++ b/sources/AppBundle/Association/Form/CompanyEditType.php @@ -5,7 +5,8 @@ namespace AppBundle\Association\Form; use Afup\Site\Utils\Pays; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Enum\PersonneMoraleEtat; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -25,6 +26,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('companyName', TextType::class, [ 'label' => 'Raison sociale', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 40, @@ -33,6 +35,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('siret', TextType::class, [ 'label' => 'SIRET', 'required' => false, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 40, @@ -41,6 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('address', TextareaType::class, [ 'label' => 'Adresse', 'required' => true, + 'empty_data' => '', 'attr' => [ 'cols' => 42, 'rows' => 10, @@ -49,6 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('zipCode', TextType::class, [ 'label' => 'Code postal', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 6, 'maxlength' => 10, @@ -57,6 +62,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('city', TextType::class, [ 'label' => 'Ville', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 50, @@ -70,6 +76,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('lastName', TextType::class, [ 'label' => 'Nom', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 40, @@ -78,6 +85,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('firstName', TextType::class, [ 'label' => 'Prénom', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 40, @@ -86,6 +94,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('email', EmailType::class, [ 'label' => 'Email', 'required' => true, + 'empty_data' => '', 'attr' => [ 'size' => 30, 'maxlength' => 100, @@ -110,9 +119,9 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->add('status', ChoiceType::class, [ 'label' => 'État', 'choices' => [ - 'Non finalisé' => CompanyMember::STATUS_PENDING, - 'Actif' => CompanyMember::STATUS_ACTIVE, - 'Inactif' => CompanyMember::STATUS_INACTIVE, + 'Non finalisé' => PersonneMoraleEtat::EnAttente, + 'Actif' => PersonneMoraleEtat::Active, + 'Inactif' => PersonneMoraleEtat::Inactive, ], ]) ->add('maxMembers', ChoiceType::class, [ diff --git a/sources/AppBundle/Association/Form/CompanyMemberType.php b/sources/AppBundle/Association/Form/CompanyMemberType.php index 473ee616a7..1406482ced 100644 --- a/sources/AppBundle/Association/Form/CompanyMemberType.php +++ b/sources/AppBundle/Association/Form/CompanyMemberType.php @@ -6,7 +6,7 @@ use AppBundle\Association\CompanyMembership\SubscriptionManagement; use AppBundle\Association\Entity\CompanyMemberInvitation; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType; use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaIsValid; use Symfony\Component\Form\AbstractType; @@ -36,41 +36,49 @@ public function buildForm(FormBuilderInterface $builder, array $options): void $builder ->add('companyName', TextType::class, [ + 'empty_data' => '', 'label' => 'Company', 'constraints' => [ new Length(max: 100), ], ]) ->add('firstName', TextType::class, [ + 'empty_data' => '', 'label' => 'Firstname', 'constraints' => [ new Length(max: 40), ], ]) ->add('lastName', TextType::class, [ + 'empty_data' => '', 'label' => 'Lastname', 'constraints' => [ new Length(max: 40), ], ]) ->add('email', EmailType::class, [ + 'empty_data' => '', 'constraints' => [ new Length(max: 100), ], ]) ->add('siret', TextType::class, [ + 'empty_data' => '', 'constraints' => [ new Length(max: 14), ], ]) - ->add('address', TextareaType::class) + ->add('address', TextareaType::class, ['empty_data' => '']) ->add('zipcode', TextType::class, [ + 'property_path' => 'zipCode', + 'empty_data' => '', 'label' => 'Zip code', 'constraints' => [ new Length(max: 10), ], ]) ->add('city', TextType::class, [ + 'empty_data' => '', 'constraints' => [ new Length(max: 50), ], @@ -92,7 +100,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'entry_type' => CompanyMemberInvitationType::class, 'allow_add' => true, 'required' => false, - // Déclaré ici et non sur le modèle : CompanyMember::$invitations n'a pas + // Déclaré ici et non sur l'entité : CompanyMember::$invitations n'a pas // d'Assert\Valid, la validation ne cascade donc pas vers les invitations. 'constraints' => [ new Callback(static function (?array $invitations, ExecutionContextInterface $context): void { diff --git a/sources/AppBundle/Association/Form/UserEditType.php b/sources/AppBundle/Association/Form/UserEditType.php index a02d469288..368f57f308 100644 --- a/sources/AppBundle/Association/Form/UserEditType.php +++ b/sources/AppBundle/Association/Form/UserEditType.php @@ -6,7 +6,7 @@ use Afup\Site\Utils\Pays; use AppBundle\Association\Genre; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\User; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\CallbackTransformer; diff --git a/sources/AppBundle/Association/Model/CompanyMember.php b/sources/AppBundle/Association/Model/CompanyMember.php deleted file mode 100644 index f47328d5e8..0000000000 --- a/sources/AppBundle/Association/Model/CompanyMember.php +++ /dev/null @@ -1,686 +0,0 @@ -id; - } - - /** - * @param int $id - */ - public function setId($id): self - { - $this->id = $id; - return $this; - } - - /** - * @return string - */ - public function getFirstName() - { - return $this->firstName; - } - - /** - * @param string $firstName - */ - public function setFirstName($firstName): self - { - $this->propertyChanged('firstName', $this->firstName, $firstName); - $this->firstName = $firstName; - return $this; - } - - /** - * @return string - */ - public function getLastName() - { - return $this->lastName; - } - - /** - * @param string $lastName - */ - public function setLastName($lastName): self - { - $this->propertyChanged('lastName', $this->lastName, $lastName); - $this->lastName = $lastName; - return $this; - } - - /** - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * @param string $email - */ - public function setEmail($email): self - { - $this->propertyChanged('email', $this->email, $email); - $this->email = $email; - return $this; - } - - /** - * @return string - */ - public function getCompanyName() - { - return $this->companyName; - } - - /** - * @param string $companyName - */ - public function setCompanyName($companyName): self - { - $this->propertyChanged('companyName', $this->companyName, $companyName); - $this->companyName = $companyName; - return $this; - } - - /** - * @return string - */ - public function getSiret() - { - return $this->siret; - } - - /** - * @param string $siret - */ - public function setSiret($siret): self - { - $this->propertyChanged('siret', $this->siret, $siret); - $this->siret = $siret; - return $this; - } - - /** - * @return string - */ - public function getAddress() - { - return $this->address; - } - - /** - * @param string $address - */ - public function setAddress($address): self - { - $this->propertyChanged('address', $this->address, $address); - $this->address = $address; - return $this; - } - - /** - * @return string - */ - public function getZipCode() - { - return $this->zipCode; - } - - /** - * @param string $zipCode - */ - public function setZipCode($zipCode): self - { - $this->propertyChanged('zipCode', $this->zipCode, $zipCode); - $this->zipCode = $zipCode; - return $this; - } - - /** - * @return string - */ - public function getCity() - { - return $this->city; - } - - /** - * @param string $city - */ - public function setCity($city): self - { - $this->propertyChanged('city', $this->city, $city); - $this->city = $city; - return $this; - } - - /** - * @return string - */ - public function getCountry() - { - return $this->country; - } - - /** - * @param string $country - */ - public function setCountry($country): self - { - $this->propertyChanged('country', $this->country, $country); - $this->country = $country; - return $this; - } - - /** - * @return string - */ - public function getPhone() - { - return $this->phone; - } - - /** - * @param string $phone - */ - public function setPhone($phone): self - { - $this->propertyChanged('phone', $this->phone, $phone); - $this->phone = $phone; - return $this; - } - - /** - * @return int - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param int $status - */ - public function setStatus($status): self - { - $this->propertyChanged('status', $this->status, $status); - $this->status = $status; - return $this; - } - - /** - * @return CompanyMemberInvitation[] - */ - public function getInvitations(): ?array - { - return $this->invitations; - } - - /** - * @param array $invitations - */ - public function setInvitations(array $invitations): self - { - $this->invitations = array_filter($invitations, static fn($invitation): bool => $invitation instanceof CompanyMemberInvitation); - - return $this; - } - - /** - * @return int - */ - public function getMaxMembers() - { - return $this->maxMembers; - } - - /** - * @param int $maxMembers - */ - public function setMaxMembers($maxMembers): self - { - $this->propertyChanged('maxMembers', $this->maxMembers, $maxMembers); - $this->maxMembers = $maxMembers; - return $this; - } - - public function getPublicProfileEnabled(): bool - { - return (bool) $this->publicProfileEnabled; - } - - /** - * @param bool $publicProfileEnabled - */ - public function setPublicProfileEnabled($publicProfileEnabled): self - { - $this->propertyChanged('publicProfileEnabled', $this->publicProfileEnabled, $publicProfileEnabled); - $this->publicProfileEnabled = $publicProfileEnabled; - - return $this; - } - - /** - * @return string|null - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string|null $description - * - * @return $this - */ - public function setDescription($description = null): self - { - $this->propertyChanged('description', $this->description, $description); - $this->description = $description; - - return $this; - } - - public function hasLogoUrl(): bool - { - return null !== $this->getLogoUrl(); - } - - /** - * @return string|null - */ - public function getLogoUrl() - { - return $this->logoUrl; - } - - /** - * @param string|null $logoUrl - * - * @return $this - */ - public function setLogoUrl($logoUrl): self - { - $this->propertyChanged('logoUrl', $this->logoUrl, $logoUrl); - $this->logoUrl = $logoUrl; - - return $this; - } - - /** - * @return string|null - */ - public function getWebsiteUrl() - { - return $this->websiteUrl; - } - - /** - * @param string|null $websiteUrl - */ - public function setWebsiteUrl($websiteUrl): self - { - $this->propertyChanged('websiteUrl', $this->websiteUrl, $websiteUrl); - $this->websiteUrl = $websiteUrl; - - return $this; - } - - /** - * @return string|null - */ - public function getContactPageUrl() - { - return $this->contactPageUrl; - } - - /** - * @param string|null $contactPageUrl - * - * @return $this - */ - public function setContactPageUrl($contactPageUrl): self - { - $this->propertyChanged('contactPageUrl', $this->contactPageUrl, $contactPageUrl); - $this->contactPageUrl = $contactPageUrl; - - return $this; - } - - /** - * @return string|null - */ - public function getCareersPageUrl() - { - return $this->careersPageUrl; - } - - /** - * @param string|null $careersPageUrl - * - * @return $this - */ - public function setCareersPageUrl($careersPageUrl): self - { - $this->propertyChanged('careersPageUrl', $this->careersPageUrl, $careersPageUrl); - $this->careersPageUrl = $careersPageUrl; - - return $this; - } - - /** - * @return string|null - */ - public function getTwitterHandle() - { - return $this->twitterHandle; - } - - public function getCleanedTwitterHandle(): ?string - { - $twitter = (string) $this->getTwitterHandle(); - $twitter = trim($twitter, '@'); - $twitter = preg_replace('!^https?://twitter.com/!', '', $twitter); - - if (!is_string($twitter)) { - return null; - } - - if (trim($twitter) === '') { - return null; - } - - return $twitter; - } - - /** - * @param string|null $twitterHandle - * - * @return $this - */ - public function setTwitterHandle($twitterHandle): self - { - $this->propertyChanged('twitterHandle', $this->twitterHandle, $twitterHandle); - $this->twitterHandle = $twitterHandle; - - return $this; - } - - /** - * @return string|null - */ - public function getRelatedAfupOffices() - { - return $this->relatedAfupOffices; - } - - /** - * @param string|null $relatedAfupOffices - * - * @return $this - */ - public function setRelatedAfupOffices($relatedAfupOffices): self - { - $this->propertyChanged('relatedAfupOffices', $this->relatedAfupOffices, $relatedAfupOffices); - $this->relatedAfupOffices = $relatedAfupOffices; - - return $this; - } - - /** - * @return list - */ - public function getFormattedRelatedAfupOffices(): array - { - $relatedAfupOffices = $this->getRelatedAfupOffices(); - if (null === $relatedAfupOffices) { - return []; - } - - return explode(',', $relatedAfupOffices); - } - - /** - * @return $this - */ - public function setFormattedRelatedAfupOffices(array $relatedAfupOffices): self - { - if ($relatedAfupOffices !== []) { - sort($relatedAfupOffices); - - $this->setRelatedAfupOffices(implode(',', $relatedAfupOffices)); - } else { - $this->setRelatedAfupOffices(null); - } - - return $this; - } - - - /** - * @return string - */ - public function getSlug() - { - $slugify = new Slugify(); - return $slugify->slugify($this->getCompanyName()); - } - - public function getLastSubscription(): ?\DateTimeImmutable - { - return $this->lastSubscription; - } - - public function setLastSubscription(?string $sub): void - { - if ($sub !== null) { - $this->lastSubscription = new \DateTimeImmutable('@' . $sub); - } - } - - public function hasUpToDateMembershipFee(?\DateTimeInterface $now = null): bool - { - if (!$now instanceof \DateTimeInterface) { - $now = new \DateTime(); - } - return $this->getLastSubscription() > $now; - } - - /** - * @return string|null - */ - public function getMembershipReason() - { - return $this->membershipReason; - } - - /** - * @param string|null $membershipReason - * - * @return $this - */ - public function setMembershipReason($membershipReason): self - { - $this->propertyChanged('membershipReason', $this->membershipReason, $membershipReason); - $this->membershipReason = $membershipReason; - - return $this; - } - - /** @return string|null */ - public function getCellphone() - { - return $this->cellphone; - } - - /** @param string|null $cellphone */ - public function setCellphone($cellphone): void - { - $this->propertyChanged('cellphone', $this->cellphone, $cellphone); - $this->cellphone = $cellphone; - } - - public function getMembershipFee(int $default = SubscriptionManagement::AFUP_PERSONNE_MORALE_SEUIL): float - { - $max = max($this->getMaxMembers(), $default); - - return ceil($max / SubscriptionManagement::AFUP_PERSONNE_MORALE_SEUIL, - ) * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE; - } -} diff --git a/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php b/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php deleted file mode 100644 index c2aee8b390..0000000000 --- a/sources/AppBundle/Association/Model/Repository/CompanyMemberRepository.php +++ /dev/null @@ -1,350 +0,0 @@ - - */ -class CompanyMemberRepository extends Repository implements MetadataInitializer -{ - public function findDisplayableCompanies(): array - { - $queryBuilder = $this->getQueryBuilderWithCompleteCompanyMember(); - $queryBuilder->where('apm.public_profile_enabled = 1'); - - $companiesCollection = $this - ->getQuery($queryBuilder->getStatement()) - ->query($this->getCollection($this->getHydratorForCompanyMember())); - - $companies = iterator_to_array($companiesCollection->getIterator()); - - return array_filter( - $companies, - fn(CompanyMember $companyMember): bool => $companyMember->hasUpToDateMembershipFee(), - ); - } - - public function findById($id): ?CompanyMember - { - $queryBuilder = $this->getQueryBuilderWithCompleteCompanyMember(); - $queryBuilder->where('apm.id = :id'); - - return $this - ->getPreparedQuery($queryBuilder->getStatement()) - ->setParams(['id' => $id]) - ->query($this->getCollection($this->getHydratorForCompanyMember())) - ->first(); - } - - public function loadAll() - { - $queryBuilder = $this->getQueryBuilderWithCompleteCompanyMember(); - - return $this - ->getQuery($queryBuilder->getStatement()) - ->query($this->getCollection($this->getHydratorForCompanyMember())); - } - - /** - * @param string $sort - * @param string $direction - * @param string|null $filter - * @param bool $onlyDisplayActive - * - * @return CollectionInterface - */ - public function search($sort = 'name', $direction = 'asc', $filter = null, $onlyDisplayActive = true) - { - Assert::inArray($direction, ['asc', 'desc']); - $sorts = [ - 'name' => ['raison_sociale'], - 'status' => ['etat', 'raison_sociale'], - ]; - Assert::keyExists($sorts, $sort); - $queryBuilder = $this->getQueryBuilderWithCompleteCompanyMember() - ->orderBy(array_map(static fn($field): string => $field . ' ' . $direction, $sorts[$sort])); - - // On filtre sur tous les mots possibles. Donc plus on a de mots dans la recherche plus on aura de résultats. - // Mais ça peut aussi permettre de trouver des personnes en entrant par exemple "Prénom email" dans le champ de recherche : - // Même si l'email ne colle pas on pourra trouver la personne. - // C'est un peu barbare mais généralement on ne met qu'un seul terme dans la recherche… du coup c'est pas bien grave. - if ($filter) { - $filters = explode(' ', $filter); - $filters = array_filter(array_map(trim(...), $filters)); - $ors = []; - foreach ($filters as $i => $value) { - $ors[] = "LOWER(apm.raison_sociale) LIKE LOWER(:filter$i) OR apm.ville LIKE :filter$i"; - $queryBuilder->bindValue('filter' . $i, '%' . $value . '%'); - } - $queryBuilder->where('(' . implode(' OR ', $ors) . ')'); - } - if ($onlyDisplayActive) { - $queryBuilder->where('apm.etat = :status') - ->bindValue('status', CompanyMember::STATUS_ACTIVE); - } - - return $this - ->getQuery($queryBuilder->getStatement()) - ->setParams($queryBuilder->getBindValues()) - ->query($this->getCollection($this->getHydratorForCompanyMember())); - } - - /** - * @return array - */ - public function countActiveByCompany(): array - { - $result = []; - $query = $this->getQuery('SELECT id_personne_morale, COUNT(id) AS nb FROM afup_personnes_physiques GROUP BY id_personne_morale'); - foreach ($query->query($this->getCollection(new HydratorArray())) as $row) { - $result[(int) $row['id_personne_morale']] = (int) $row['nb']; - } - - return $result; - } - - public function remove(CompanyMember $companyMember): void - { - $nbCotisations = (int) $this->getQuery('SELECT COUNT(*) nb FROM afup_cotisations WHERE type_personne = :memberType AND id_personne = :id') - ->setParams(['memberType' => MemberType::MemberCompany->value, 'id' => $companyMember->getId()]) - ->query()->first()[0]->nb; - if (0 < $nbCotisations) { - throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des cotisations'); - } - $nbUsers = $this->getQuery('SELECT COUNT(*) nb FROM afup_personnes_physiques WHERE id_personne_morale = :id') - ->setParams(['id' => $companyMember->getId()]) - ->query()->first()[0]->nb; - if (0 < $nbUsers) { - throw new InvalidArgumentException('Impossible de supprimer une personne morale qui a des membres'); - } - - $this->delete($companyMember); - } - - /** @return array */ - public function getList(): array - { - $result = []; - $query = $this->getQuery('SELECT id, raison_sociale FROM afup_personnes_morales ORDER BY raison_sociale'); - foreach ($query->query($this->getCollection(new HydratorArray())) as $row) { - $result[(int) $row['id']] = sprintf('%s (id : %d)', $row['raison_sociale'], $row['id']); - } - - return $result; - } - - /** - * @param int $status - * - * @return int - */ - public function countByStatus($status) - { - return (int) $this->getQuery('SELECT COUNT(id) AS nb FROM afup_personnes_morales WHERE etat = :status') - ->setParams(['status' => $status]) - ->query($this->getCollection())->first()[0]->nb; - } - - private function getHydratorForCompanyMember() - { - return new HydratorSingleObject() - ->mapAliasTo('lastsubcription', 'apm', 'setLastSubscription'); - } - - private function getQueryBuilderWithCompleteCompanyMember() - { - return $this - ->getQueryBuilderWithSubscriptions() - ->cols([ - 'apm.*', - "MAX(ac.date_fin) AS lastsubcription", - ]); - } - - private function getQueryBuilderWithSubscriptions() - { - /** - * @var SelectInterface $queryBuilder - */ - $queryBuilder = $this->getQueryBuilder(self::QUERY_SELECT); - $queryBuilder - ->from('afup_personnes_morales apm') - ->join('LEFT', 'afup_cotisations ac', 'ac.type_personne = 1 AND ac.id_personne = apm.id') - ->groupBy(['apm.`id`']); - - return $queryBuilder; - } - - public function searchCompanyMemberSubscriptions(string $search) - { - $query = $this->getPreparedQuery( - 'SELECT pers.nom, pers.prenom, pers.email, pers.raison_sociale, cotis.* - FROM afup_personnes_morales AS pers - - LEFT JOIN afup_cotisations AS cotis - ON pers.id = cotis.id_personne - WHERE - cotis.type_personne = 1 - AND ( - cotis.informations_reglement LIKE :like - OR cotis.numero_facture LIKE :like - OR cotis.commentaires LIKE :like - OR pers.email LIKE :like - OR pers.nom LIKE :like - OR pers.prenom LIKE :like - )', - )->setParams(['like' => "%{$search}%"]); - return $query->query($this->getCollection(new HydratorArray())); - } - - /** - * @inheritDoc - */ - public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = []) - { - $metadata = new Metadata($serializerFactory); - - $metadata->setEntity(CompanyMember::class); - $metadata->setConnectionName('main'); - $metadata->setDatabase($options['database']); - $metadata->setTable('afup_personnes_morales'); - - $metadata - ->addField([ - 'columnName' => 'id', - 'fieldName' => 'id', - 'primary' => true, - 'autoincrement' => true, - 'type' => 'int', - ]) - ->addField([ - 'columnName' => 'prenom', - 'fieldName' => 'firstName', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'nom', - 'fieldName' => 'lastName', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'email', - 'fieldName' => 'email', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'raison_sociale', - 'fieldName' => 'companyName', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'siret', - 'fieldName' => 'siret', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'adresse', - 'fieldName' => 'address', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'code_postal', - 'fieldName' => 'zipCode', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'ville', - 'fieldName' => 'city', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'id_pays', - 'fieldName' => 'country', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'telephone_fixe', - 'fieldName' => 'phone', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'telephone_portable', - 'fieldName' => 'cellphone', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'etat', - 'fieldName' => 'status', - 'type' => 'int', - ]) - ->addField([ - 'columnName' => 'max_members', - 'fieldName' => 'maxMembers', - 'type' => 'int', - ]) - ->addField([ - 'columnName' => 'public_profile_enabled', - 'fieldName' => 'publicProfileEnabled', - 'type' => 'bool', - 'serializer' => Boolean::class, - ]) - ->addField([ - 'columnName' => 'description', - 'fieldName' => 'description', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'logo_url', - 'fieldName' => 'logoUrl', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'website_url', - 'fieldName' => 'websiteUrl', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'contact_page_url', - 'fieldName' => 'contactPageUrl', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'careers_page_url', - 'fieldName' => 'careersPageUrl', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'twitter_handle', - 'fieldName' => 'twitterHandle', - 'type' => 'string', - ]) - ->addField(([ - 'columnName' => 'related_afup_offices', - 'fieldName' => 'relatedAfupOffices', - 'type' => 'string', - ])) - ->addField(([ - 'columnName' => 'membership_reason', - 'fieldName' => 'membershipReason', - 'type' => 'string', - ])); - - return $metadata; - } -} diff --git a/sources/AppBundle/Association/Model/Repository/UserRepository.php b/sources/AppBundle/Association/Model/Repository/UserRepository.php index 5ef2b18821..ba924b2714 100644 --- a/sources/AppBundle/Association/Model/Repository/UserRepository.php +++ b/sources/AppBundle/Association/Model/Repository/UserRepository.php @@ -6,7 +6,7 @@ use AppBundle\Association\Genre; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; use AppBundle\Event\Entity\Badge; use Aura\SqlQuery\Common\SelectInterface; @@ -127,7 +127,7 @@ public function loadActiveUsersByCompany(CompanyMember $companyMember) return $this ->getPreparedQuery($queryBuilder->getStatement()) ->setParams([ - 'company' => $companyMember->getId(), + 'company' => $companyMember->id, 'state' => User::STATUS_ACTIVE, ]) ->query($this->getCollection($this->getHydratorForUser())) @@ -389,6 +389,8 @@ private function getQueryBuilderWithCompleteUser() 'app.`nearest_office`', 'app.`last_login`', 'MD5(CONCAT(app.`id`, \'_\', app.`email`, \'_\', app.`login`)) as hash', "MAX(ac.date_fin) AS lastsubcription", + 'apm.`raison_sociale` AS company_name', + 'apm.`max_members` AS company_max_members', ]); } @@ -411,7 +413,8 @@ private function getHydratorForUser() return new HydratorSingleObject() ->mapAliasTo('lastsubcription', 'app', 'setLastSubscription') ->mapAliasTo('hash', 'app', 'setHash') - ->mapObjectTo('apm', 'app', 'setCompany') + ->mapAliasTo('company_name', 'app', 'setCompanyName') + ->mapAliasTo('company_max_members', 'app', 'setCompanyMaxMembers') ; } diff --git a/sources/AppBundle/Association/Model/User.php b/sources/AppBundle/Association/Model/User.php index 3a63d62bfd..0944825e8f 100644 --- a/sources/AppBundle/Association/Model/User.php +++ b/sources/AppBundle/Association/Model/User.php @@ -135,7 +135,10 @@ class User implements NotifyPropertyInterface, NotifiableInterface, UserInterfac private ?\DateTimeImmutable $lastSubscription = null; - private ?CompanyMember $company = null; + // Renseignés par UserRepository depuis la jointure sur afup_personnes_morales + private ?string $companyName = null; + + private ?int $companyMaxMembers = null; private ?string $nearestOffice = null; @@ -527,17 +530,25 @@ public function getDaysBeforeMembershipExpiration(?\DateTimeInterface $now = nul return $this->lastSubscription?->diff($now)->days; } - /** - * @return CompanyMember - */ - public function getCompany(): ?CompanyMember + public function getCompanyName(): ?string + { + return $this->companyName; + } + + public function setCompanyName(?string $companyName): self + { + $this->companyName = $companyName; + return $this; + } + + public function getCompanyMaxMembers(): ?int { - return $this->company; + return $this->companyMaxMembers; } - public function setCompany(CompanyMember $company): self + public function setCompanyMaxMembers(int|string|null $companyMaxMembers): self { - $this->company = $company; + $this->companyMaxMembers = $companyMaxMembers !== null ? (int) $companyMaxMembers : null; return $this; } diff --git a/sources/AppBundle/Association/UserMembership/BadgesComputer.php b/sources/AppBundle/Association/UserMembership/BadgesComputer.php index a358641de3..c119310c3e 100644 --- a/sources/AppBundle/Association/UserMembership/BadgesComputer.php +++ b/sources/AppBundle/Association/UserMembership/BadgesComputer.php @@ -6,7 +6,7 @@ use AppBundle\AssembleeGenerale\Entity\Repository\PresenceRepository; use AppBundle\AssembleeGenerale\Enum\PresenceEtat; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; use AppBundle\Event\Model\Repository\EventRepository; use AppBundle\Event\Entity\Repository\UserBadgeRepository; diff --git a/sources/AppBundle/Association/UserMembership/SeniorityComputer.php b/sources/AppBundle/Association/UserMembership/SeniorityComputer.php index ef133ed5a5..99845f5bb0 100644 --- a/sources/AppBundle/Association/UserMembership/SeniorityComputer.php +++ b/sources/AppBundle/Association/UserMembership/SeniorityComputer.php @@ -5,7 +5,7 @@ namespace AppBundle\Association\UserMembership; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Model\User; use AppBundle\MembershipFee\Entity\Cotisation; use AppBundle\MembershipFee\Entity\Repository\CotisationRepository; @@ -21,7 +21,7 @@ public function __construct( /** @return array{years: int, first_year: int|null} */ public function computeCompanyAndReturnInfos(CompanyMember $companyMember): array { - $cotis = $this->membershipFeeRepository->getListByUserTypeAndId(MemberType::MemberCompany, $companyMember->getId()); + $cotis = $this->membershipFeeRepository->getListByUserTypeAndId(MemberType::MemberCompany, $companyMember->id); return $this->computeFromCotisationsAndReturnInfos($cotis); } diff --git a/sources/AppBundle/Association/UserMembership/StatisticsComputer.php b/sources/AppBundle/Association/UserMembership/StatisticsComputer.php index ffc57ab2b1..38fe45c3a4 100644 --- a/sources/AppBundle/Association/UserMembership/StatisticsComputer.php +++ b/sources/AppBundle/Association/UserMembership/StatisticsComputer.php @@ -4,8 +4,8 @@ namespace AppBundle\Association\UserMembership; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Enum\PersonneMoraleEtat; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; @@ -34,7 +34,7 @@ public function computeStatistics(): Statistics $statistics->usersCountWithoutCompanies++; } } - $statistics->companiesCount = $this->companyMemberRepository->countByStatus(CompanyMember::STATUS_ACTIVE); + $statistics->companiesCount = $this->companyMemberRepository->countByStatus(PersonneMoraleEtat::Active); return $statistics; } diff --git a/sources/AppBundle/Command/UpdateCompanyMemberStateCommand.php b/sources/AppBundle/Command/UpdateCompanyMemberStateCommand.php index 6919859b78..a0844f19d6 100644 --- a/sources/AppBundle/Command/UpdateCompanyMemberStateCommand.php +++ b/sources/AppBundle/Command/UpdateCompanyMemberStateCommand.php @@ -4,8 +4,8 @@ namespace AppBundle\Command; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Enum\PersonneMoraleEtat; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -26,10 +26,8 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - /** @var CompanyMember $companyMember */ foreach ($this->companyMemberRepository->loadAll() as $companyMember) { - $hasUptoDateMembershipFee = $companyMember->hasUpToDateMembershipFee(); - $companyMember->setStatus($hasUptoDateMembershipFee ? 1 : 0); + $companyMember->status = $companyMember->hasUpToDateMembershipFee() ? PersonneMoraleEtat::Active : PersonneMoraleEtat::Inactive; $this->companyMemberRepository->save($companyMember); } diff --git a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php index ac775bbca8..3580f033b9 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php @@ -4,8 +4,9 @@ namespace AppBundle\Controller\Admin\Accounting\MembershipFee; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\AuditLog\Audit; use AppBundle\MembershipFee\Entity\Cotisation; @@ -32,17 +33,21 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request { $membershipFee = new Cotisation(); $member = match ($memberType) { - MemberType::MemberCompany => $this->companyMemberRepository->get($memberId), + MemberType::MemberCompany => $this->companyMemberRepository->find($memberId), MemberType::MemberPhysical => $this->userRepository->get($memberId), }; - $startDate = $this->membershipFeeRepository->getMembershipStartingDate($memberType, $member->getId()); + if ($member === null) { + throw $this->createNotFoundException('Membre non trouvé'); + } + + $startDate = $this->membershipFeeRepository->getMembershipStartingDate($memberType, $memberId); $endDate = clone $startDate; $endDate->modify('+1 year'); $membershipFee->dateDebut = $startDate; $membershipFee->dateFin = $endDate; $membershipFee->typePersonne = $memberType; - $membershipFee->idPersonne = $member->getId(); + $membershipFee->idPersonne = $memberId; $membershipFee->token = base64_encode(random_bytes(30)); $membershipFee->dateFacture = $this->clock->now(); @@ -56,7 +61,7 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request ); $fmt->setPattern('dd MMMM yyyy'); - $name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : $member->getFirstName() . ' ' . $member->getLastName(); + $name = $member instanceof CompanyMember ? $member->companyName : $member->getFirstName() . ' ' . $member->getLastName(); try { $membershipFee->numeroFacture = $this->membershipFeeRepository->generateInvoiceNumber(); @@ -66,7 +71,7 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request } catch (\Exception) { $this->addFlash('error', 'Une erreur est survenue lors de l\'ajout de la cotisation jusqu\'au ' . $fmt->format($membershipFee->dateFin) . ' pour ' . $name); } - return $this->redirectToRoute('admin_membership_fee_list', ['memberType' => $memberType->value, 'memberId' => $member->getId()]); + return $this->redirectToRoute('admin_membership_fee_list', ['memberType' => $memberType->value, 'memberId' => $memberId]); } return $this->render('admin/accounting/membership/add.html.twig', [ diff --git a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php index 45fa7895ca..567f401d58 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/EditMembershipFeeAction.php @@ -4,8 +4,9 @@ namespace AppBundle\Controller\Admin\Accounting\MembershipFee; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\AuditLog\Audit; use AppBundle\MembershipFee\Entity\Repository\CotisationRepository; @@ -29,23 +30,27 @@ public function __invoke(MemberType $memberType, int $memberId, int $membershipF { $membershipFee = $this->membershipFeeRepository->find($membershipFeeId); $member = match ($memberType) { - MemberType::MemberCompany => $this->companyMemberRepository->get($memberId), + MemberType::MemberCompany => $this->companyMemberRepository->find($memberId), MemberType::MemberPhysical => $this->userRepository->get($memberId), }; + if ($member === null) { + throw $this->createNotFoundException('Membre non trouvé'); + } + $form = $this->createForm(MembershipFeeType::class, $membershipFee); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { try { $this->membershipFeeRepository->save($membershipFee); - $name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : ($member->getFirstName() . ' ' . $member->getLastName()); + $name = $member instanceof CompanyMember ? $member->companyName : ($member->getFirstName() . ' ' . $member->getLastName()); $this->audit->log('Modification de la cotisation ' . $membershipFeeId . ' pour ' . $name); $this->addFlash('notice', 'La cotisation pour ' . $name . ' a bien été modifiée'); } catch (\Exception) { $this->addFlash('error', 'Une erreur est survenue lors de la modification de la cotisation (' . $membershipFeeId . ') pour ' . $name); } - return $this->redirectToRoute('admin_membership_fee_list', ['memberType' => $memberType->value, 'memberId' => $member->getId()]); + return $this->redirectToRoute('admin_membership_fee_list', ['memberType' => $memberType->value, 'memberId' => $memberId]); } return $this->render('admin/accounting/membership/edit.html.twig', [ diff --git a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/ListMembershipFeeAction.php b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/ListMembershipFeeAction.php index 56ae8ae52d..83ad4c3d91 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/ListMembershipFeeAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/ListMembershipFeeAction.php @@ -5,7 +5,7 @@ namespace AppBundle\Controller\Admin\Accounting\MembershipFee; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\MembershipFee\Entity\Repository\CotisationRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -26,7 +26,7 @@ public function __construct( public function __invoke(#[CurrentUser] UserInterface $user, MemberType $memberType, int $memberId): Response { $member = match ($memberType) { - MemberType::MemberCompany => $this->companyMemberRepository->get($memberId), + MemberType::MemberCompany => $this->companyMemberRepository->find($memberId), MemberType::MemberPhysical => $this->userRepository->get($memberId), }; diff --git a/sources/AppBundle/Controller/Admin/Members/CompanyAction.php b/sources/AppBundle/Controller/Admin/Members/CompanyAction.php index c098bd16d9..c06bea1dd9 100644 --- a/sources/AppBundle/Controller/Admin/Members/CompanyAction.php +++ b/sources/AppBundle/Controller/Admin/Members/CompanyAction.php @@ -5,8 +5,8 @@ namespace AppBundle\Controller\Admin\Members; use AppBundle\Association\Form\CompanyEditType; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use Exception; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -26,7 +26,7 @@ public function __invoke(Request $request, ?int $id): Response { $company = new CompanyMember(); if ($id) { - $company = $this->companyMemberRepository->get($id); + $company = $this->companyMemberRepository->find($id); if ($company === null) { $this->addFlash('error', 'Personne morale non trouvée'); return $this->redirectToRoute('admin_members_company_list'); @@ -39,7 +39,7 @@ public function __invoke(Request $request, ?int $id): Response $this->companyMemberRepository->save($company); $this->addFlash('notice', 'La personne morale a été ' . ($id ? 'modifiée' : 'ajoutée')); - return $this->redirectToRoute('admin_members_company_list', ['filter' => $company->getCompanyName()]); + return $this->redirectToRoute('admin_members_company_list', ['filter' => $company->companyName]); } catch (Exception) { $this->addFlash('error', 'Une erreur est survenue lors de l\'ajout de la personne morale'); } @@ -47,7 +47,7 @@ public function __invoke(Request $request, ?int $id): Response return $this->render('admin/members/company/' . ($id ? 'edit' : 'add') . '.html.twig', [ 'form' => $form->createView(), - 'users' => $this->userRepository->search('lastname', 'asc', null, $company->getId(), onlyActive: false), + 'users' => $this->userRepository->search('lastname', 'asc', null, $company->id ?? null, onlyActive: false), 'company' => $company, ]); } diff --git a/sources/AppBundle/Controller/Admin/Members/CompanyDeleteAction.php b/sources/AppBundle/Controller/Admin/Members/CompanyDeleteAction.php index 972ce932a7..ec86fad0d9 100644 --- a/sources/AppBundle/Controller/Admin/Members/CompanyDeleteAction.php +++ b/sources/AppBundle/Controller/Admin/Members/CompanyDeleteAction.php @@ -4,7 +4,7 @@ namespace AppBundle\Controller\Admin\Members; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\AuditLog\Audit; use Exception; use InvalidArgumentException; @@ -23,13 +23,13 @@ public function __construct( public function __invoke(Request $request): RedirectResponse { - $companyMember = $this->companyMemberRepository->get($request->query->get('id')); + $companyMember = $this->companyMemberRepository->find($request->query->getInt('id')); if (null === $companyMember) { throw $this->createNotFoundException('Personne morale non trouvée'); } try { $this->companyMemberRepository->remove($companyMember); - $this->audit->log('Suppression de la personne morale ' . $companyMember->getId()); + $this->audit->log('Suppression de la personne morale ' . $companyMember->id); $this->addFlash('notice', 'La personne morale a été supprimée'); } catch (InvalidArgumentException $e) { $this->addFlash('error', $e->getMessage()); diff --git a/sources/AppBundle/Controller/Admin/Members/CompanyListAction.php b/sources/AppBundle/Controller/Admin/Members/CompanyListAction.php index c729b273b6..8c2b2cb455 100644 --- a/sources/AppBundle/Controller/Admin/Members/CompanyListAction.php +++ b/sources/AppBundle/Controller/Admin/Members/CompanyListAction.php @@ -4,7 +4,7 @@ namespace AppBundle\Controller\Admin\Members; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; diff --git a/sources/AppBundle/Controller/Website/CompanyPublicProfile/CompanyPublicProfileController.php b/sources/AppBundle/Controller/Website/CompanyPublicProfile/CompanyPublicProfileController.php index d8c64656d7..71f46eb243 100644 --- a/sources/AppBundle/Controller/Website/CompanyPublicProfile/CompanyPublicProfileController.php +++ b/sources/AppBundle/Controller/Website/CompanyPublicProfile/CompanyPublicProfileController.php @@ -4,8 +4,8 @@ namespace AppBundle\Controller\Website\CompanyPublicProfile; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; abstract class CompanyPublicProfileController extends AbstractController @@ -14,11 +14,11 @@ public function __construct(private readonly CompanyMemberRepository $companyMem protected function checkAndGetCompanyMember(int $id, string $slug): CompanyMember { - $companyMember = $this->companyMemberRepository->findById($id); + $companyMember = $this->companyMemberRepository->findWithLastSubscription($id); if ($companyMember === null || $companyMember->getSlug() != $slug - || false === $companyMember->getPublicProfileEnabled() + || true !== $companyMember->publicProfileEnabled || false === $companyMember->hasUpToDateMembershipFee() ) { throw $this->createNotFoundException("Company member not found"); diff --git a/sources/AppBundle/Controller/Website/CompanyPublicProfile/IndexAction.php b/sources/AppBundle/Controller/Website/CompanyPublicProfile/IndexAction.php index 4c1b2202df..fcbda49017 100644 --- a/sources/AppBundle/Controller/Website/CompanyPublicProfile/IndexAction.php +++ b/sources/AppBundle/Controller/Website/CompanyPublicProfile/IndexAction.php @@ -6,8 +6,8 @@ use AppBundle\Antennes\Entity\Antenne; use AppBundle\Antennes\Entity\Repository\AntenneRepository; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\UserMembership\BadgesComputer; use AppBundle\Twig\ViewRenderer; use Symfony\Component\HttpFoundation\Response; diff --git a/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php b/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php index 6b3345e40e..48b12004fd 100644 --- a/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php +++ b/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php @@ -4,8 +4,8 @@ namespace AppBundle\Controller\Website\CompanyPublicProfile; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Twig\ViewRenderer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; @@ -22,8 +22,8 @@ public function __invoke(): Response $displayableCompanies = $this->companyMemberRepository->findDisplayableCompanies(); usort($displayableCompanies, function (CompanyMember $companyMemberA, CompanyMember $companyMemberB): int { - $a = $companyMemberA->getCompanyName(); - $b = $companyMemberB->getCompanyName(); + $a = $companyMemberA->companyName; + $b = $companyMemberB->companyName; return $a <=> $b; }); diff --git a/sources/AppBundle/Controller/Website/CompanyPublicProfile/LogoAction.php b/sources/AppBundle/Controller/Website/CompanyPublicProfile/LogoAction.php index eb8312c46d..a0d7d67c1b 100644 --- a/sources/AppBundle/Controller/Website/CompanyPublicProfile/LogoAction.php +++ b/sources/AppBundle/Controller/Website/CompanyPublicProfile/LogoAction.php @@ -4,7 +4,7 @@ namespace AppBundle\Controller\Website\CompanyPublicProfile; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\BinaryFileResponse; @@ -22,7 +22,7 @@ public function __invoke(int $id, string $slug): BinaryFileResponse { $companyMember = $this->checkAndGetCompanyMember($id, $slug); - $filepath = $this->storageDir . DIRECTORY_SEPARATOR . $companyMember->getLogoUrl(); + $filepath = $this->storageDir . DIRECTORY_SEPARATOR . $companyMember->logoUrl; if (false === is_file($filepath)) { throw $this->createNotFoundException(); diff --git a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php index b9a6ee722e..8d36c2f57b 100644 --- a/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php +++ b/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php @@ -5,7 +5,7 @@ namespace AppBundle\Controller\Website\Global; use Afup\Site\Corporate\Feuille; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Talk; use AppBundle\Site\Entity\Repository\ArticleRepository; @@ -60,12 +60,12 @@ private function members(): array $members = []; foreach ($displayableCompanies as $member) { $url = $this->generateUrl('company_public_profile', [ - 'id' => $member->getId(), + 'id' => $member->id, 'slug' => $member->getSlug(), ]); $members[] = [ - 'name' => $member->getCompanyName(), + 'name' => $member->companyName, 'url' => $url, ]; } diff --git a/sources/AppBundle/Controller/Website/Member/CompanyAction.php b/sources/AppBundle/Controller/Website/Member/CompanyAction.php index e39174cfc9..9917fc80de 100644 --- a/sources/AppBundle/Controller/Website/Member/CompanyAction.php +++ b/sources/AppBundle/Controller/Website/Member/CompanyAction.php @@ -5,8 +5,8 @@ namespace AppBundle\Controller\Website\Member; use AppBundle\Association\Form\AdminCompanyMemberType; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Security\Authentication; use AppBundle\Twig\ViewRenderer; use Exception; @@ -24,7 +24,7 @@ public function __construct( public function __invoke(Request $request): Response { - $company = $this->companyMemberRepository->get($this->authentication->getAfupUser()->getCompanyId()); + $company = $this->companyMemberRepository->find($this->authentication->getAfupUser()->getCompanyId()); if ($company === null) { throw $this->createNotFoundException('Company not found'); } diff --git a/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php b/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php index 3acdd80e77..0dbfc4005d 100644 --- a/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php +++ b/sources/AppBundle/Controller/Website/Member/CompanyPublicProfileAction.php @@ -5,13 +5,14 @@ namespace AppBundle\Controller\Website\Member; use AppBundle\Association\Form\CompanyPublicProfile; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Security\Authentication; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; final class CompanyPublicProfileAction extends AbstractController { @@ -24,21 +25,21 @@ public function __construct( public function __invoke(Request $request): Response { - $companyMember = $this->companyMemberRepository->get($this->authentication->getAfupUser()->getCompanyId()); + $companyMember = $this->companyMemberRepository->find($this->authentication->getAfupUser()->getCompanyId()); if ($companyMember === null) { throw $this->createNotFoundException("Company member not found"); } $defaultData = [ - 'enabled' => $companyMember->getPublicProfileEnabled(), - 'description' => $companyMember->getDescription(), - 'website_url' => $companyMember->getWebsiteUrl(), - 'contact_page_url' => $companyMember->getContactPageUrl(), - 'careers_page_url' => $companyMember->getCareersPageUrl(), - 'twitter_handle' => $companyMember->getTwitterHandle(), + 'enabled' => (bool) $companyMember->publicProfileEnabled, + 'description' => $companyMember->description, + 'website_url' => $companyMember->websiteUrl, + 'contact_page_url' => $companyMember->contactPageUrl, + 'careers_page_url' => $companyMember->careersPageUrl, + 'twitter_handle' => $companyMember->twitterHandle, 'related_afup_offices' => $companyMember->getFormattedRelatedAfupOffices(), - 'membership_reason' => $companyMember->getMembershipReason(), + 'membership_reason' => $companyMember->membershipReason, ]; $formOptions = [ @@ -55,26 +56,29 @@ public function __invoke(Request $request): Response $uploadedFile = $data['logo'] ?? null; if ($uploadedFile instanceof UploadedFile) { - $filename = $companyMember->getId() . '.' . $uploadedFile->getClientOriginalExtension(); + $filename = $companyMember->id . '.' . $uploadedFile->getClientOriginalExtension(); $uploadedFile->move( $this->prepareUploadedFilesDir(), $filename, ); - $companyMember->setLogoUrl($filename); + $companyMember->logoUrl = $filename; } - $companyMember - ->setPublicProfileEnabled($data['enabled']) - ->setDescription($data[('description')]) - ->setWebsiteUrl($data['website_url']) - ->setContactPageUrl($data['contact_page_url']) - ->setCareersPageUrl($data['careers_page_url']) - ->setTwitterHandle($data['twitter_handle']) - ->setFormattedRelatedAfupOffices($data['related_afup_offices']) - ->setMembershipReason($data['membership_reason']) - ; + $relatedAfupOffices = $data['related_afup_offices'] ?? []; + if (!is_array($relatedAfupOffices) || array_filter($relatedAfupOffices, is_string(...)) !== $relatedAfupOffices) { + throw new BadRequestHttpException('Invalid related AFUP offices.'); + } + + $companyMember->publicProfileEnabled = (bool) $data['enabled']; + $companyMember->description = $this->nullableString($data['description'] ?? null); + $companyMember->websiteUrl = $this->nullableString($data['website_url'] ?? null); + $companyMember->contactPageUrl = $this->nullableString($data['contact_page_url'] ?? null); + $companyMember->careersPageUrl = $this->nullableString($data['careers_page_url'] ?? null); + $companyMember->twitterHandle = $this->nullableString($data['twitter_handle'] ?? null); + $companyMember->setFormattedRelatedAfupOffices($relatedAfupOffices); + $companyMember->membershipReason = $this->nullableString($data['membership_reason'] ?? null); $this->companyMemberRepository->save($companyMember); @@ -91,6 +95,15 @@ public function __invoke(Request $request): Response ); } + private function nullableString(mixed $value): ?string + { + if (null !== $value && !is_string($value)) { + throw new BadRequestHttpException('Expected a string.'); + } + + return $value; + } + private function prepareUploadedFilesDir(): string { if (!is_dir($this->storageDir)) { diff --git a/sources/AppBundle/Controller/Website/Member/MembersAction.php b/sources/AppBundle/Controller/Website/Member/MembersAction.php index d2727fc7a7..3885e6b9a8 100644 --- a/sources/AppBundle/Controller/Website/Member/MembersAction.php +++ b/sources/AppBundle/Controller/Website/Member/MembersAction.php @@ -7,11 +7,11 @@ use AppBundle\Association\CompanyMembership\InvitationMail; use AppBundle\Association\CompanyMembership\UserCompany; use AppBundle\Association\Form\CompanyMemberInvitationType; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use AppBundle\Association\Entity\CompanyMemberInvitation; use AppBundle\Association\Entity\Repository\CompanyMemberInvitationRepository; use AppBundle\Association\Enum\InvitationEtat; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; use AppBundle\Model\CollectionFilter; @@ -45,24 +45,24 @@ public function __construct( public function __invoke(Request $request): Response { $id = $request->attributes->get('id'); - if ($id && $this->isGranted('ROLE_MEMBRES_WRITER')) { - $companyId = $id; + if (is_numeric($id) && (int) $id > 0 && $this->isGranted('ROLE_MEMBRES_WRITER')) { + $companyId = (int) $id; } else { $companyId = $this->authentication->getAfupUser()->getCompanyId(); } - $company = $this->companyMemberRepository->get($companyId); + $company = $this->companyMemberRepository->find($companyId); if ($company === null) { throw $this->createNotFoundException('Company not found'); } $users = $this->userRepository->loadActiveUsersByCompany($company); - $pendingInvitations = $this->companyMemberInvitationRepository->loadPendingInvitationsByCompany((int) $company->getId()); + $pendingInvitations = $this->companyMemberInvitationRepository->loadPendingInvitationsByCompany($company->id); $invitation = new CompanyMemberInvitation(); $invitationForm = $this->createForm(CompanyMemberInvitationType::class, $invitation); $invitationForm->handleRequest($request); - $canAddUser = count($pendingInvitations) + $users->count() < $company->getMaxMembers(); + $canAddUser = count($pendingInvitations) + $users->count() < $company->maxMembers; if ($request->isMethod(Request::METHOD_POST)) { if ($invitationForm->isSubmitted() && $invitationForm->isValid()) { if ($canAddUser) { @@ -107,7 +107,7 @@ private function addUser( ): void { // Check if there is already a pending invitation for this email and this company $matchingUser = $this->collectionFilter->findOne($users, 'getEmail', $invitation->email); - $matchingInvitation = $this->companyMemberInvitationRepository->findPendingByEmail((int) $company->getId(), $invitation->email); + $matchingInvitation = $this->companyMemberInvitationRepository->findPendingByEmail($company->id, $invitation->email); if ($matchingInvitation !== null || $matchingUser !== null) { $this->addFlash('error', 'Vous ne pouvez pas envoyer plusieurs invitations au même email.'); @@ -117,7 +117,7 @@ private function addUser( // Handle invitation $invitation->submittedOn = new DateTime(); - $invitation->companyId = (int) $company->getId(); + $invitation->companyId = $company->id; $invitation->token = base64_encode(random_bytes(30)); $invitation->status = InvitationEtat::EnAttente; $this->companyMemberInvitationRepository->save($invitation); @@ -130,7 +130,7 @@ private function addUser( private function removeInvitation(string $emailToDelete, CompanyMember $company): void { - $invitationToDelete = $this->companyMemberInvitationRepository->findPendingByEmail((int) $company->getId(), $emailToDelete); + $invitationToDelete = $this->companyMemberInvitationRepository->findPendingByEmail($company->id, $emailToDelete); if ($invitationToDelete !== null) { $invitationToDelete->status = InvitationEtat::Annulee; @@ -143,7 +143,7 @@ private function removeInvitation(string $emailToDelete, CompanyMember $company) private function resendInvitation(string $emailToSend, CompanyMember $company): void { - $invitationToSend = $this->companyMemberInvitationRepository->findPendingByEmail((int) $company->getId(), $emailToSend); + $invitationToSend = $this->companyMemberInvitationRepository->findPendingByEmail($company->id, $emailToSend); if ($invitationToSend !== null) { $this->invitationMail->sendInvitation($company, $invitationToSend); diff --git a/sources/AppBundle/Controller/Website/Membership/CompanyAction.php b/sources/AppBundle/Controller/Website/Membership/CompanyAction.php index f093ec4c7d..e9c45c81d9 100644 --- a/sources/AppBundle/Controller/Website/Membership/CompanyAction.php +++ b/sources/AppBundle/Controller/Website/Membership/CompanyAction.php @@ -10,8 +10,8 @@ use AppBundle\Association\Entity\Repository\CompanyMemberInvitationRepository; use AppBundle\Association\Enum\InvitationEtat; use AppBundle\Association\Form\CompanyMemberType; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Twig\ViewRenderer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -38,15 +38,15 @@ public function __invoke(Request $request): Response $defaultMembers = SubscriptionManagement::AFUP_PERSONNE_MORALE_SEUIL; $data = new CompanyMember(); - $data->setMaxMembers($defaultMembers); - $data->setInvitations(array_map( + $data->maxMembers = $defaultMembers; + $data->invitations = array_map( static function (int $index): CompanyMemberInvitation { $invitation = new CompanyMemberInvitation(); $invitation->manager = 0 === $index; return $invitation; }, range(0, $defaultMembers - 1), - )); + ); $subscribeForm = $this->createForm(CompanyMemberType::class, $data); $subscribeForm->handleRequest($request); @@ -58,12 +58,12 @@ static function (int $index): CompanyMemberInvitation { $member = $subscribeForm->getData(); $this->companyMemberRepository->save($member); - foreach ($member->getInvitations() as $index => $invitation) { + foreach ($member->getValidInvitations() as $index => $invitation) { if ($invitation->email === '') { continue; } $invitation->submittedOn = new \DateTime(); - $invitation->companyId = (int) $member->getId(); + $invitation->companyId = $member->id; $invitation->token = base64_encode(random_bytes(30)); $invitation->status = InvitationEtat::EnAttente; if ($index === 0) { @@ -80,7 +80,7 @@ static function (int $index): CompanyMemberInvitation { } $subscriptionManager = $this->subscriptionManagement; - $invoice = $subscriptionManager->createInvoiceForInscription($member, count($member->getInvitations())); + $invoice = $subscriptionManager->createInvoiceForInscription($member, count($member->getValidInvitations())); return $this->redirectToRoute('company_membership_payment', ['invoiceNumber' => $invoice['invoice'], 'token' => $invoice['token']]); } diff --git a/sources/AppBundle/Controller/Website/Membership/Fee/DownloadAction.php b/sources/AppBundle/Controller/Website/Membership/Fee/DownloadAction.php index 19a5c48713..b9265f10af 100644 --- a/sources/AppBundle/Controller/Website/Membership/Fee/DownloadAction.php +++ b/sources/AppBundle/Controller/Website/Membership/Fee/DownloadAction.php @@ -7,8 +7,8 @@ use AppBundle\MembershipFee\MembershipFeeInvoicePdfGenerator; use Afup\Site\Droits; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; use AppBundle\AuditLog\Audit; @@ -46,9 +46,9 @@ public function __invoke(Request $request): BinaryFileResponse $membershipFee = $this->membershipFeeRepository->find($id); if ($membershipFee->typePersonne === MemberType::MemberCompany) { - $company = $this->companyMemberRepository->get($membershipFee->idPersonne); + $company = $this->companyMemberRepository->find($membershipFee->idPersonne); Assert::isInstanceOf($company, CompanyMember::class); - $patternPrefix = $company->getCompanyName(); + $patternPrefix = $company->companyName; } else { $user = $this->userRepository->get($membershipFee->idPersonne); Assert::isInstanceOf($user, User::class); diff --git a/sources/AppBundle/Controller/Website/Membership/Fee/IndexAction.php b/sources/AppBundle/Controller/Website/Membership/Fee/IndexAction.php index bec2fd38c3..465d128fdc 100644 --- a/sources/AppBundle/Controller/Website/Membership/Fee/IndexAction.php +++ b/sources/AppBundle/Controller/Website/Membership/Fee/IndexAction.php @@ -12,7 +12,7 @@ use AppBundle\Security\MembershipFeeVoter; use AppBundle\Association\MembershipFeeReferenceGenerator; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\UserMembership\UserService; use AppBundle\MembershipFee\Entity\Cotisation; @@ -76,7 +76,7 @@ public function __invoke(): Response $type_personne = MemberType::MemberCompany; $prefixe = 'Personne morale'; - if (!$company = $this->companyMemberRepository->findById($id_personne)) { + if (!$company = $this->companyMemberRepository->findWithLastSubscription($id_personne)) { throw $this->createNotFoundException('La personne morale n\'existe pas'); } $montant = $company->getMembershipFee(); diff --git a/sources/AppBundle/Controller/Website/Membership/MemberInvitationAction.php b/sources/AppBundle/Controller/Website/Membership/MemberInvitationAction.php index 3e29fe63a0..20361b2449 100644 --- a/sources/AppBundle/Controller/Website/Membership/MemberInvitationAction.php +++ b/sources/AppBundle/Controller/Website/Membership/MemberInvitationAction.php @@ -8,7 +8,7 @@ use AppBundle\Association\Form\UserType; use AppBundle\Association\Entity\Repository\CompanyMemberInvitationRepository; use AppBundle\Association\Enum\InvitationEtat; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; use AppBundle\Twig\ViewRenderer; @@ -34,7 +34,7 @@ public function __invoke(Request $request, int $invitationId, string $token): Re $invitation = $this->companyMemberInvitationRepository->findOneBy(['id' => $invitationId, 'token' => $token, 'status' => InvitationEtat::EnAttente]); $company = null; if ($invitation) { - $company = $this->companyMemberRepository->get($invitation->companyId); + $company = $this->companyMemberRepository->find($invitation->companyId); } if ($invitation === null || $company === null) { @@ -53,7 +53,7 @@ public function __invoke(Request $request, int $invitationId, string $token): Re $user->setPassword($hash); $user ->setStatus(User::STATUS_ACTIVE) - ->setCompanyId($company->getId()) + ->setCompanyId($company->id) ; if ($invitation->manager) { diff --git a/sources/AppBundle/Controller/Website/Membership/PaymentAction.php b/sources/AppBundle/Controller/Website/Membership/PaymentAction.php index 7353aeb975..7664124bbd 100644 --- a/sources/AppBundle/Controller/Website/Membership/PaymentAction.php +++ b/sources/AppBundle/Controller/Website/Membership/PaymentAction.php @@ -6,7 +6,7 @@ use AppBundle\Afup; use AppBundle\MembershipFee\MembershipFeeService; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Compta\BankAccount\BankAccountFactory; use AppBundle\MembershipFee\Entity\Cotisation; use AppBundle\Payment\PayboxBilling; @@ -29,19 +29,19 @@ public function __invoke(string $invoiceNumber, ?string $token): Response $invoice = $this->membershipFeeService->getByInvoice($invoiceNumber, $token); $company = null; if ($invoice instanceof Cotisation) { - $company = $this->companyMemberRepository->get($invoice->idPersonne); + $company = $this->companyMemberRepository->find($invoice->idPersonne); } if (!$invoice || $company === null) { throw $this->createNotFoundException(sprintf('Could not find the invoice "%s" with token "%s"', $invoiceNumber, $token)); } - $payboxBilling = new PayboxBilling($company->getFirstName(), $company->getLastName(), $company->getAddress(), $company->getZipCode(), $company->getCity(), $company->getCountry()); + $payboxBilling = new PayboxBilling($company->firstName, $company->lastName, $company->address, $company->zipCode, $company->city, $company->country); $paybox = $this->payboxFactory->createPayboxForSubscription( 'F' . $invoiceNumber, (float) $invoice->montant, - $company->getEmail(), + $company->email, $payboxBilling, ); diff --git a/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php b/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php index e9447d3d02..9e15cf8d39 100644 --- a/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php +++ b/sources/AppBundle/Event/Validator/Constraints/CorporateMemberValidator.php @@ -5,7 +5,7 @@ namespace AppBundle\Event\Validator\Constraints; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\User; use AppBundle\Event\Model\Repository\TicketRepository; use AppBundle\Event\Model\Ticket; @@ -66,7 +66,7 @@ public function validate($tickets, Constraint $constraint): void return; } - $company = $this->companyMemberRepository->get($user->getCompanyId()); + $company = $this->companyMemberRepository->find($user->getCompanyId()); if ($company === null) { // Il faut etre connecté pour avoir accès aux tickets membre @@ -77,11 +77,11 @@ public function validate($tickets, Constraint $constraint): void $ticketsSoldToThisCompany = $this->ticketRepository->getTotalOfSoldTicketsByMember( MemberType::MemberCompany->value, - $company->getId(), + $company->id, $eventId, ); - if (($ticketsSoldToThisCompany + $restrictedTickets) > $company->getMaxMembers()) { + if (($ticketsSoldToThisCompany + $restrictedTickets) > $company->maxMembers) { $this->context->buildViolation($constraint->messageTooMuchRestrictedTickets) ->atPath('tickets') ->addViolation() diff --git a/sources/AppBundle/MembershipFee/MembershipFeeInvoicePdfGenerator.php b/sources/AppBundle/MembershipFee/MembershipFeeInvoicePdfGenerator.php index f7afeeeba4..e5e7e5b8df 100644 --- a/sources/AppBundle/MembershipFee/MembershipFeeInvoicePdfGenerator.php +++ b/sources/AppBundle/MembershipFee/MembershipFeeInvoicePdfGenerator.php @@ -9,8 +9,8 @@ use Afup\Site\Utils\Vat; use AppBundle\Accounting\Invoices\InvoiceGenerator; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Association\Model\User; use AppBundle\Compta\BankAccount\BankAccountFactory; @@ -37,13 +37,16 @@ public function genererFacture(int $idCotisation, ?string $chemin = null): ?stri { $cotisation = $this->membershipFeeRepository->find($idCotisation); - $userRepository = match ($cotisation->typePersonne) { - MemberType::MemberCompany => $this->companyMemberRepository, - default => $this->userRepository, - }; + $idPersonne = $cotisation->idPersonne; - /** @var User|CompanyMember $user */ - $user = $userRepository->get($cotisation->idPersonne); + /** @var User|CompanyMember|null $user */ + $user = match ($cotisation->typePersonne) { + MemberType::MemberCompany => $this->companyMemberRepository->find($idPersonne), + default => $this->userRepository->get($idPersonne), + }; + if (null === $user) { + throw new \LogicException(sprintf('Member %d not found.', $idPersonne)); + } $invoiceData = $this->invoiceGenerator->getInvoiceData($user); $dateFacture = $cotisation->dateFacture diff --git a/sources/AppBundle/MembershipFee/MembershipFeeMailer.php b/sources/AppBundle/MembershipFee/MembershipFeeMailer.php index f18553215d..0cb4e3db5c 100644 --- a/sources/AppBundle/MembershipFee/MembershipFeeMailer.php +++ b/sources/AppBundle/MembershipFee/MembershipFeeMailer.php @@ -6,7 +6,7 @@ use AppBundle\Afup; use AppBundle\Association\MemberType; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Association\Model\Repository\UserRepository; use AppBundle\Email\Mailer\Attachment; use AppBundle\Email\Mailer\Mailer; @@ -39,12 +39,12 @@ public function envoyerFacture(int $idCotisation): bool $membership = $this->membershipFeeRepository->find($idCotisation); if ($membership->typePersonne === MemberType::MemberCompany) { - $company = $this->companyMemberRepository->get($membership->idPersonne); + $company = $this->companyMemberRepository->find($membership->idPersonne); Assert::notNull($company); $contactPhysique = [ - 'nom' => $company->getLastName(), - 'prenom' => $company->getFirstName(), - 'email' => $company->getEmail(), + 'nom' => $company->lastName, + 'prenom' => $company->firstName, + 'email' => $company->email, ]; } else { $user = $this->userRepository->get($membership->idPersonne); @@ -71,7 +71,7 @@ public function envoyerFacture(int $idCotisation): bool $subject = 'Facture AFUP'; if ($membership->typePersonne === MemberType::MemberCompany) { - $subject .= ' - ' . $company->getCompanyName(); + $subject .= ' - ' . $company->companyName; } else { $subject .= ' - ' . $contactPhysique['nom'] . ' ' . $contactPhysique['prenom']; } @@ -114,10 +114,10 @@ public function notifierReglementEnLigneAuTresorier(string $cmd, float $total, s ]; if ($typePersonne == MemberType::MemberCompany->value) { - if ($company = $this->companyMemberRepository->get($idPersonne)) { - $infos['nom'] = $company->getLastName(); - $infos['prenom'] = $company->getFirstName(); - $infos['email'] = $company->getEmail(); + if (null !== $company = $this->companyMemberRepository->find((int) $idPersonne)) { + $infos['nom'] = $company->lastName; + $infos['prenom'] = $company->firstName; + $infos['email'] = $company->email; } } else { if ($user = $this->userRepository->get($idPersonne)) { diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php index 49bc304bc5..e4cbce4211 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -5,8 +5,7 @@ namespace AppBundle\Subscriber; use Afup\Site\Corporate\Feuille; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; use AppBundle\Controller\Website\News\ListAction; use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Repository\EventRepository; @@ -162,7 +161,6 @@ public function registerNewsUrls(UrlContainerInterface $urls): void private function registerMembers(UrlContainerInterface $urls): void { - /** @var CompanyMember[] $members */ $members = $this->companyMemberRepository->findDisplayableCompanies(); foreach ($members as $member) { @@ -171,7 +169,7 @@ private function registerMembers(UrlContainerInterface $urls): void $this->urlGenerator->generate( 'company_public_profile', [ - 'id' => $member->getId(), + 'id' => $member->id, 'slug' => $member->getSlug(), ], UrlGeneratorInterface::ABSOLUTE_URL, diff --git a/templates/admin/accounting/search.html.twig b/templates/admin/accounting/search.html.twig index d862b66a90..ac0cc5b6be 100644 --- a/templates/admin/accounting/search.html.twig +++ b/templates/admin/accounting/search.html.twig @@ -35,7 +35,7 @@

Aucun résultat

{% else %} - {% if results.companyMembers.count > 0 %} + {% if results.companyMembers|length > 0 %}

Cotisations de personnes morales

diff --git a/templates/admin/members/company_list.html.twig b/templates/admin/members/company_list.html.twig index 9fc4567133..d0832772d2 100644 --- a/templates/admin/members/company_list.html.twig +++ b/templates/admin/members/company_list.html.twig @@ -56,9 +56,9 @@ {% for company in companies %} - {# @var company \AppBundle\Association\Model\CompanyMember #} - {% set isActive = company.status == constant('AppBundle\\Association\\Model\\CompanyMember::STATUS_ACTIVE') %} - {% set isPending = company.status == constant('AppBundle\\Association\\Model\\CompanyMember::STATUS_PENDING') %} + {# @var company \AppBundle\Association\Entity\CompanyMember #} + {% set isActive = company.status == constant('AppBundle\\Association\\Enum\\PersonneMoraleEtat::Active') %} + {% set isPending = company.status == constant('AppBundle\\Association\\Enum\\PersonneMoraleEtat::EnAttente') %} {{ company.companyName }} diff --git a/templates/event/ticket/ticket.html.twig b/templates/event/ticket/ticket.html.twig index fbd8c88be9..9be161071c 100644 --- a/templates/event/ticket/ticket.html.twig +++ b/templates/event/ticket/ticket.html.twig @@ -70,7 +70,7 @@
{% if app.user %} {% if app.user.companyId > 0 %} -

{{ 'Vous êtes connecté avec le compte AFUP de l\'entreprise %company%. Votre cotisation est valable pour %maxMembers% salarié·e·s. Vous pouvez donc acheter %maxMembers% tickets au tarif AFUP pour cet évènement - pour qui vous voulez !'|trans({ '%maxMembers%': app.user.company.maxMembers, '%company%': app.user.company.companyName}) }}

+

{{ 'Vous êtes connecté avec le compte AFUP de l\'entreprise %company%. Votre cotisation est valable pour %maxMembers% salarié·e·s. Vous pouvez donc acheter %maxMembers% tickets au tarif AFUP pour cet évènement - pour qui vous voulez !'|trans({ '%maxMembers%': app.user.companyMaxMembers, '%company%': app.user.companyName}) }}

{{ 'Vous avez déjà acheté %soldTickets% ticket(s) au tarif AFUP pour cet évènement.'|trans({'%soldTickets%': soldTicketsForMember}) }}

{% else %}

{{ 'Vous êtes connecté avec un compte AFUP personnel. Vous pouvez acheter une place au tarif membre pour vous seul. Pour être valable, cette place doit être enregistrée avec l\'adresse %mail%.'|trans({'%mail%': app.user.email}) }}

diff --git a/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberInvitationRepositoryTest.php b/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberInvitationRepositoryTest.php index 65fa4e926b..982077a30e 100644 --- a/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberInvitationRepositoryTest.php +++ b/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberInvitationRepositoryTest.php @@ -8,8 +8,8 @@ use AppBundle\Association\Entity\CompanyMemberInvitation; use AppBundle\Association\Entity\Repository\CompanyMemberInvitationRepository; use AppBundle\Association\Enum\InvitationEtat; -use AppBundle\Association\Model\CompanyMember; -use AppBundle\Association\Model\Repository\CompanyMemberRepository; +use AppBundle\Association\Entity\CompanyMember; +use AppBundle\Association\Entity\Repository\CompanyMemberRepository; final class CompanyMemberInvitationRepositoryTest extends IntegrationTestCase { @@ -21,12 +21,12 @@ public function testLoadPendingInvitationsByCompanyReturnsOnlyPendingOfTheCompan $company = $this->createCompany($companyMemberRepository, 'societe-a@example.com'); $otherCompany = $this->createCompany($companyMemberRepository, 'societe-b@example.com'); - $this->persistInvitation($repository, $company->getId(), 'en-attente@example.com', InvitationEtat::EnAttente); - $this->persistInvitation($repository, $company->getId(), 'annulee@example.com', InvitationEtat::Annulee); - $this->persistInvitation($repository, $company->getId(), 'acceptee@example.com', InvitationEtat::Acceptee); - $this->persistInvitation($repository, $otherCompany->getId(), 'autre-societe@example.com', InvitationEtat::EnAttente); + $this->persistInvitation($repository, $company->id, 'en-attente@example.com', InvitationEtat::EnAttente); + $this->persistInvitation($repository, $company->id, 'annulee@example.com', InvitationEtat::Annulee); + $this->persistInvitation($repository, $company->id, 'acceptee@example.com', InvitationEtat::Acceptee); + $this->persistInvitation($repository, $otherCompany->id, 'autre-societe@example.com', InvitationEtat::EnAttente); - $invitations = $repository->loadPendingInvitationsByCompany((int) $company->getId()); + $invitations = $repository->loadPendingInvitationsByCompany($company->id); self::assertCount(1, $invitations); self::assertSame('en-attente@example.com', $invitations[0]->email); @@ -40,13 +40,13 @@ public function testLoadPendingInvitationsByCompanySortsBySubmissionDate(): void $company = $this->createCompany($companyMemberRepository, 'tri@example.com'); - $ancienne = $this->persistInvitation($repository, $company->getId(), 'ancienne@example.com', InvitationEtat::EnAttente); + $ancienne = $this->persistInvitation($repository, $company->id, 'ancienne@example.com', InvitationEtat::EnAttente); $ancienne->submittedOn = new \DateTime('-2 days'); $repository->save($ancienne); - $recente = $this->persistInvitation($repository, $company->getId(), 'recente@example.com', InvitationEtat::EnAttente); + $recente = $this->persistInvitation($repository, $company->id, 'recente@example.com', InvitationEtat::EnAttente); - $invitations = $repository->loadPendingInvitationsByCompany((int) $company->getId()); + $invitations = $repository->loadPendingInvitationsByCompany($company->id); self::assertSame(['ancienne@example.com', 'recente@example.com'], array_map( static fn(CompanyMemberInvitation $invitation): string => $invitation->email, @@ -63,16 +63,16 @@ public function testFindPendingByEmailReturnsPendingInvitationOfTheCompany(): vo $company = $this->createCompany($companyMemberRepository, 'recherche@example.com'); $otherCompany = $this->createCompany($companyMemberRepository, 'recherche-autre@example.com'); - $this->persistInvitation($repository, $company->getId(), 'invite@example.com', InvitationEtat::EnAttente); + $this->persistInvitation($repository, $company->id, 'invite@example.com', InvitationEtat::EnAttente); - $invitation = $repository->findPendingByEmail((int) $company->getId(), 'invite@example.com'); + $invitation = $repository->findPendingByEmail($company->id, 'invite@example.com'); self::assertNotNull($invitation); self::assertSame('invite@example.com', $invitation->email); - self::assertSame((int) $company->getId(), $invitation->companyId); + self::assertSame($company->id, $invitation->companyId); // Le même email chez une autre société ne doit rien retourner. - self::assertNull($repository->findPendingByEmail((int) $otherCompany->getId(), 'invite@example.com')); + self::assertNull($repository->findPendingByEmail($otherCompany->id, 'invite@example.com')); } public function testFindPendingByEmailIgnoresCancelledInvitation(): void @@ -82,11 +82,11 @@ public function testFindPendingByEmailIgnoresCancelledInvitation(): void $company = $this->createCompany($companyMemberRepository, 'annulation@example.com'); - $invitation = $this->persistInvitation($repository, $company->getId(), 'annulee@example.com', InvitationEtat::EnAttente); + $invitation = $this->persistInvitation($repository, $company->id, 'annulee@example.com', InvitationEtat::EnAttente); $invitation->status = InvitationEtat::Annulee; $repository->save($invitation); - self::assertNull($repository->findPendingByEmail((int) $company->getId(), 'annulee@example.com')); + self::assertNull($repository->findPendingByEmail($company->id, 'annulee@example.com')); } public function testSaveThenUpdateKeepsSameRow(): void @@ -97,7 +97,7 @@ public function testSaveThenUpdateKeepsSameRow(): void $company = $this->createCompany($companyMemberRepository, 'cycle@example.com'); - $invitation = $this->persistInvitation($repository, $company->getId(), 'cycle@example.com', InvitationEtat::EnAttente); + $invitation = $this->persistInvitation($repository, $company->id, 'cycle@example.com', InvitationEtat::EnAttente); $id = $invitation->id; $invitation->status = InvitationEtat::Acceptee; @@ -110,7 +110,7 @@ public function testSaveThenUpdateKeepsSameRow(): void ); self::assertSame(1, (int) $connection->fetchOne( 'SELECT COUNT(*) FROM afup_personnes_morales_invitations WHERE company_id = :companyId', - ['companyId' => $company->getId()], + ['companyId' => $company->id], )); } @@ -119,16 +119,16 @@ private function createCompany(CompanyMemberRepository $repository, string $emai static $counter = 0; $counter++; - $company = (new CompanyMember()) - ->setFirstName('Prénom') - ->setLastName('Nom') - ->setEmail($email) - ->setCompanyName('Société de test ' . $counter) - ->setSiret('12345678901234') - ->setAddress('1 rue du Test') - ->setZipCode('75000') - ->setCity('Paris') - ->setCountry('FR'); + $company = new CompanyMember(); + $company->firstName = 'Prénom'; + $company->lastName = 'Nom'; + $company->email = $email; + $company->companyName = 'Société de test ' . $counter; + $company->siret = '12345678901234'; + $company->address = '1 rue du Test'; + $company->zipCode = '75000'; + $company->city = 'Paris'; + $company->country = 'FR'; $repository->save($company); return $company; diff --git a/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberRepositoryTest.php b/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberRepositoryTest.php new file mode 100644 index 0000000000..8871356364 --- /dev/null +++ b/tests/integration/AppBundle/Association/Entity/Repository/CompanyMemberRepositoryTest.php @@ -0,0 +1,284 @@ +repository = self::getContainer()->get(CompanyMemberRepository::class); + $this->connection = self::getContainer()->get(Connection::class); + } + + public function testSaveFindAndRemove(): void + { + $company = $this->createCompany('Société de test'); + $id = $company->id; + self::assertNotNull($id); + + $row = $this->connection->fetchAssociative('SELECT * FROM afup_personnes_morales WHERE id = :id', ['id' => $id]); + self::assertIsArray($row); + self::assertSame('Société de test', $row['raison_sociale']); + self::assertSame('Paris', $row['ville']); + self::assertSame('FR', $row['id_pays']); + self::assertSame(PersonneMoraleEtat::Active->value, (int) $row['etat']); + + self::getContainer()->get('doctrine')->getManager()->clear(); + + $found = $this->repository->find($id); + self::assertInstanceOf(CompanyMember::class, $found); + self::assertSame('Société de test', $found->companyName); + self::assertSame(3, $found->maxMembers); + self::assertNull($found->lastSubscription, 'find() ne calcule pas la dernière cotisation'); + + $this->repository->remove($found); + + self::assertFalse($this->connection->fetchOne('SELECT 1 FROM afup_personnes_morales WHERE id = :id', ['id' => $id])); + } + + public function testRemoveIsRefusedWhenTheCompanyHasMembershipFees(): void + { + $company = $this->createCompany('Avec cotisation'); + $this->createMembershipFee(MemberType::MemberCompany, $company->id, new \DateTime('+1 month')); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Impossible de supprimer une personne morale qui a des cotisations'); + + $this->repository->remove($company); + } + + public function testRemoveIsRefusedWhenTheCompanyHasMembers(): void + { + $company = $this->createCompany('Avec membres'); + $this->insertPhysicalPerson('membre@example.com', User::STATUS_ACTIVE, $company->id); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Impossible de supprimer une personne morale qui a des membres'); + + $this->repository->remove($company); + } + + public function testFindWithLastSubscriptionLoadsTheLastSubscription(): void + { + $company = $this->createCompany('Cotisante'); + $otherCompany = $this->createCompany('Autre'); + $lastEnd = new \DateTime('+6 months'); + $this->createMembershipFee(MemberType::MemberCompany, $company->id, new \DateTime('-6 months')); + $this->createMembershipFee(MemberType::MemberCompany, $company->id, $lastEnd); + // Cotisation d'une personne physique portant le même identifiant : ne doit pas être prise en compte. + $this->createMembershipFee(MemberType::MemberPhysical, $otherCompany->id, new \DateTime('+2 years')); + + $found = $this->repository->findWithLastSubscription($company->id); + self::assertInstanceOf(CompanyMember::class, $found); + self::assertSame($lastEnd->getTimestamp(), $found->lastSubscription?->getTimestamp()); + self::assertTrue($found->hasUpToDateMembershipFee()); + + $other = $this->repository->findWithLastSubscription($otherCompany->id); + self::assertInstanceOf(CompanyMember::class, $other); + self::assertNull($other->lastSubscription); + self::assertFalse($other->hasUpToDateMembershipFee()); + + self::assertNull($this->repository->findWithLastSubscription(999_999)); + } + + public function testFindDisplayableCompanies(): void + { + $upToDate = $this->createCompany('À jour', publicProfile: true); + $this->createMembershipFee(MemberType::MemberCompany, $upToDate->id, new \DateTime('+1 month')); + + $expired = $this->createCompany('Expirée', publicProfile: true); + $this->createMembershipFee(MemberType::MemberCompany, $expired->id, new \DateTime('-1 month')); + + $private = $this->createCompany('Privée', publicProfile: false); + $this->createMembershipFee(MemberType::MemberCompany, $private->id, new \DateTime('+1 month')); + + $this->createCompany('Sans cotisation', publicProfile: true); + + $companies = $this->repository->findDisplayableCompanies(); + + self::assertSame(['À jour'], array_map(static fn(CompanyMember $c): string => $c->companyName, $companies)); + } + + public function testLoadAll(): void + { + $company = $this->createCompany('Une'); + $this->createCompany('Deux'); + $this->createMembershipFee(MemberType::MemberCompany, $company->id, new \DateTime('+1 month')); + + $companies = $this->repository->loadAll(); + + self::assertCount(2, $companies); + $byName = []; + foreach ($companies as $c) { + $byName[$c->companyName] = $c; + } + self::assertTrue($byName['Une']->hasUpToDateMembershipFee()); + self::assertFalse($byName['Deux']->hasUpToDateMembershipFee()); + } + + public function testSearch(): void + { + $this->createCompany('Zeta Corp', city: 'Lyon'); + $this->createCompany('Alpha SARL', city: 'Paris', status: PersonneMoraleEtat::EnAttente); + $this->createCompany('Beta SAS', city: 'Lille'); + + $names = static fn(array $companies): array => array_map(static fn(CompanyMember $c): string => $c->companyName, $companies); + + self::assertSame(['Beta SAS', 'Zeta Corp'], $names($this->repository->search())); + self::assertSame(['Zeta Corp', 'Beta SAS'], $names($this->repository->search('name', 'desc'))); + self::assertSame(['Alpha SARL', 'Beta SAS', 'Zeta Corp'], $names($this->repository->search('name', 'asc', null, false))); + self::assertSame(['Alpha SARL', 'Beta SAS', 'Zeta Corp'], $names($this->repository->search('status', 'asc', null, false))); + // La direction s'applique à tous les champs de tri (état puis raison sociale) + self::assertSame(['Zeta Corp', 'Beta SAS', 'Alpha SARL'], $names($this->repository->search('status', 'desc', null, false))); + + // Filtre insensible à la casse sur la raison sociale, ou sur la ville + self::assertSame(['Zeta Corp'], $names($this->repository->search('name', 'asc', 'zeta'))); + self::assertSame(['Beta SAS'], $names($this->repository->search('name', 'asc', 'Lille'))); + // Plusieurs mots : un OU entre eux, combiné en ET avec le filtre sur l'état + self::assertSame(['Beta SAS', 'Zeta Corp'], $names($this->repository->search('name', 'asc', 'Zeta Lille Alpha'))); + self::assertSame(['Alpha SARL', 'Beta SAS', 'Zeta Corp'], $names($this->repository->search('name', 'asc', 'Zeta Lille Alpha', false))); + } + + public function testSearchRejectsUnknownSort(): void + { + $this->expectException(\InvalidArgumentException::class); + + $this->repository->search('unknown'); + } + + public function testCountByStatusCountsCompaniesNotPhysicalPersons(): void + { + // Une seule personne morale active, deux en attente. + $this->createCompany('Active'); + $this->createCompany('En attente 1', status: PersonneMoraleEtat::EnAttente); + $this->createCompany('En attente 2', status: PersonneMoraleEtat::EnAttente); + + // Cinq personnes physiques actives, aucune en attente : des comptes + // volontairement différents de ceux des personnes morales ci-dessus, + // pour détecter toute confusion entre les deux tables. + for ($i = 0; $i < 5; $i++) { + $this->insertPhysicalPerson("physique{$i}@example.com", User::STATUS_ACTIVE); + } + + self::assertSame(1, $this->repository->countByStatus(PersonneMoraleEtat::Active)); + self::assertSame(2, $this->repository->countByStatus(PersonneMoraleEtat::EnAttente)); + self::assertSame(0, $this->repository->countByStatus(PersonneMoraleEtat::Inactive)); + } + + public function testGetList(): void + { + $b = $this->createCompany('Bravo'); + $a = $this->createCompany('Alpha'); + + self::assertSame([ + $a->id => sprintf('Alpha (id : %d)', $a->id), + $b->id => sprintf('Bravo (id : %d)', $b->id), + ], $this->repository->getList()); + } + + public function testCountActiveByCompany(): void + { + $company = $this->createCompany('Avec membres'); + $this->insertPhysicalPerson('un@example.com', User::STATUS_ACTIVE, $company->id); + $this->insertPhysicalPerson('deux@example.com', User::STATUS_ACTIVE, $company->id); + $this->insertPhysicalPerson('seul@example.com', User::STATUS_ACTIVE); + + $counts = $this->repository->countActiveByCompany(); + + self::assertSame(2, $counts[$company->id]); + self::assertSame(1, $counts[0]); + } + + public function testSearchCompanyMemberSubscriptions(): void + { + $company = $this->createCompany('Recherchée', email: 'contact@recherchee.example.com'); + $fee = $this->createMembershipFee(MemberType::MemberCompany, $company->id, new \DateTime('+1 month'), 'Virement XYZ'); + // Même identifiant, mais personne physique : exclue. + $this->createMembershipFee(MemberType::MemberPhysical, $company->id, new \DateTime('+1 month'), 'Virement XYZ'); + + $results = $this->repository->searchCompanyMemberSubscriptions('XYZ'); + + self::assertCount(1, $results); + self::assertSame('Recherchée', $results[0]['raison_sociale']); + self::assertSame('contact@recherchee.example.com', $results[0]['email']); + self::assertSame($fee->id, (int) $results[0]['id']); + self::assertSame('Virement XYZ', $results[0]['informations_reglement']); + + self::assertCount(1, $this->repository->searchCompanyMemberSubscriptions('recherchee.example')); + self::assertCount(0, $this->repository->searchCompanyMemberSubscriptions('introuvable')); + } + + private function createCompany( + string $name, + string $city = 'Paris', + PersonneMoraleEtat $status = PersonneMoraleEtat::Active, + bool $publicProfile = false, + ?string $email = null, + ): CompanyMember { + static $counter = 0; + $counter++; + + $company = new CompanyMember(); + $company->firstName = 'Prénom'; + $company->lastName = 'Nom'; + $company->email = $email ?? "morale{$counter}@example.com"; + $company->companyName = $name; + $company->siret = '12345678901234'; + $company->address = '1 rue du Test'; + $company->zipCode = '75000'; + $company->city = $city; + $company->country = 'FR'; + $company->status = $status; + $company->maxMembers = 3; + $company->publicProfileEnabled = $publicProfile; + $this->repository->save($company); + + return $company; + } + + private function createMembershipFee(MemberType $type, int $memberId, \DateTime $end, ?string $paymentInfo = null): Cotisation + { + static $invoiceCounter = 0; + $invoiceCounter++; + + $fee = new Cotisation(); + $fee->numeroFacture = sprintf('TEST-%04d', $invoiceCounter); + $fee->typePersonne = $type; + $fee->idPersonne = $memberId; + $fee->montant = 150.0; + $fee->dateDebut = (clone $end)->modify('-1 year'); + $fee->dateFin = $end; + $fee->informationsReglement = $paymentInfo; + self::getContainer()->get(CotisationRepository::class)->save($fee); + + return $fee; + } + + private function insertPhysicalPerson(string $email, int $status, int $companyId = 0): void + { + $this->connection->insert('afup_personnes_physiques', [ + 'roles' => '[]', + 'adresse' => '1 rue du Test', + 'email' => $email, + 'etat' => $status, + 'id_personne_morale' => $companyId, + ]); + } +} diff --git a/tests/integration/AppBundle/Association/Model/Repository/CompanyMemberRepositoryTest.php b/tests/integration/AppBundle/Association/Model/Repository/CompanyMemberRepositoryTest.php deleted file mode 100644 index de459426f2..0000000000 --- a/tests/integration/AppBundle/Association/Model/Repository/CompanyMemberRepositoryTest.php +++ /dev/null @@ -1,62 +0,0 @@ -get(CompanyMemberRepository::class); - $connection = self::getContainer()->get(Connection::class); - - // Une seule personne morale active, deux en attente. - $companyMemberRepository->save($this->buildCompanyMember(CompanyMember::STATUS_ACTIVE)); - $companyMemberRepository->save($this->buildCompanyMember(CompanyMember::STATUS_PENDING)); - $companyMemberRepository->save($this->buildCompanyMember(CompanyMember::STATUS_PENDING)); - - // Cinq personnes physiques actives, aucune en attente : des comptes - // volontairement différents de ceux des personnes morales ci-dessus, - // pour détecter toute confusion entre les deux tables. - for ($i = 0; $i < 5; $i++) { - $this->insertPhysicalPerson($connection, "physique{$i}@example.com", CompanyMember::STATUS_ACTIVE); - } - - self::assertSame(1, $companyMemberRepository->countByStatus(CompanyMember::STATUS_ACTIVE)); - self::assertSame(2, $companyMemberRepository->countByStatus(CompanyMember::STATUS_PENDING)); - } - - private function buildCompanyMember(int $status): CompanyMember - { - static $counter = 0; - $counter++; - - return (new CompanyMember()) - ->setFirstName('Prénom') - ->setLastName('Nom') - ->setEmail("morale{$counter}@example.com") - ->setCompanyName('Société de test') - ->setSiret('12345678901234') - ->setAddress('1 rue du Test') - ->setZipCode('75000') - ->setCity('Paris') - ->setCountry('FR') - ->setStatus($status); - } - - private function insertPhysicalPerson(Connection $connection, string $email, int $status): void - { - $connection->insert('afup_personnes_physiques', [ - 'roles' => '[]', - 'adresse' => '1 rue du Test', - 'email' => $email, - 'etat' => $status, - ]); - } -} diff --git a/tests/unit/AppBundle/Association/Entity/CompanyMemberTest.php b/tests/unit/AppBundle/Association/Entity/CompanyMemberTest.php new file mode 100644 index 0000000000..979f30f967 --- /dev/null +++ b/tests/unit/AppBundle/Association/Entity/CompanyMemberTest.php @@ -0,0 +1,104 @@ +maxMembers = $maxMembers; + + self::assertEquals($expectedAmount, $companyMember->getMembershipFee()); + } + + /** + * @return array + */ + public static function companies(): array + { + return [ + 'null' => [null, SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + 'zero' => [0, SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + 'under' => [2, SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + 'equal' => [3, SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + 'just over' => [4, 2 * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + 'over' => [6, 2 * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], + ]; + } + + public function testHasUpToDateMembershipFee(): void + { + $now = new \DateTimeImmutable('2026-06-15 12:00:00'); + $companyMember = new CompanyMember(); + + self::assertFalse($companyMember->hasUpToDateMembershipFee($now), 'sans cotisation'); + + $companyMember->lastSubscription = $now->modify('+1 day'); + self::assertTrue($companyMember->hasUpToDateMembershipFee($now)); + + $companyMember->lastSubscription = $now->modify('-1 day'); + self::assertFalse($companyMember->hasUpToDateMembershipFee($now)); + } + + public function testFormattedRelatedAfupOffices(): void + { + $companyMember = new CompanyMember(); + self::assertSame([], $companyMember->getFormattedRelatedAfupOffices()); + + $companyMember->setFormattedRelatedAfupOffices(['lyon', 'bordeaux']); + self::assertSame('bordeaux,lyon', $companyMember->relatedAfupOffices); + self::assertSame(['bordeaux', 'lyon'], $companyMember->getFormattedRelatedAfupOffices()); + + $companyMember->setFormattedRelatedAfupOffices([]); + self::assertNull($companyMember->relatedAfupOffices); + } + + #[DataProvider('twitterHandles')] + public function testCleanedTwitterHandle(?string $handle, ?string $expected): void + { + $companyMember = new CompanyMember(); + $companyMember->twitterHandle = $handle; + + self::assertSame($expected, $companyMember->getCleanedTwitterHandle()); + } + + /** + * @return array + */ + public static function twitterHandles(): array + { + return [ + 'null' => [null, null], + 'vide' => ['', null], + 'arobase' => ['@afup', 'afup'], + 'url' => ['https://twitter.com/afup', 'afup'], + ]; + } + + public function testSlug(): void + { + $companyMember = new CompanyMember(); + $companyMember->companyName = 'Société Générale & Co'; + + self::assertSame('societe-generale-co', $companyMember->getSlug()); + } + + public function testValidInvitationsIgnoresEmptyEntries(): void + { + $invitation = new CompanyMemberInvitation(); + $companyMember = new CompanyMember(); + $companyMember->invitations = [null, $invitation, null]; + + self::assertSame([1 => $invitation], $companyMember->getValidInvitations()); + } +} diff --git a/tests/unit/AppBundle/Association/Form/CompanyMemberTypeTest.php b/tests/unit/AppBundle/Association/Form/CompanyMemberTypeTest.php index 4aaa7d751d..c9af9fca0a 100644 --- a/tests/unit/AppBundle/Association/Form/CompanyMemberTypeTest.php +++ b/tests/unit/AppBundle/Association/Form/CompanyMemberTypeTest.php @@ -6,7 +6,7 @@ use AppBundle\Association\Entity\CompanyMemberInvitation; use AppBundle\Association\Form\CompanyMemberType; -use AppBundle\Association\Model\CompanyMember; +use AppBundle\Association\Entity\CompanyMember; use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType; use EWZ\Bundle\RecaptchaBundle\Locale\LocaleResolver; use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations; @@ -118,7 +118,7 @@ public function unMembreSupplementaireRenseigneEstBienRattache(): void private function invitation(CompanyMember $member, int $index): CompanyMemberInvitation { - $invitations = $member->getInvitations() ?? []; + $invitations = $member->getValidInvitations(); self::assertArrayHasKey($index, $invitations); return $invitations[$index]; @@ -129,7 +129,7 @@ private function invitation(CompanyMember $member, int $index): CompanyMemberInv */ private function invitations(CompanyMember $member): array { - return array_values($member->getInvitations() ?? []); + return array_values($member->getValidInvitations()); } /** @@ -146,7 +146,7 @@ private function newCompanyMember(): CompanyMember $member = new CompanyMember(); $invitation = new CompanyMemberInvitation(); $invitation->manager = true; - $member->setInvitations([$invitation]); + $member->invitations = [$invitation]; return $member; } diff --git a/tests/unit/AppBundle/Association/Model/CompanyMemberTest.php b/tests/unit/AppBundle/Association/Model/CompanyMemberTest.php deleted file mode 100644 index f467e35b09..0000000000 --- a/tests/unit/AppBundle/Association/Model/CompanyMemberTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getMembershipFee()); - } - - public static function companies(): array - { - return [ - 'null' => [(new CompanyMember()), SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], - 'under' => [new CompanyMember()->setMaxMembers(2), - SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE, - ], - 'equal' => [new CompanyMember()->setMaxMembers(3), - SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE, - ], - 'just over' => [new CompanyMember()->setMaxMembers(4), 2 * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], - 'over' => [new CompanyMember()->setMaxMembers(6), 2 * SubscriptionManagement::AFUP_COTISATION_PERSONNE_MORALE], - ]; - } - -}