/** * @param Request $request * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response * * @Route("/accounting/add", * name="app_accounting_add", * methods={"GET","POST"}) */ public function addAction(Request $request) { // Transaction $transaction = new Transaction(); $transaction->addDetail(new TransactionDetail()); // Edit form $formEdit = $this->createForm(TransactionType::class, $transaction); $formEdit->handleRequest($request); if ($formEdit->isSubmitted() && $formEdit->isValid()) { // Save data $tm = $this->get('app.transaction_manager'); $tm->update($transaction, $formEdit); // Flash message $this->addFlash('success', $this->get('translator')->trans('add.success.added', [], 'accounting')); // Redirect if (!is_null($request->request->get('add_and_close'))) { return $this->redirectToRoute('app_accounting_homepage'); } elseif (!is_null($request->request->get('add_and_new'))) { return $this->redirectToRoute('app_accounting_add'); } else { return $this->redirectToRoute('app_accounting_edit', ['transaction' => $transaction->getId()]); } } // Render return $this->render('accounting/add.html.twig', ['formEdit' => $formEdit->createView()]); }
/** * @param User $user * * @throws PersisterException * @throws \Exception */ public function createUser(User $user) { $user->setUsername($user->getEmail()); try { $transaction = new Transaction(); $transaction->setAmount(0); $transaction->setDate(new \DateTime(date("Y-m-d H:i:s"))); $transaction->setOperation('Ouverture du compte'); $transaction->setTotalMoney(0); $user->addTransaction($transaction); $this->userDao->persist($user); } catch (PersisterException $e) { throw $e; } }