/**
  * @param $client_id
  * @param $month
  * @param $year
  * @param int $blocked
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function lockingAction($client_id, $month, $year, $blocked = 1)
 {
     list($_month, $_year) = $this->admin->getQueryMonth($month);
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getDoctrine()->getManager();
     $locking = $em->getRepository('ApplicationSonataClientOperationsBundle:Locking')->findOneBy(array('client_id' => $client_id, 'month' => $_month, 'year' => $_year));
     if ($locking) {
         $status_id = 2;
     }
     if ($blocked) {
         $status_id = 1;
     }
     if ($status_id == 1 && !$this->acceptLocking($client_id, $month)) {
         $this->get('session')->setFlash('sonata_flash_error', 'Cloture Mois-TVA ' . $_year . '-' . $_month . ' impossible car au moins une opération n\'a pas été prise en compte sur une des Ca3 précédente dans : ' . $this->_lockingTab . ' - ' . $this->datefmtFormatFilter($this->_lockingDate, 'YYYY MMMM'));
         return $this->redirect($this->generateUrl('admin_sonata_clientoperations_' . $this->_tabAlias . '_list', array('filter' => array('client_id' => array('value' => $client_id)), 'month' => $month)));
     }
     if ($status_id == 2 && !$this->acceptUnlocking($client_id, $month)) {
         $this->get('session')->setFlash('sonata_flash_error', 'Le mois ' . $this->_unlockingYear . '-' . $this->_unlockingMonth . ' est déjà vérouillé, vous ne pouvez donc pas dévérouillé le mois sélectionné.');
         return $this->redirect($this->generateUrl('admin_sonata_clientoperations_' . $this->_tabAlias . '_list', array('filter' => array('client_id' => array('value' => $client_id)), 'month' => $month)));
     }
     if ($locking) {
         $em->remove($locking);
         $em->flush();
     }
     if ($blocked) {
         $locking = new Locking();
         $locking->setClientId($client_id);
         $locking->setMonth($_month);
         $locking->setYear($_year);
         $em->persist($locking);
         $em->flush();
     }
     $status = $em->getRepository('ApplicationSonataClientOperationsBundle:ListStatuses')->find($status_id);
     if ($status) {
         foreach ($this->_config_excel as $table => $params) {
             $objects = $em->getRepository('ApplicationSonataClientOperationsBundle:' . $params['entity'])->createQueryBuilder('o')->where('o.mois BETWEEN :from_date AND :to_date')->andWhere('o.client_id = :client_id')->setParameter(':from_date', $_year . '-' . $_month . '-01')->setParameter(':to_date', $_year . '-' . $_month . '-31')->setParameter(':client_id', $client_id)->getQuery()->getResult();
             foreach ($objects as $obj) {
                 /** @var $obj \Application\Sonata\ClientOperationsBundle\Entity\AbstractBaseEntity */
                 $obj->setStatus($status);
                 $em->persist($obj);
                 $em->flush();
             }
             unset($objects);
         }
     }
     return $this->redirect($this->generateUrl('admin_sonata_clientoperations_' . $this->_tabAlias . '_list', array('filter' => array('client_id' => array('value' => $client_id)), 'month' => $month)));
 }
 public function setLocking()
 {
     /* @var $em \Doctrine\ORM\EntityManager */
     $em = $this->getDoctrine()->getManager();
     $locking = $em->getRepository('ApplicationSonataClientOperationsBundle:Locking')->findOneBy(array('client_id' => $this->_client_id, 'month' => $this->_month, 'year' => $this->_year));
     if ($locking) {
         $em->remove($locking);
         $em->flush();
         $status_id = 2;
     }
     if ($this->_blocked) {
         $locking = new Locking();
         $locking->setClientId($this->_client_id);
         $locking->setMonth($this->_month);
         $locking->setYear($this->_year);
         $em->persist($locking);
         $em->flush();
         $status_id = 1;
     }
     $status = $em->getRepository('ApplicationSonataClientOperationsBundle:ListStatuses')->find($status_id);
     if ($status) {
         foreach ($this->_config_excel as $table => $params) {
             $objects = $em->getRepository('ApplicationSonataClientOperationsBundle:' . $params['entity'])->createQueryBuilder('o')->where('o.mois BETWEEN :from_date AND :to_date')->andWhere('o.client_id = :client_id')->setParameter(':from_date', $this->_year . '-' . $this->_month . '-01')->setParameter(':to_date', $this->_year . '-' . $this->_month . '-31')->setParameter(':client_id', $this->_client_id)->getQuery()->getResult();
             foreach ($objects as $obj) {
                 /** @var $obj \Application\Sonata\ClientOperationsBundle\Entity\AbstractBaseEntity */
                 $obj->setStatus($status);
                 $em->persist($obj);
                 $em->flush();
             }
             unset($objects);
         }
     }
 }