From 004c850e6d84171fdc0446de9e87a6e7f273ede7 Mon Sep 17 00:00:00 2001 From: Nathan Boiron Date: Fri, 30 Jan 2026 14:38:33 +0100 Subject: [PATCH] Sauvegarde de la date de facturation d'une cotisation fixes #458 --- ...30130135_add_date_facture_to_cotisation.php | 17 +++++++++++++++++ sources/Afup/Association/Cotisations.php | 18 ++++++++++++------ .../MembershipFee/AddMembershipFeeAction.php | 8 ++++++-- .../MembershipFee/Model/MembershipFee.php | 14 ++++++++++++++ .../Repository/MembershipFeeRepository.php | 9 +++++++++ 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 db/migrations/20260130130135_add_date_facture_to_cotisation.php diff --git a/db/migrations/20260130130135_add_date_facture_to_cotisation.php b/db/migrations/20260130130135_add_date_facture_to_cotisation.php new file mode 100644 index 000000000..66e3a46c3 --- /dev/null +++ b/db/migrations/20260130130135_add_date_facture_to_cotisation.php @@ -0,0 +1,17 @@ +table('afup_cotisations') + ->addColumn('date_facture', 'timestamp', [ + 'null' => true, + ]) + ->update(); + } +} diff --git a/sources/Afup/Association/Cotisations.php b/sources/Afup/Association/Cotisations.php index c79a1dde8..04c5d3931 100644 --- a/sources/Afup/Association/Cotisations.php +++ b/sources/Afup/Association/Cotisations.php @@ -126,7 +126,7 @@ public function ajouter(MemberType $type_personne, $id_personne, $montant, $type { $requete = 'INSERT INTO '; $requete .= ' afup_cotisations (type_personne, id_personne, montant, type_reglement , informations_reglement,'; - $requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client) '; + $requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client, date_facture) '; $requete .= 'VALUES ('; $requete .= $type_personne->value . ','; $requete .= $id_personne . ','; @@ -138,7 +138,8 @@ public function ajouter(MemberType $type_personne, $id_personne, $montant, $type $requete .= $this->_bdd->echapper($this->_genererNumeroFacture()) . ','; $requete .= $this->_bdd->echapper(base64_encode(random_bytes(30))) . ','; $requete .= $this->_bdd->echapper($commentaires) . ','; - $requete .= $this->_bdd->echapper($referenceClient) . ')'; + $requete .= $this->_bdd->echapper($referenceClient) . ','; + $requete .= $this->_bdd->echapper(date('Y-m-d\TH:i:s')) . ')'; return $this->_bdd->executer($requete) !== false; } @@ -332,15 +333,20 @@ public function genererFacture($id_cotisation, $chemin = null) $requete = 'SELECT * FROM ' . $table . ' WHERE id=' . $cotisation['id_personne']; $personne = $this->_bdd->obtenirEnregistrement($requete); - $dateCotisation = \DateTimeImmutable::createFromFormat('U', $cotisation['date_debut']); + if ($cotisation['date_facture'] !== null) { + $dateFacture = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cotisation['date_facture']); + } else { + $dateFacture = \DateTimeImmutable::createFromFormat('U', $cotisation['date_debut']); + } + $bankAccountFactory = new BankAccountFactory(); - $isSubjectedToVat = Vat::isSubjectedToVat($dateCotisation); + $isSubjectedToVat = Vat::isSubjectedToVat($dateFacture); // Construction du PDF - $pdf = new PDF_Facture($bankAccountFactory->createApplyableAt($dateCotisation), $isSubjectedToVat); + $pdf = new PDF_Facture($bankAccountFactory->createApplyableAt($dateFacture), $isSubjectedToVat); $pdf->AddPage(); $pdf->Cell(130, 5); - $pdf->Cell(60, 5, 'Le ' . $dateCotisation->format('d/m/Y')); + $pdf->Cell(60, 5, 'Le ' . $dateFacture->format('d/m/Y')); $pdf->Ln(); $pdf->Ln(); diff --git a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php index d86be78dd..8aedfff74 100644 --- a/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php +++ b/sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php @@ -11,6 +11,7 @@ use AppBundle\MembershipFee\Form\MembershipFeeType; use AppBundle\MembershipFee\Model\MembershipFee; use AppBundle\MembershipFee\Model\Repository\MembershipFeeRepository; +use Psr\Clock\ClockInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -21,6 +22,7 @@ public function __construct( private readonly CompanyMemberRepository $companyMemberRepository, private readonly UserRepository $userRepository, private readonly MembershipFeeRepository $membershipFeeRepository, + private readonly ClockInterface $clock, private readonly Audit $audit, ) {} @@ -32,7 +34,6 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request MemberType::MemberPhysical => $this->userRepository->get($memberId), }; - $startDate = $this->membershipFeeRepository->getMembershipStartingDate($memberType, $member->getId()); $endDate = clone $startDate; $endDate->modify('+1 year'); @@ -41,6 +42,7 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request ->setUserType($memberType) ->setUserId($member->getId()) ->setToken(base64_encode(random_bytes(30))) + ->setInvoiceDate($this->clock->now()) ; $form = $this->createForm(MembershipFeeType::class, $membershipFee); @@ -52,10 +54,12 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request \IntlDateFormatter::FULL, ); $fmt->setPattern('dd MMMM yyyy'); + + $name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : $member->getFirstName() . ' ' . $member->getLastName(); + try { $membershipFee->setInvoiceNumber($this->membershipFeeRepository->generateInvoiceNumber()); $this->membershipFeeRepository->save($membershipFee); - $name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : $member->getFirstName() . ' ' . $member->getLastName(); $this->audit->log("Ajout de la cotisation jusqu'au " . $fmt->format($membershipFee->getEndDate()) . ' pour ' . $name); $this->addFlash('notice', "La cotisation jusqu'au " . $fmt->format($membershipFee->getEndDate()) . ' pour ' . $name . ' a bien été ajoutée'); } catch (\Exception) { diff --git a/sources/AppBundle/MembershipFee/Model/MembershipFee.php b/sources/AppBundle/MembershipFee/Model/MembershipFee.php index 762a3c22e..ada997107 100644 --- a/sources/AppBundle/MembershipFee/Model/MembershipFee.php +++ b/sources/AppBundle/MembershipFee/Model/MembershipFee.php @@ -9,6 +9,7 @@ use CCMBenchmark\Ting\Entity\NotifyProperty; use CCMBenchmark\Ting\Entity\NotifyPropertyInterface; use DateTime; +use DateTimeImmutable; class MembershipFee implements NotifyPropertyInterface { @@ -23,6 +24,7 @@ class MembershipFee implements NotifyPropertyInterface private ?DateTime $startDate = null; private ?DateTime $endDate = null; private ?string $invoiceNumber = null; + private ?DateTimeImmutable $invoiceDate = null; private ?string $clientReference = null; private ?string $comments = null; private ?string $token = null; @@ -137,6 +139,18 @@ public function setInvoiceNumber(?string $invoiceNumber): self return $this; } + public function getInvoiceDate(): ?DateTimeImmutable + { + return $this->invoiceDate; + } + + public function setInvoiceDate(?\DateTimeImmutable $invoiceDate): self + { + $this->propertyChanged('invoiceDate', $this->invoiceDate, $invoiceDate); + $this->invoiceDate = $invoiceDate; + return $this; + } + public function getClientReference(): ?string { return $this->clientReference; diff --git a/sources/AppBundle/MembershipFee/Model/Repository/MembershipFeeRepository.php b/sources/AppBundle/MembershipFee/Model/Repository/MembershipFeeRepository.php index 053aecea9..bed0966f2 100644 --- a/sources/AppBundle/MembershipFee/Model/Repository/MembershipFeeRepository.php +++ b/sources/AppBundle/MembershipFee/Model/Repository/MembershipFeeRepository.php @@ -126,6 +126,15 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor 'fieldName' => 'invoiceNumber', 'type' => 'string', ]) + ->addField([ + 'columnName' => 'date_facture', + 'fieldName' => 'invoiceDate', + 'type' => 'datetime_immutable', + 'serializer_options' => [ + 'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'Y-m-d H:i:s'], + 'serialize' => ['serializeUseFormat' => true, 'format' => 'Y-m-d H:i:s'], + ], + ]) ->addField([ 'columnName' => 'reference_client', 'fieldName' => 'clientReference',