/** * Creates a new exchangeRateUSD entity. * * @Route("/new", name="admin_exchangeRateUSD_new") * @Method({"GET", "POST"}) */ public function newAction(Request $request) { $exchangeRateUSD = new ExchangeRateUSD(); $exchangeRateUSD->setDate(new \DateTime('today')); $exchangeRateUSD->setExpiration(new \DateTime('today')); $form = $this->createForm('TS\\CYABundle\\Form\\exchangeRateUSDType', $exchangeRateUSD); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($exchangeRateUSD); $em->flush(); $this->get('session')->getFlashBag()->set('exito', 'Registro agregado correctamente'); return $this->redirectToRoute('admin_exchangeRateUSD_show', array('id' => $exchangeRateUSD->getId())); } return $this->render('exchangerateusd/new.html.twig', array('exchangeRateUSD' => $exchangeRateUSD, 'form' => $form->createView())); }
public function isNearbyToExpire(ExchangeRateUSD $exchangeRateUSD, \DateTime $today) { $expirationDay = $exchangeRateUSD->getExpiration(); if ($today->format('m-Y') === $expirationDay->format('m-Y')) { $expirationDays = $expirationDay->format('d') - $today->format('d'); if ($expirationDays <= 3) { return ["name" => $exchangeRateUSD->getCoin()->getName(), "code" => $exchangeRateUSD->getCoin()->getCode(), "symbol" => $exchangeRateUSD->getCoin()->getSymbol(), "days" => $expirationDays]; } } $curdate = strtotime($today->format('d-m-Y')); $mydate = strtotime($expirationDay->format('d-m-Y')); if ($curdate > $mydate) { return ["name" => $exchangeRateUSD->getCoin()->getName(), "code" => $exchangeRateUSD->getCoin()->getCode(), "symbol" => $exchangeRateUSD->getCoin()->getSymbol(), "days" => 0]; } return false; }