diff --git a/src/Controller/DonationController.php b/src/Controller/DonationController.php index daae6fbd..3bcb3507 100644 --- a/src/Controller/DonationController.php +++ b/src/Controller/DonationController.php @@ -36,34 +36,42 @@ public function listAction(DonationRepository $donationRepository): Response */ public function new(Request $request): Response { - $updateDonationFDO = new UpdateDonationFDO(); + $createDonationFDO = new UpdateDonationFDO(); - $form = $this->createForm(DonationType::class, $updateDonationFDO); + $form = $this->createForm(DonationType::class, $createDonationFDO); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); - $donator = $updateDonationFDO->getDonator(); + $donator = $createDonationFDO->getDonator(); // -- DONATION -- // $donation = new Donation(); - $donation->setAmount($updateDonationFDO->getAmount()); + $donation->setAmount($createDonationFDO->getAmount()); $donation->setDonator($donator); - $donation->setDonationDate($updateDonationFDO->getDonationDate()); + $donation->setDonationDate($createDonationFDO->getDonationDate()); // -- PAYMENT -- // $payment = new Payment(); $payment->setPayer($donator); - $payment->setType($updateDonationFDO->getPaymentType()); - $payment->setAmount($updateDonationFDO->getAmount()); - $payment->setDateReceived($updateDonationFDO->getDonationDate()); - $payment->setDateCashed($updateDonationFDO->getCashedDate()); - $payment->setComment($updateDonationFDO->getComment()); + $payment->setType($createDonationFDO->getPaymentType()); + $payment->setAmount($createDonationFDO->getAmount()); + $payment->setDateReceived($createDonationFDO->getDonationDate()); + $payment->setDateCashed($createDonationFDO->getCashedDate()); + if ($payment->getType()->isBankneeded()) + { + $payment->setBank($createDonationFDO->getBank()); + } + else + { + $payment->setBank(null); + } + $payment->setComment($createDonationFDO->getComment()); $em->persist($payment); @@ -110,27 +118,36 @@ public function show(Donation $donation): Response */ public function edit(Request $request, Donation $donation): Response { - $updatePeopleDataFDO = new UpdateDonationFDO($donation); + $updateDonationFDO = new UpdateDonationFDO($donation); - $form = $this->createForm(DonationType::class, $updatePeopleDataFDO); + $form = $this->createForm(DonationType::class, $updateDonationFDO); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); - $donator = $updatePeopleDataFDO->getDonator(); + $donator = $updateDonationFDO->getDonator(); - $donation->setAmount($updatePeopleDataFDO->getAmount()); + $donation->setAmount($updateDonationFDO->getAmount()); $donation->setDonator($donator); - $donation->setDonationDate($updatePeopleDataFDO->getDonationDate()); + $donation->setDonationDate($updateDonationFDO->getDonationDate()); $payment = $donation->getPayment(); $payment->setPayer($donator); - $payment->setType($updatePeopleDataFDO->getPaymentType()); - $payment->setAmount($updatePeopleDataFDO->getAmount()); - $payment->setDateReceived($updatePeopleDataFDO->getDonationDate()); - $payment->setDateCashed($updatePeopleDataFDO->getCashedDate()); + $payment->setType($updateDonationFDO->getPaymentType()); + $payment->setAmount($updateDonationFDO->getAmount()); + $payment->setDateReceived($updateDonationFDO->getDonationDate()); + $payment->setDateCashed($updateDonationFDO->getCashedDate()); + if ($payment->getType()->isBankneeded()) + { + $payment->setBank($updateDonationFDO->getBank()); + } + else + { + $payment->setBank(null); + } + $payment->setComment($updateDonationFDO->getComment()); $em->persist($payment); $em->persist($donation);