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
15 changes: 9 additions & 6 deletions db/seeds/Inscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public function run(): void
'date' => new \DateTime("2024-01-02")->getTimestamp(),
'reference' => 'REF-TEST-004',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
// Prix vendeur de l'evenement de test (db/seeds/EventTarif.php : id_tarif = 3, price = 15)
'montant' => 15.0,
'genre' => Genre::Femme->value,
'nom' => 'Sans',
'prenom' => 'Cotisation',
Expand All @@ -85,7 +86,8 @@ public function run(): void
'date' => time(),
'reference' => 'REF-TEST-005',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
// Prix vendeur de l'evenement de test (db/seeds/EventTarif.php : id_tarif = 3, price = 15)
'montant' => 15.0,
'genre' => Genre::Homme->value,
'nom' => 'Personne',
'prenom' => 'Paul',
Expand All @@ -103,7 +105,8 @@ public function run(): void
'date' => time(),
'reference' => 'REF-TEST-006',
'type_inscription' => Tarif::TYPE_2_DAYS_AFUP['id'],
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
// Prix vendeur de l'evenement de test (db/seeds/EventTarif.php : id_tarif = 3, price = 15)
'montant' => 15.0,
'genre' => Genre::Homme->value,
'nom' => 'Maurice',
'prenom' => 'Jean',
Expand Down Expand Up @@ -223,7 +226,7 @@ public function run(): void
],
[
'reference' => 'REF-TEST-004',
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'montant' => 15.0,
'date_reglement' => new \DateTime("2024-01-02")->getTimestamp(),
'type_reglement' => Ticket::PAYMENT_CREDIT_CARD,
'email' => 'sans@cotisation.fr',
Expand All @@ -242,7 +245,7 @@ public function run(): void
],
[
'reference' => 'REF-TEST-005',
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'montant' => 15.0,
'date_reglement' => new \DateTime("2024-01-02")->getTimestamp(),
'type_reglement' => Ticket::PAYMENT_CREDIT_CARD,
'nom' => 'Personne',
Expand All @@ -261,7 +264,7 @@ public function run(): void
],
[
'reference' => 'REF-TEST-006',
'montant' => Tarif::TYPE_2_DAYS_AFUP['default_price'],
'montant' => 15.0,
'date_reglement' => new \DateTime("2024-01-02")->getTimestamp(),
'type_reglement' => Ticket::PAYMENT_CREDIT_CARD,
'nom' => 'Maurice',
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -6328,7 +6328,7 @@
$ignoreErrors[] = [
'message' => '#^Cannot cast mixed to int\\.$#',
'identifier' => 'cast.int',
'count' => 3,
'count' => 4,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php',
];
$ignoreErrors[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ private function computeStatistics(EventStats $statistics, Event $event): array
$registered = $statistics->ticketType->registered[$ticketType] ?? 0;
$confirmed = $statistics->ticketType->confirmed[$ticketType] ?? 0;
$paying = $statistics->ticketType->paying[$ticketType] ?? 0;
$amount = $paying * $ticketOffer->price;
$realAmount = $statistics->ticketType->realAmounts[$ticketType] ?? 0.0;
$amount = $realAmount;

if ($registered) {
$computed[$ticketType] = [
'label' => $ticketOffer->name,
'registered' => $registered,
'confirmed' => $confirmed,
'paying' => $paying,
'amount' => $ticketOffer->price,
'amount' => $paying > 0 && $realAmount > 0 ? round($realAmount / $paying, 2) : $ticketOffer->price,
'payingAmount' => $amount,
'availableTickets' => $ticketOffer->availableTickets,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public function __construct(

/** @var list<int> */
public array $paying,

/** @var array<int, float> Montant réel encaissé ou en attente par type de tarif */
public array $realAmounts = [],
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ public function getStatsForTicketTypes(int $eventId, ?Datetime $from): TicketTyp
$paying[$row['type_inscription']] = $row['c'];
}

$queryBuilder = clone $baseQueryBuilder;
$queryBuilder
->select('type_inscription', 'SUM(montant) AS montant')
->andWhere('etat IN(:states)')
->setParameter('states', [Ticket::STATUS_PAID, Ticket::STATUS_WAITING], ArrayParameterType::INTEGER);
$statement = $queryBuilder->executeQuery();

$realAmounts = [];
foreach ($statement->fetchAllAssociative() as $row) {
if (is_numeric($row['montant'])) {
$realAmounts[(int) $row['type_inscription']] = (float) $row['montant'];
}
}

$queryBuilder = clone $baseQueryBuilder;
$statement = $queryBuilder->andWhere('etat NOT IN(:states)')
->setParameter('states', [Ticket::STATUS_CANCELLED, Ticket::STATUS_ERROR, Ticket::STATUS_DECLINED], ArrayParameterType::INTEGER)
Expand All @@ -85,7 +99,7 @@ public function getStatsForTicketTypes(int $eventId, ?Datetime $from): TicketTyp
$registered[$row['type_inscription']] = $row['c'];
}

return new TicketTypeStats($confirmed, $registered, $paying);
return new TicketTypeStats($confirmed, $registered, $paying, $realAmounts);
}

private function getStatsForDay(int $eventId, string $day, ?Datetime $from = null): DailyStats
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace AppBundle\IntegrationTests\Event\Model\Repository;

use Afup\Tests\Support\IntegrationTestCase;
use AppBundle\Event\Model\Repository\EventStatsRepository;
use AppBundle\Event\Model\Ticket;
use Doctrine\DBAL\Connection;

final class EventStatsRepositoryTest extends IntegrationTestCase
{
public function testRealAmountsIncludeBilleteriePriveeTickets(): void
{
$eventStatsRepository = self::getContainer()->get(EventStatsRepository::class);
$connection = self::getContainer()->get(Connection::class);

// Deux places via une billetterie privée : une réglée, une en attente de règlement
$this->insertInscription($connection, 'TOKEN-STATS-1', 'STATS-A', 42, Ticket::STATUS_PAID, 80.0);
$this->insertInscription($connection, 'TOKEN-STATS-1', 'STATS-B', 42, Ticket::STATUS_WAITING, 80.0);
// Une place annulée ne doit pas être comptée
$this->insertInscription($connection, 'TOKEN-STATS-1', 'STATS-C', 42, Ticket::STATUS_CANCELLED, 80.0);

$stats = $eventStatsRepository->getStatsForTicketTypes(42, null);

self::assertSame(2, $stats->paying[Ticket::TYPE_SPECIAL_PRICE] ?? 0);
self::assertSame(160.0, $stats->realAmounts[Ticket::TYPE_SPECIAL_PRICE] ?? 0.0);
}

private function insertInscription(
Connection $connection,
string $token,
string $reference,
int $forumId,
int $etat,
float $montant,
): void {
$connection->insert('afup_inscription_forum', [
'reference' => $reference,
'special_price_token' => $token,
'id_forum' => $forumId,
'etat' => $etat,
'type_inscription' => Ticket::TYPE_SPECIAL_PRICE,
'montant' => $montant,
'date' => time(),
]);
}
}
Loading