Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions db/migrations/20260130130135_add_date_facture_to_cotisation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddDateFactureToCotisation extends AbstractMigration
{
public function change(): void
{
$this->table('afup_cotisations')
->addColumn('date_facture', 'timestamp', [
'null' => true,
])
->update();
}
}
18 changes: 12 additions & 6 deletions sources/Afup/Association/Cotisations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ',';
Expand All @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
) {}

Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions sources/AppBundle/MembershipFee/Model/MembershipFee.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use CCMBenchmark\Ting\Entity\NotifyProperty;
use CCMBenchmark\Ting\Entity\NotifyPropertyInterface;
use DateTime;
use DateTimeImmutable;

class MembershipFee implements NotifyPropertyInterface
{
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading