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(); } }
protected function setRealCreditTvaAReporter() { $em = $this->getDoctrine()->getManager(); $rapState = $em->getRepository('ApplicationSonataClientOperationsBundle:RapprochementState')->findOneBy(array('client_id' => $this->_client_id, 'month' => $this->_month, 'year' => $this->_year)); if (!$rapState) { $rapState = new RapprochementState(); $rapState->setClientId($this->_client_id)->setMonth($this->_month)->setYear($this->_year); } $clientDeclaration = new ClientDeclaration($this->_client); $clientDeclaration->setYear($this->_year)->setMonth($this->_month); $clientDeclarationComputation = new ClientDeclarationComputation($clientDeclaration); $realCreditTvaAReporter = $clientDeclarationComputation->getCreditOfVATCarriedForward(); $rapState->setRealCreditTvaAReporter($realCreditTvaAReporter); $em->persist($rapState); $em->flush(); }