protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->em = $this->getContainer()->get('doctrine')->getManager();
     $locks = $this->em->getRepository('ApplicationSonataClientOperationsBundle:Locking')->findBy(array(), array('year' => 'ASC', 'month' => 'ASC', 'client_id' => 'ASC'));
     $clients = $clientDeclarations = $clientDeclarationComputations = array();
     foreach ($locks as $lock) {
         $rapState = $this->em->getRepository('ApplicationSonataClientOperationsBundle:RapprochementState')->findOneBy(array('client_id' => $lock->getClientId(), 'month' => $lock->getMonth(), 'year' => $lock->getYear()));
         if (!$rapState) {
             $rapState = new RapprochementState();
             $rapState->setClientId($lock->getClientId())->setMonth($lock->getMonth())->setYear($lock->getYear());
         }
         $key = sha1($lock->getClientId() . $lock->getYear() . $lock->getMonth());
         if (!isset($clients[$key])) {
             $client = $this->em->getRepository('ApplicationSonataClientBundle:Client')->findOneBy(array('id' => $lock->getClientId()));
             if (!$client) {
                 continue;
             }
             $clients[$key] = $client;
         }
         if (!isset($clientDeclarations[$key])) {
             $clientDeclaration = new ClientDeclaration($clients[$key]);
             $clientDeclaration->setYear($lock->getYear())->setMonth($lock->getMonth());
             $clientDeclarations[$key] = $clientDeclaration;
             $clientDeclarationComputations[$key] = new ClientDeclarationComputation($clientDeclaration);
         }
         $realCreditTvaAReporter = $clientDeclarationComputations[$key]->getCreditOfVATCarriedForward();
         $rapState->setRealCreditTvaAReporter($realCreditTvaAReporter);
         $this->em->persist($rapState);
         $this->em->flush();
     }
 }
 public function frameAction($client_id, $month)
 {
     $this->validateParams($client_id, $month);
     $em = $this->get('doctrine')->getEntityManager();
     $rap = $em->getRepository('ApplicationSonataClientOperationsBundle:RapprochementState')->findOneBy(array('client_id' => $this->_client_id, 'month' => $this->_month, 'year' => $this->_year));
     if (!$rap) {
         $rap = new RapprochementState();
     }
     $clientDeclaration = $this->_client->getDeclaration($this->_year, $this->_month);
     $request = $this->get('request');
     //$this->exportExcelDeclaration();
     //exit;
     if ($request->getMethod() == 'POST') {
         $rap->setClientId((int) $this->_client_id)->setMonth($this->_month)->setYear($this->_year);
         if ($_POST['type'] == 'ddr') {
             $rap->setDemandeDeRemboursement((double) $_POST['number']);
         } elseif ($_POST['type'] == 'ctar') {
             $rap->setCreditTvaAReporter((double) $_POST['number']);
         }
         $em->persist($rap);
         $em->flush();
         //$this->_setAlert($client_id);
         return $this->render(':redirects:back.html.twig');
     }
     return $this->render('ApplicationSonataClientOperationsBundle:Rapprochement:frame.html.twig', array('client_id' => $this->_client_id, 'client' => $this->_client, 'clientDeclaration' => $clientDeclaration, 'month' => $this->_month, 'year' => $this->_year, 'blocked' => $this->_blocked, 'rapState' => $rap, 'declarationLink' => $this->generateUrl('admin_sonata_clientoperations_v01tva_declaration', array('filter' => array('client_id' => array('value' => $this->_client_id)), 'month' => $this->_query_month)), 'exporterDebLink' => $this->generateUrl('admin_sonata_clientoperations_v01tva_exportTransDeb', array('filter' => array('client_id' => array('value' => $this->_client_id)), 'month' => $this->_query_month)), 'ajaxLink' => $this->generateUrl('rapprochement_frame_ajax')));
 }