From a387515eb0f4931b69cfc31c351251c9adb34b42 Mon Sep 17 00:00:00 2001 From: vgreb Date: Fri, 16 Jan 2026 13:02:51 +0100 Subject: [PATCH] =?UTF-8?q?Refonte=20Doctrine=20des=20comptes=20de=20la=20?= =?UTF-8?q?tr=C3=A9sorerie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AppBundle/Accounting/Entity/Account.php | 23 +++++++ .../Entity/Repository/AccountRepository.php | 45 ++++++++++++ .../AppBundle/Accounting/Model/Account.php | 58 ---------------- .../Model/Repository/AccountRepository.php | 68 ------------------- .../Configuration/AddAccountAction.php | 8 +-- .../Configuration/ArchiveAccountAction.php | 8 +-- .../Configuration/EditAccountAction.php | 8 +-- .../Configuration/ListAccountAction.php | 4 +- .../Configuration/RestoreAccountAction.php | 8 +-- 9 files changed, 86 insertions(+), 144 deletions(-) create mode 100644 sources/AppBundle/Accounting/Entity/Account.php create mode 100644 sources/AppBundle/Accounting/Entity/Repository/AccountRepository.php delete mode 100644 sources/AppBundle/Accounting/Model/Account.php delete mode 100644 sources/AppBundle/Accounting/Model/Repository/AccountRepository.php diff --git a/sources/AppBundle/Accounting/Entity/Account.php b/sources/AppBundle/Accounting/Entity/Account.php new file mode 100644 index 000000000..38d87ba42 --- /dev/null +++ b/sources/AppBundle/Accounting/Entity/Account.php @@ -0,0 +1,23 @@ + + */ +final class AccountRepository extends EntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Account::class); + } + + /** + * @return array + */ + public function getAllSortedByName(): array + { + return $this->createQueryBuilder('c') + ->orderBy('c.name', 'asc') + ->getQuery() + ->execute(); + } + + + /** + * @return array + */ + public function getActiveAccounts(): array + { + return $this->createQueryBuilder('c') + ->where('c.archivedAt IS NULL') + ->orderBy('c.name', 'asc') + ->getQuery() + ->execute(); + } + +} diff --git a/sources/AppBundle/Accounting/Model/Account.php b/sources/AppBundle/Accounting/Model/Account.php deleted file mode 100644 index 1d68806cb..000000000 --- a/sources/AppBundle/Accounting/Model/Account.php +++ /dev/null @@ -1,58 +0,0 @@ -id; - } - - public function setId(int $id): self - { - $this->propertyChanged('id', $this->id, $id); - $this->id = $id; - return $this; - } - - public function getName(): ?string - { - return $this->name; - } - - public function setName(?string $name): self - { - $this->propertyChanged('name', $this->name, $name); - $this->name = $name; - - return $this; - } - - public function getArchivedAt(): ?DateTime - { - return $this->archivedAt; - } - - public function setArchivedAt(?DateTime $archivedAt): self - { - $this->propertyChanged('archivedAt', $this->archivedAt, $archivedAt); - $this->archivedAt = $archivedAt; - - return $this; - } -} diff --git a/sources/AppBundle/Accounting/Model/Repository/AccountRepository.php b/sources/AppBundle/Accounting/Model/Repository/AccountRepository.php deleted file mode 100644 index a87cf78c7..000000000 --- a/sources/AppBundle/Accounting/Model/Repository/AccountRepository.php +++ /dev/null @@ -1,68 +0,0 @@ - - */ -class AccountRepository extends Repository implements MetadataInitializer -{ - /** - * @return Collection - */ - public function getActiveAccounts(): CollectionInterface - { - /** @var SelectInterface $builder */ - $builder = $this->getQueryBuilder(self::QUERY_SELECT); - $builder->cols(['id', 'nom_compte']) - ->from('compta_compte') - ->where('archived_at IS NULL') - ->orderBy(['nom_compte asc']); - - return $this->getQuery($builder->getStatement())->query($this->getCollection(new HydratorSingleObject())); - } - - public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = []) - { - $metadata = new Metadata($serializerFactory); - - $metadata->setEntity(Account::class); - $metadata->setConnectionName('main'); - $metadata->setDatabase($options['database']); - $metadata->setTable('compta_compte'); - - $metadata - ->addField([ - 'columnName' => 'id', - 'fieldName' => 'id', - 'primary' => true, - 'autoincrement' => true, - 'type' => 'int', - ]) - ->addField([ - 'columnName' => 'nom_compte', - 'fieldName' => 'name', - 'type' => 'string', - ]) - ->addField([ - 'columnName' => 'archived_at', - 'fieldName' => 'archivedAt', - 'type' => 'datetime', - ]) - ; - - return $metadata; - } -} diff --git a/sources/AppBundle/Controller/Admin/Accounting/Configuration/AddAccountAction.php b/sources/AppBundle/Controller/Admin/Accounting/Configuration/AddAccountAction.php index a486ba36b..13d7a4b25 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Configuration/AddAccountAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Configuration/AddAccountAction.php @@ -5,8 +5,8 @@ namespace AppBundle\Controller\Admin\Accounting\Configuration; use AppBundle\Accounting\Form\AccountType; -use AppBundle\Accounting\Model\Account; -use AppBundle\Accounting\Model\Repository\AccountRepository; +use AppBundle\Accounting\Entity\Account; +use AppBundle\Accounting\Entity\Repository\AccountRepository; use AppBundle\AuditLog\Audit; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -26,8 +26,8 @@ public function __invoke(Request $request): Response $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->accountRepository->save($account); - $this->audit->log('Ajout du compte ' . $account->getName()); - $this->addFlash('notice', 'Le compte ' . $account->getName() . ' a été créé'); + $this->audit->log('Ajout du compte ' . $account->name); + $this->addFlash('notice', 'Le compte ' . $account->name . ' a été créé'); return $this->redirectToRoute('admin_accounting_accounts_list'); } diff --git a/sources/AppBundle/Controller/Admin/Accounting/Configuration/ArchiveAccountAction.php b/sources/AppBundle/Controller/Admin/Accounting/Configuration/ArchiveAccountAction.php index ad3f68e4b..cd2d4b0e1 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Configuration/ArchiveAccountAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Configuration/ArchiveAccountAction.php @@ -4,8 +4,8 @@ namespace AppBundle\Controller\Admin\Accounting\Configuration; -use AppBundle\Accounting\Model\Account; -use AppBundle\Accounting\Model\Repository\AccountRepository; +use AppBundle\Accounting\Entity\Account; +use AppBundle\Accounting\Entity\Repository\AccountRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -15,7 +15,7 @@ public function __construct(private readonly AccountRepository $accountRepositor public function __invoke(int $id): RedirectResponse { - $account = $this->accountRepository->get($id); + $account = $this->accountRepository->find($id); if (!$account instanceof Account) { $this->addFlash('error', 'Compte non trouvé'); @@ -23,7 +23,7 @@ public function __invoke(int $id): RedirectResponse return $this->redirectToRoute('admin_accounting_accounts_list'); } - $account->setArchivedAt(new \DateTime()); + $account->archivedAt = new \DateTimeImmutable(); $this->accountRepository->save($account); return $this->redirectToRoute('admin_accounting_accounts_edit', [ diff --git a/sources/AppBundle/Controller/Admin/Accounting/Configuration/EditAccountAction.php b/sources/AppBundle/Controller/Admin/Accounting/Configuration/EditAccountAction.php index f0d277caf..a8c0fc892 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Configuration/EditAccountAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Configuration/EditAccountAction.php @@ -5,7 +5,7 @@ namespace AppBundle\Controller\Admin\Accounting\Configuration; use AppBundle\Accounting\Form\AccountType; -use AppBundle\Accounting\Model\Repository\AccountRepository; +use AppBundle\Accounting\Entity\Repository\AccountRepository; use AppBundle\AuditLog\Audit; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -20,13 +20,13 @@ public function __construct( public function __invoke(int $id,Request $request): Response { - $account = $this->accountRepository->get($id); + $account = $this->accountRepository->find($id); $form = $this->createForm(AccountType::class, $account); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->accountRepository->save($account); - $this->audit->log('Modification du compte ' . $account->getName()); - $this->addFlash('notice', 'Le compte ' . $account->getName() . ' a été modifié'); + $this->audit->log('Modification du compte ' . $account->name); + $this->addFlash('notice', 'Le compte ' . $account->name . ' a été modifié'); return $this->redirectToRoute('admin_accounting_accounts_list'); } diff --git a/sources/AppBundle/Controller/Admin/Accounting/Configuration/ListAccountAction.php b/sources/AppBundle/Controller/Admin/Accounting/Configuration/ListAccountAction.php index 2bc345b12..2023632d2 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Configuration/ListAccountAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Configuration/ListAccountAction.php @@ -4,7 +4,7 @@ namespace AppBundle\Controller\Admin\Accounting\Configuration; -use AppBundle\Accounting\Model\Repository\AccountRepository; +use AppBundle\Accounting\Entity\Repository\AccountRepository; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Twig\Environment; @@ -18,7 +18,7 @@ public function __construct( public function __invoke(Request $request): Response { - $accounts = $this->accountRepository->getAll(); + $accounts = $this->accountRepository->findAll(); return new Response($this->twig->render('admin/accounting/configuration/account_list.html.twig', [ 'accounts' => $accounts, diff --git a/sources/AppBundle/Controller/Admin/Accounting/Configuration/RestoreAccountAction.php b/sources/AppBundle/Controller/Admin/Accounting/Configuration/RestoreAccountAction.php index 6d2cf81f0..da71965db 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/Configuration/RestoreAccountAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/Configuration/RestoreAccountAction.php @@ -4,8 +4,8 @@ namespace AppBundle\Controller\Admin\Accounting\Configuration; -use AppBundle\Accounting\Model\Account; -use AppBundle\Accounting\Model\Repository\AccountRepository; +use AppBundle\Accounting\Entity\Account; +use AppBundle\Accounting\Entity\Repository\AccountRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -15,7 +15,7 @@ public function __construct(private readonly AccountRepository $accountRepositor public function __invoke(int $id): RedirectResponse { - $account = $this->accountRepository->get($id); + $account = $this->accountRepository->find($id); if (!$account instanceof Account) { $this->addFlash('error', 'Compte non trouvé'); @@ -23,7 +23,7 @@ public function __invoke(int $id): RedirectResponse return $this->redirectToRoute('admin_accounting_accounts_list'); } - $account->setArchivedAt(null); + $account->archivedAt = null; $this->accountRepository->save($account); return $this->redirectToRoute('admin_accounting_accounts_edit', [