From e78d7409a7b29fa315bdb4f482800270e82754d2 Mon Sep 17 00:00:00 2001 From: LucileDT Date: Mon, 13 Jul 2020 13:47:32 +0200 Subject: [PATCH] Ref #215: set to null bank information if payment type does not need it on membership creation&edition --- src/Controller/MembershipController.php | 16 ++++++++++++++++ src/Entity/Payment.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Controller/MembershipController.php b/src/Controller/MembershipController.php index a6ad1310..76dd7389 100644 --- a/src/Controller/MembershipController.php +++ b/src/Controller/MembershipController.php @@ -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); @@ -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()); diff --git a/src/Entity/Payment.php b/src/Entity/Payment.php index 5960d444..da5b0dc4 100644 --- a/src/Entity/Payment.php +++ b/src/Entity/Payment.php @@ -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.'); }