Skip to content

Commit

Permalink
Ref #215: check if bank information is needed when setting one to a p…
Browse files Browse the repository at this point in the history
…ayment
  • Loading branch information
LucileDT committed Jul 13, 2020
1 parent cc20cd0 commit d826384
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Entity/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,20 @@ function getBank()
return $this->bank;
}

/**
* Set Bank for this payment
*
* @param \App\Entity\Bank $bank Bank to set for this payment
* @return \self
* @throws \Exception If bank information is not needed in the
* corresponding payment type, throws an exception
*/
function setBank(Bank $bank): self
{
if (!$this->type->isBankneeded())
{
throw new \Exception('Bank information is not needed in this payment.');
}
$this->bank = $bank;

return $this;
Expand Down
22 changes: 22 additions & 0 deletions src/Entity/PaymentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ class PaymentType
*/
private $payments;

/**
* Boolean to check in the Payment of this type if Bank information
* is needed.
*
* @var boolean True is Bank is needed in payment, false otherwise
*
* @ORM\Column(type="boolean", length=255)
*/
private $isBankneeded;

public function __construct()
{
$this->payments = new ArrayCollection();
Expand Down Expand Up @@ -100,4 +110,16 @@ public function removePayment(Payment $payment): self

return $this;
}

function isBankneeded(): bool
{
return $this->isBankneeded;
}

function setIsBankneeded(bool $isBankneeded): self
{
$this->isBankneeded = $isBankneeded;

return $this;
}
}
37 changes: 37 additions & 0 deletions src/Migrations/Version20200713102639.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20200713102639 extends AbstractMigration
{
public function getDescription() : string
{
return 'Add boolean to payment type to check if Bank information is needed in payment.';
}

public function up(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE payment_type ADD is_bankneeded TINYINT(1) NOT NULL');

// Bank information is only needed in payment of type Check
$this->addSql('UPDATE payment_type SET is_bankneeded = 0 WHERE id = 1');
$this->addSql('UPDATE payment_type SET is_bankneeded = 0 WHERE id = 2');
$this->addSql('UPDATE payment_type SET is_bankneeded = 0 WHERE id = 3');
$this->addSql('UPDATE payment_type SET is_bankneeded = 1 WHERE id = 4');
$this->addSql('UPDATE payment_type SET is_bankneeded = 0 WHERE id = 5');
}

public function down(Schema $schema) : void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE payment_type DROP is_bankneeded');
}
}

0 comments on commit d826384

Please sign in to comment.