/**
  * @return ErrorElements
  */
 public function validateTauxDeChange()
 {
     /** @var $_object \Application\Sonata\ClientOperationsBundle\Entity\A02TVA|\Application\Sonata\ClientOperationsBundle\Entity\V01TVA */
     $_object = $this->_object;
     //-- http://redmine.testenm.com/issues/1364#note-9
     //if ($_object->getPaiementMontant() && !$_object->getTauxDeChange()) {
     if (!$_object->getTauxDeChange()) {
         $listDevise = null;
         if (method_exists($_object, 'getPaiementDevise')) {
             $listDevise = $_object->getPaiementDevise();
         } else {
             if (method_exists($_object, 'getDevise')) {
                 $listDevise = $_object->getDevise();
             }
         }
         $date = null;
         if (method_exists($_object, 'getPaiementDate')) {
             $date = $_object->getPaiementDate();
         } else {
             if (method_exists($_object, 'getDatePiece')) {
                 $date = $_object->getDatePiece();
             }
         }
         if ($listDevise && $date) {
             $currency = $listDevise->getAlias();
             $taux_de_change = 0;
             if ($currency == static::Device) {
                 $taux_de_change = 1;
             } else {
                 //                     /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */
                 //                     $doctrine = \AppKernel::getStaticContainer()->get('doctrine');
                 //                     /* @var $em \Doctrine\ORM\EntityManager */
                 //                     $em = $doctrine->getManager();
                 //                     /* @var $devise \Application\Sonata\DevisesBundle\Entity\Devises */
                 //                     $devise = $em->getRepository('ApplicationSonataDevisesBundle:Devises')->findOneByDate($_object->getPaiementDate());
                 //                     if ($devise) {
                 //                         $method = 'getMoney' . $currency;
                 //                         if (method_exists($devise, $method)) {
                 //                             $taux_de_change = $devise->$method();
                 //                         } else {
                 //                             new \Exception('Currency is not found (Devises): ' . $method);
                 //                         }
                 //                     }
                 $taux_de_change = Devises::getDevisesValue($listDevise->getId(), $date);
             }
             // setTauxDeChange
             $_object->setTauxDeChange($taux_de_change);
             if (!$taux_de_change) {
                 $this->_errorElement->with('taux_de_change')->addViolation('"Taux de change" non valide ' . $taux_de_change)->end();
             }
         }
     }
     return $this;
 }
 /**
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function RDevisesAction()
 {
     $devise_id = $this->getRequest()->request->get('devise');
     $date_piece = $this->getRequest()->request->get('date');
     if (!$devise_id && !$date_piece) {
         throw new NotFoundHttpException('Must be devise and date_piece');
     }
     $value = Devises::getDevisesValue($devise_id, \DateTime::createFromFormat('d/m/Y', $date_piece));
     return $this->renderJson(array('value' => $value));
 }