Skip to content

Commit 652bb90

Browse files
authored
Sauvegarde de la date de facturation d'une cotisation (#2130)
fixes #458
1 parent 448057e commit 652bb90

File tree

5 files changed

+58
-8
lines changed

5 files changed

+58
-8
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class AddDateFactureToCotisation extends AbstractMigration
8+
{
9+
public function change(): void
10+
{
11+
$this->table('afup_cotisations')
12+
->addColumn('date_facture', 'timestamp', [
13+
'null' => true,
14+
])
15+
->update();
16+
}
17+
}

sources/Afup/Association/Cotisations.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function ajouter(MemberType $type_personne, $id_personne, $montant, $type
126126
{
127127
$requete = 'INSERT INTO ';
128128
$requete .= ' afup_cotisations (type_personne, id_personne, montant, type_reglement , informations_reglement,';
129-
$requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client) ';
129+
$requete .= ' date_debut, date_fin, numero_facture, token, commentaires, reference_client, date_facture) ';
130130
$requete .= 'VALUES (';
131131
$requete .= $type_personne->value . ',';
132132
$requete .= $id_personne . ',';
@@ -138,7 +138,8 @@ public function ajouter(MemberType $type_personne, $id_personne, $montant, $type
138138
$requete .= $this->_bdd->echapper($this->_genererNumeroFacture()) . ',';
139139
$requete .= $this->_bdd->echapper(base64_encode(random_bytes(30))) . ',';
140140
$requete .= $this->_bdd->echapper($commentaires) . ',';
141-
$requete .= $this->_bdd->echapper($referenceClient) . ')';
141+
$requete .= $this->_bdd->echapper($referenceClient) . ',';
142+
$requete .= $this->_bdd->echapper(date('Y-m-d\TH:i:s')) . ')';
142143
return $this->_bdd->executer($requete) !== false;
143144
}
144145

@@ -332,15 +333,20 @@ public function genererFacture($id_cotisation, $chemin = null)
332333
$requete = 'SELECT * FROM ' . $table . ' WHERE id=' . $cotisation['id_personne'];
333334
$personne = $this->_bdd->obtenirEnregistrement($requete);
334335

335-
$dateCotisation = \DateTimeImmutable::createFromFormat('U', $cotisation['date_debut']);
336+
if ($cotisation['date_facture'] !== null) {
337+
$dateFacture = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $cotisation['date_facture']);
338+
} else {
339+
$dateFacture = \DateTimeImmutable::createFromFormat('U', $cotisation['date_debut']);
340+
}
341+
336342
$bankAccountFactory = new BankAccountFactory();
337-
$isSubjectedToVat = Vat::isSubjectedToVat($dateCotisation);
343+
$isSubjectedToVat = Vat::isSubjectedToVat($dateFacture);
338344
// Construction du PDF
339-
$pdf = new PDF_Facture($bankAccountFactory->createApplyableAt($dateCotisation), $isSubjectedToVat);
345+
$pdf = new PDF_Facture($bankAccountFactory->createApplyableAt($dateFacture), $isSubjectedToVat);
340346
$pdf->AddPage();
341347

342348
$pdf->Cell(130, 5);
343-
$pdf->Cell(60, 5, 'Le ' . $dateCotisation->format('d/m/Y'));
349+
$pdf->Cell(60, 5, 'Le ' . $dateFacture->format('d/m/Y'));
344350

345351
$pdf->Ln();
346352
$pdf->Ln();

sources/AppBundle/Controller/Admin/Accounting/MembershipFee/AddMembershipFeeAction.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use AppBundle\MembershipFee\Form\MembershipFeeType;
1212
use AppBundle\MembershipFee\Model\MembershipFee;
1313
use AppBundle\MembershipFee\Model\Repository\MembershipFeeRepository;
14+
use Psr\Clock\ClockInterface;
1415
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
@@ -21,6 +22,7 @@ public function __construct(
2122
private readonly CompanyMemberRepository $companyMemberRepository,
2223
private readonly UserRepository $userRepository,
2324
private readonly MembershipFeeRepository $membershipFeeRepository,
25+
private readonly ClockInterface $clock,
2426
private readonly Audit $audit,
2527
) {}
2628

@@ -32,7 +34,6 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request
3234
MemberType::MemberPhysical => $this->userRepository->get($memberId),
3335
};
3436

35-
3637
$startDate = $this->membershipFeeRepository->getMembershipStartingDate($memberType, $member->getId());
3738
$endDate = clone $startDate;
3839
$endDate->modify('+1 year');
@@ -41,6 +42,7 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request
4142
->setUserType($memberType)
4243
->setUserId($member->getId())
4344
->setToken(base64_encode(random_bytes(30)))
45+
->setInvoiceDate($this->clock->now())
4446
;
4547

4648
$form = $this->createForm(MembershipFeeType::class, $membershipFee);
@@ -52,10 +54,12 @@ public function __invoke(MemberType $memberType, int $memberId, Request $request
5254
\IntlDateFormatter::FULL,
5355
);
5456
$fmt->setPattern('dd MMMM yyyy');
57+
58+
$name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : $member->getFirstName() . ' ' . $member->getLastName();
59+
5560
try {
5661
$membershipFee->setInvoiceNumber($this->membershipFeeRepository->generateInvoiceNumber());
5762
$this->membershipFeeRepository->save($membershipFee);
58-
$name = $memberType->value === MemberType::MemberCompany->value ? $member->getCompanyName() : $member->getFirstName() . ' ' . $member->getLastName();
5963
$this->audit->log("Ajout de la cotisation jusqu'au " . $fmt->format($membershipFee->getEndDate()) . ' pour ' . $name);
6064
$this->addFlash('notice', "La cotisation jusqu'au " . $fmt->format($membershipFee->getEndDate()) . ' pour ' . $name . ' a bien été ajoutée');
6165
} catch (\Exception) {

sources/AppBundle/MembershipFee/Model/MembershipFee.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use CCMBenchmark\Ting\Entity\NotifyProperty;
1010
use CCMBenchmark\Ting\Entity\NotifyPropertyInterface;
1111
use DateTime;
12+
use DateTimeImmutable;
1213

1314
class MembershipFee implements NotifyPropertyInterface
1415
{
@@ -23,6 +24,7 @@ class MembershipFee implements NotifyPropertyInterface
2324
private ?DateTime $startDate = null;
2425
private ?DateTime $endDate = null;
2526
private ?string $invoiceNumber = null;
27+
private ?DateTimeImmutable $invoiceDate = null;
2628
private ?string $clientReference = null;
2729
private ?string $comments = null;
2830
private ?string $token = null;
@@ -137,6 +139,18 @@ public function setInvoiceNumber(?string $invoiceNumber): self
137139
return $this;
138140
}
139141

142+
public function getInvoiceDate(): ?DateTimeImmutable
143+
{
144+
return $this->invoiceDate;
145+
}
146+
147+
public function setInvoiceDate(?\DateTimeImmutable $invoiceDate): self
148+
{
149+
$this->propertyChanged('invoiceDate', $this->invoiceDate, $invoiceDate);
150+
$this->invoiceDate = $invoiceDate;
151+
return $this;
152+
}
153+
140154
public function getClientReference(): ?string
141155
{
142156
return $this->clientReference;

sources/AppBundle/MembershipFee/Model/Repository/MembershipFeeRepository.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ public static function initMetadata(SerializerFactoryInterface $serializerFactor
126126
'fieldName' => 'invoiceNumber',
127127
'type' => 'string',
128128
])
129+
->addField([
130+
'columnName' => 'date_facture',
131+
'fieldName' => 'invoiceDate',
132+
'type' => 'datetime_immutable',
133+
'serializer_options' => [
134+
'unserialize' => ['unSerializeUseFormat' => true, 'format' => 'Y-m-d H:i:s'],
135+
'serialize' => ['serializeUseFormat' => true, 'format' => 'Y-m-d H:i:s'],
136+
],
137+
])
129138
->addField([
130139
'columnName' => 'reference_client',
131140
'fieldName' => 'clientReference',

0 commit comments

Comments
 (0)