From 8362be382dc8507a8025d15a3cbce1bf9b47aea3 Mon Sep 17 00:00:00 2001 From: LucileDT Date: Mon, 13 Jul 2020 13:39:18 +0200 Subject: [PATCH] Update fixtures: - #215: remove bank information where not needed - add more donations - rework of payment dates to be able to diplay nice stats on home page --- src/DataFixtures/DonationFixtures.php | 61 ++++++++++++++++--------- src/DataFixtures/MembershipFixtures.php | 14 +++--- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/DataFixtures/DonationFixtures.php b/src/DataFixtures/DonationFixtures.php index e4d98e6f..f1af01ff 100644 --- a/src/DataFixtures/DonationFixtures.php +++ b/src/DataFixtures/DonationFixtures.php @@ -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(); diff --git a/src/DataFixtures/MembershipFixtures.php b/src/DataFixtures/MembershipFixtures.php index 888d0f9a..b7a86836 100644 --- a/src/DataFixtures/MembershipFixtures.php +++ b/src/DataFixtures/MembershipFixtures.php @@ -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); @@ -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); @@ -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) @@ -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); @@ -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)