Skip to content

Commit

Permalink
Ref #215: create bank fixtures and update existing payments
Browse files Browse the repository at this point in the history
  • Loading branch information
LucileDT committed Jul 12, 2020
1 parent 054022e commit 785ad21
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
59 changes: 59 additions & 0 deletions src/DataFixtures/BankFixtures.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Console\Output\ConsoleOutput;
use App\Entity\Bank;

class BankFixtures extends Fixture implements FixtureGroupInterface
{
public function __construct()
{
}

public static function getGroups(): array
{
return ['banks'];
}

public function load(ObjectManager $manager)
{
// Create logger used to display information messages
$output = new ConsoleOutput();

// Create pool of banks
$output->writeln(' <comment>></comment> <info>Banks creation...</info>');
$bankRepository = $manager->getRepository(Bank::class);

$bank = new Bank();
$bank->setName('Société Générale');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('BNP Paribas');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('La Banque Postale');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('HSBC');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('LCL');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('Allianz Banque');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('AXA Banque');
$manager->persist($bank);
$bank = new Bank();
$bank->setName('Groupama Banque');
$manager->persist($bank);

$manager->flush();
$output->writeln(' <comment>></comment> <info>Banks creation complete</info>');
}
}
14 changes: 12 additions & 2 deletions src/DataFixtures/DonationFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use App\Entity\People;
use App\Entity\Bank;
use App\Entity\Donation;
use App\Entity\Membership;
use App\Entity\MembershipType;
use App\Entity\Payment;
use App\Entity\PaymentType;
use App\Entity\Donation;
use App\Entity\People;

class DonationFixtures extends Fixture implements FixtureGroupInterface, DependentFixtureInterface
{
Expand All @@ -35,6 +36,10 @@ public function load(ObjectManager $manager)
$output->writeln(' <comment>></comment> <info>Donations linked to membership payments creation...</info>');
$paymentTypeRepository = $manager->getRepository(PaymentType::class);

$bankRepository = $manager->getRepository(Bank::class);
$banks = $bankRepository->findAll();
$banksCount = count($banks);

$paymentsTooBig = $paymentTypeRepository->findByAmountTooBigForMembership();
foreach ($paymentsTooBig as $payment)
{
Expand Down Expand Up @@ -68,6 +73,10 @@ public function load(ObjectManager $manager)
$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();
Expand All @@ -87,6 +96,7 @@ public function getDependencies()
return array(
UserFixtures::class,
MembershipFixtures::class,
BankFixtures::class,
);
}
}
18 changes: 16 additions & 2 deletions src/DataFixtures/MembershipFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use App\Entity\People;
use App\Entity\Bank;
use App\Entity\Membership;
use App\Entity\MembershipType;
use App\Entity\Payment;
use App\Entity\PaymentType;
use App\Entity\People;

class MembershipFixtures extends Fixture implements FixtureGroupInterface, DependentFixtureInterface
{
Expand All @@ -32,6 +33,10 @@ public function load(ObjectManager $manager)

// Creating MembershipType
$output->writeln(' <comment>></comment> <info>Membership types creation...</info>');
$bankRepository = $manager->getRepository(Bank::class);
$banks = $bankRepository->findAll();
$banksCount = count($banks);

$MembershipTypeFamily = new MembershipType();
$MembershipTypeFamily->setDefaultAmount(30.0);
$MembershipTypeFamily->setLabel('Famille');
Expand Down Expand Up @@ -64,6 +69,8 @@ public function load(ObjectManager $manager)
$paymentAdhesionCheque50->setType($paymentTypeCheck);
$paymentAdhesionCheque50->setDateReceived(new \DateTime('2017-02-17 16:01:57'));
$paymentAdhesionCheque50->setDateCashed(new \DateTime('2017-02-17 16:01:57'));
$bank = $banks[rand(0, $banksCount - 1)];
$paymentAdhesionCheque50->setBank($bank);

$manager->persist($paymentAdhesionCheque50);

Expand All @@ -73,6 +80,8 @@ 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 @@ -82,6 +91,8 @@ 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 @@ -92,7 +103,8 @@ 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 @@ -101,6 +113,8 @@ 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

0 comments on commit 785ad21

Please sign in to comment.