Skip to content

Commit

Permalink
Ref #215: set to null bank information if payment type does not need …
Browse files Browse the repository at this point in the history
…it on membership creation&edition
  • Loading branch information
LucileDT committed Jul 13, 2020
1 parent 8362be3 commit e78d740
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Controller/MembershipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ public function createAction(Request $request, TranslatorInterface $translator)
$payment->setAmount($updateMembershipFDO->getPaymentAmount());
$payment->setDateReceived($updateMembershipFDO->getPaymentDateReceived());
$payment->setDateCashed($updateMembershipFDO->getPaymentDateCashed());
if ($payment->getType()->isBankneeded())
{
$payment->setBank($updateMembershipFDO->getBank());
}
else
{
$payment->setBank(null);
}

$payment->setPayer($updateMembershipFDO->getPayer());
$payment->setMembership($membership);
Expand Down Expand Up @@ -236,6 +244,14 @@ public function editAction(Membership $membership, Request $request, TranslatorI
$payment->setAmount($updateMembershipFDO->getPaymentAmount());
$payment->setDateReceived($updateMembershipFDO->getPaymentDateReceived());
$payment->setDateCashed($updateMembershipFDO->getPaymentDateCashed());
if ($payment->getType()->isBankneeded())
{
$payment->setBank($updateMembershipFDO->getBank());
}
else
{
$payment->setBank(null);
}

$payment->setPayer($updateMembershipFDO->getPayer());

Expand Down
4 changes: 2 additions & 2 deletions src/Entity/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ function getBank()
* @throws \Exception If bank information is not needed in the
* corresponding payment type, throws an exception
*/
function setBank(Bank $bank): self
function setBank(?Bank $bank): self
{
if (!$this->type->isBankneeded())
if (!$this->type->isBankneeded() && !is_null($bank))
{
throw new \Exception('Bank information is not needed in this payment.');
}
Expand Down

0 comments on commit e78d740

Please sign in to comment.