Skip to content

Commit

Permalink
Update fixtures:
Browse files Browse the repository at this point in the history
- #215: remove bank information where not needed
- add more donations
- rework of payment dates to be able to diplay nice stats on home page
  • Loading branch information
LucileDT committed Jul 13, 2020
1 parent d826384 commit 8362be3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 30 deletions.
61 changes: 39 additions & 22 deletions src/DataFixtures/DonationFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,47 @@ public function load(ObjectManager $manager)
$people = $peopleRepository->findAll();
$paymentTypeCheck = $paymentTypeRepository->findOneBy(['label' => 'Chèque']);

foreach ($people as $index => $individual)
for ($i = 0 ; $i < 5 ; $i++)
{
if ($index % 3 == 0)
foreach ($people as $index => $individual)
{
$amountDonation = (float) rand (20, 1000);
$dateDonation = rand (2017, 2019) . '-02-15 ' . rand (10, 23) . ':00:00';

$paymentDonationCheque = new Payment();
$paymentDonationCheque->setAmount($amountDonation);
$paymentDonationCheque->setType($paymentTypeCheck);
$paymentDonationCheque->setDateReceived(new \DateTime($dateDonation));
$paymentDonationCheque->setPayer($individual);

$bank = $banks[rand(0, $banksCount - 1)];
$paymentDonationCheque->setBank($bank);

$manager->persist($paymentDonationCheque);

$donation = new Donation();
$donation->setAmount($amountDonation);
$donation->setDonationDate(new \DateTime($dateDonation));
$donation->setDonator($individual);
$donation->setPayment($paymentDonationCheque);
$manager->persist($donation);
// Only create donations of 1/3 people
if ($index % 3 == 0)
{
// Create donations of amount between 5 and 200€
$amountDonation = (float) rand (5, 200);
// Create donation between this year and two years ago
$currentDate = new \DateTime();
$currentYear = date('Y', $currentDate->getTimestamp());
$yearTwoYearsAgo = date('Y', strtotime('-2 years', $currentDate->getTimestamp()));
$dateDonation = rand ($yearTwoYearsAgo, $currentYear)
. '-'
. rand (01, 12)
. '-'
. rand (01, 28)
. ' '
. rand (10, 23)
. ':00:00';

$paymentDonationCheque = new Payment();
$paymentDonationCheque->setAmount($amountDonation);
$paymentDonationCheque->setType($paymentTypeCheck);
$paymentDonationCheque->setDateReceived(new \DateTime($dateDonation));
$paymentDonationCheque->setDateCashed(new \DateTime($dateDonation));
$paymentDonationCheque->setPayer($individual);

$bank = $banks[rand(0, $banksCount - 1)];
$paymentDonationCheque->setBank($bank);

$manager->persist($paymentDonationCheque);

$donation = new Donation();
$donation->setAmount($amountDonation);
$donation->setDonationDate(new \DateTime($dateDonation));
$donation->setDonator($individual);
$donation->setPayment($paymentDonationCheque);
$manager->persist($donation);
}
}
}
$manager->flush();
Expand Down
14 changes: 6 additions & 8 deletions src/DataFixtures/MembershipFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public function load(ObjectManager $manager)
$paymentAdhesionHelloAsso30->setType($paymentTypeHelloAsso);
$paymentAdhesionHelloAsso30->setDateReceived(new \DateTime('2017-01-18 14:36:03'));
$paymentAdhesionHelloAsso30->setDateCashed(new \DateTime('2017-01-18 14:36:03'));
$bank = $banks[rand(0, $banksCount - 1)];
$paymentAdhesionHelloAsso30->setBank($bank);

$manager->persist($paymentAdhesionHelloAsso30);

Expand All @@ -91,8 +89,6 @@ public function load(ObjectManager $manager)
$paymentAdhesionCash20->setType($paymentTypeCash);
$paymentAdhesionCash20->setDateReceived(new \DateTime('2019-10-27 12:21:09'));
$paymentAdhesionCash20->setDateCashed(new \DateTime('2019-10-27 12:21:09'));
$bank = $banks[rand(0, $banksCount - 1)];
$paymentAdhesionCash20->setBank($bank);

$manager->persist($paymentAdhesionCash20);

Expand All @@ -103,8 +99,6 @@ public function load(ObjectManager $manager)
$paymentAdhesionCard20->setType($paymentTypeCard);
$paymentAdhesionCard20->setDateReceived(new \DateTime('2018-05-11 08:28:09'));
$paymentAdhesionCard20->setDateCashed(new \DateTime('2018-05-11 08:28:09'));
$bank = $banks[rand(0, $banksCount - 1)];
$paymentAdhesionCard20->setBank($bank);


// Fifth payment (transfer)
Expand All @@ -113,8 +107,6 @@ public function load(ObjectManager $manager)
$paymentAdhesionTransfer20->setType($paymentTypeTransfer);
$paymentAdhesionTransfer20->setDateReceived(new \DateTime('2018-04-25 10:59:02'));
$paymentAdhesionTransfer20->setDateCashed(new \DateTime('2018-04-25 10:59:02'));
$bank = $banks[rand(0, $banksCount - 1)];
$paymentAdhesionTransfer20->setBank($bank);

$manager->persist($paymentAdhesionTransfer20);

Expand Down Expand Up @@ -232,6 +224,12 @@ public function load(ObjectManager $manager)

// Card payment generated for this membership
$payment = clone $paymentAdhesionCard20;
// Change date received and date cashed to add more diversity and cohesion
$days = rand(1, 200);
$paymentDateTimestamp = strtotime('-' . $days . ' days', $now->getTimestamp());
$paymentDate = new \DateTime('@' . $paymentDateTimestamp);
$payment->setDateReceived($paymentDate);
$payment->setDateCashed($paymentDate);

// Create and associate active and inactive memberships evenly on members
if ($index % 2 == 0)
Expand Down

0 comments on commit 8362be3

Please sign in to comment.