Skip to content

Commit

Permalink
Ref #215: save bank on donation creation and edition
Browse files Browse the repository at this point in the history
  • Loading branch information
LucileDT committed Dec 13, 2020
1 parent 6790fa2 commit b151047
Showing 1 changed file with 36 additions and 19 deletions.
55 changes: 36 additions & 19 deletions src/Controller/DonationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b151047

Please sign in to comment.