protected function execute(InputInterface $input, OutputInterface $output) { $this->container = $this->getContainer(); $this->em = $this->getContainer()->get('doctrine')->getManager(); //$this->em->getConnection()->getConfiguration()->setSQLLogger(null); $this->formCSRF = $this->container->get('form.csrf_provider'); $this->adminPool = $this->container->get('sonata.admin.pool'); $this->user = $this->em->getRepository('ApplicationSonataUserBundle:User')->findOneBy(array('id' => $input->getArgument('user_id'))); $this->translator = \AppKernel::getStaticContainer()->get('translator'); $token = new UsernamePasswordToken($this->user, $this->user->getPassword(), "public", $this->user->getRoles()); $this->getContainer()->get("security.context")->setToken($token); // Fire the login event $event = new InteractiveLoginEvent($this->getContainer()->get('request'), $token); $this->getContainer()->get("event_dispatcher")->dispatch("security.interactive_login", $event); $this->targetProcess = $input->getArgument('target'); $this->user_id = $input->getArgument('user_id'); $this->pid = $input->getArgument('pid'); $file = $input->getArgument('file'); $objReader = \PHPExcel_IOFactory::createReaderForFile($file); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($file); $sheet = $objPHPExcel->getSheet(0); $rows = $sheet->toArray(); $this->processClient($rows); $this->messages = $this->getCountMessageImports(); $this->sendNotification(); echo serialize(array('messages' => $this->messages, 'import_counts' => $this->_import_counts, 'pid' => $this->pid, 'absErrorLogFilename' => $this->absErrorLogFilename)); }
/** * {@inheritdoc} */ public function createQueryBuilder($alias) { $queryBuilder = parent::createQueryBuilder($alias); /* @var $securityContext SecurityContext */ $securityContext = \AppKernel::getStaticContainer()->get('security.context'); if (!$securityContext->isGranted('ROLE_SUPER_ADMIN')) { $queryBuilder->where($alias . '.id != :admin_id')->setParameter(':admin_id', 1); } return $queryBuilder; }
/** * {@inheritdoc} */ public function createQueryBuilder($alias) { $queryBuilder = parent::createQueryBuilder($alias); /* @var $securityContext SecurityContext */ $securityContext = \AppKernel::getStaticContainer()->get('security.context'); if (!$securityContext->isGranted('ROLE_EDIT_ALL_CLIENTS')) { $queryBuilder->where($alias . '.user = :user')->setParameter(':user', $securityContext->getToken()->getUser()); } return $queryBuilder; }
/** * @return ListDevises */ public static function getDefault() { if (is_null(static::$default)) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); static::$default = $em->getRepository('ApplicationSonataClientBundle:ListDevises')->findOneByAlias(static::Device); } return static::$default; }
public function __construct() { parent::__construct(); /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); $this->setEnabled(true); $group = $em->getRepository('ApplicationSonataUserBundle:Group')->find(static::GroupId); if ($group) { $this->addGroup($group); } }
public function __construct($client, $show_all_operations, $year, $month, $excel = null) { if (is_null($excel)) { $this->_excel = new \PHPExcel(); } else { $this->_excel = $excel; } $this->translator = \AppKernel::getStaticContainer()->get('translator'); $this->_client = $client; $this->_show_all_operations = $show_all_operations; $this->_year = $year; $this->_month = $month; $this->clientDeclaration = new ClientDeclaration($this->_client); $this->clientDeclaration->setShowAllOperations($this->_show_all_operations)->setYear($this->_year)->setMonth($this->_month); }
/** * @Template() */ public function indexAction() { /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->getDoctrine()->getManager(); $clients = $em->getRepository('ApplicationSonataClientBundle:Client')->createQueryBuilder('c')->select('c, cdi, u, ndc, SUM(cc.montant) as compte_solde_montant, 0 as dimmed')->leftJoin('c.center_des_impots', 'cdi')->leftJoin('c.user', 'u')->leftJoin('c.nature_du_client', 'ndc')->leftJoin('c.comptes', 'cc')->andWhere('(NOT c.date_fin_mission BETWEEN :date_lowest AND :date_highest) OR (c.date_fin_mission IS NULL)')->setParameter(':date_lowest', new \DateTime('1000-01-01'))->setParameter(':date_highest', new \DateTime())->groupBy('c.id')->orderBy('c.raison_sociale')->getQuery()->execute(); $clientsDimmed = $em->getRepository('ApplicationSonataClientBundle:Client')->createQueryBuilder('c')->select('c, cdi, u, ndc, SUM(cc.montant) as compte_solde_montant, 1 as dimmed')->leftJoin('c.center_des_impots', 'cdi')->leftJoin('c.user', 'u')->leftJoin('c.nature_du_client', 'ndc')->leftJoin('c.comptes', 'cc')->andWhere('c.date_fin_mission BETWEEN :date_lowest AND :date_highest')->setParameter(':date_lowest', new \DateTime('1000-01-01'))->setParameter(':date_highest', new \DateTime())->groupBy('c.id')->orderBy('c.raison_sociale')->getQuery()->execute(); $alerts = $em->getRepository('ApplicationSonataClientBundle:Client')->createQueryBuilder('c')->select('SUM(c.alert_count) as cnt')->getQuery()->execute(); $now = new \DateTime(); /* * We should have "Mois TVA (M-1).YYYY" if days <= 25 "Mois TVA (M).YYYY" if days > 25 */ $moisExtraColTitle = $now->format('d') > 25 ? date('m.Y', strtotime('now')) : date('m.Y', strtotime('now -1 month')); $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); return array('clients' => array_merge($clients, $clientsDimmed), 'cookies' => $this->getRequest()->cookies, 'alert_count' => $alerts[0]['cnt'], 'moisExtraColTitle' => $moisExtraColTitle, 'isSuperviseur' => $user->hasGroup('Superviseur')); }
/** * @return \Symfony\Component\HttpFoundation\Response */ public function listAction() { $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); $this->jsSettingsJson(array('isSuperviseur' => $user->hasGroup('Superviseur'))); global $clientsDimmed; /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->getDoctrine()->getManager(); $clientsDimmed = json_encode($em->getRepository('ApplicationSonataClientBundle:Client')->createQueryBuilder('c')->select('c as client, cdi, u, ndc, SUM(cc.montant) as compte_solde_montant')->leftJoin('c.center_des_impots', 'cdi')->leftJoin('c.user', 'u')->leftJoin('c.nature_du_client', 'ndc')->leftJoin('c.comptes', 'cc')->andWhere('c.date_fin_mission BETWEEN :date_lowest AND :date_highest')->setParameter(':date_lowest', new \DateTime('1000-01-01'))->setParameter(':date_highest', new \DateTime())->groupBy('c.id')->orderBy('c.raison_sociale')->getQuery()->getArrayResult(), 256); //return parent::listAction(); if (false === $this->admin->isGranted('LIST')) { throw new AccessDeniedException(); } $datagrid = $this->admin->getDatagrid(); $formView = $datagrid->getForm()->createView(); // set the theme for the current Admin Form $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme()); return $this->render($this->admin->getTemplate('list'), array('action' => 'list', 'form' => $formView, 'datagrid' => $datagrid, 'js_settings_json' => $this->_jsSettingsJson)); }
/** * @return array */ protected function makeExportData() { $rows = array(); $rows[] = $this->excelHeader(); /** @var $em \Doctrine\ORM\EntityManager */ $em = \AppKernel::getStaticContainer()->get('doctrine'); /** @var $query \Doctrine\ORM\QueryBuilder */ $object = $em->getRepository('ApplicationSonataClientBundle:Garantie')->createQueryBuilder('g')->orderBy('g.date_decheance', 'ASC')->getQuery()->execute(); $nom_de_la_banques = Garantie::getNomDeLaBanques(); foreach ($object as $key => $row) { $date_decheance = $row->getDateDecheance() ? \PHPExcel_Shared_Date::PHPToExcel($row->getDateDecheance()) : ''; /** @var $row Garantie */ $cell = array('client' => (string) $row->getClient(), 'date_decheance' => $date_decheance, 'montant' => $row->getMontant(), 'nom_de_la_banques_id' => isset($nom_de_la_banques[$row->getNomDeLaBanquesId()]) ? $nom_de_la_banques[$row->getNomDeLaBanquesId()] : '', 'num_de_ganrantie' => $row->getNumDeGanrantie(), 'note' => $row->getNote(), 'client_date_fin_mission' => $row->getClient()->getDateFinMission() ? \PHPExcel_Shared_Date::PHPToExcel($row->getClient()->getDateFinMission()) : '', 'calc_day_date_decheance' => $date_decheance ? '=B' . ($key + 2) . '-TODAY()' : ''); //format $this->excelCellFormat($key + 2, $row); $rows[] = $cell; } return $rows; }
/** * Get status * * @return ListStatuses */ public function getStatus() { if (!$this->status) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); $this->setStatus($em->getRepository('ApplicationSonataClientOperationsBundle:ListStatuses')->find(2)); } return $this->status; }
/** * @param $value * @return mixed */ public function getCurrentDevises($value) { $date = new \DateTime($value . '-01'); $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); return $em->getRepository('ApplicationSonataDevisesBundle:Devises')->findOneByDate($date); }
/** * @static * @param $id * @param \DateTime $date * @return int */ public static function getDevisesValue($id, \DateTime $date) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); /** @var $list_devises \Application\Sonata\ClientBundle\Entity\ListDevises */ $list_devises = $em->getRepository('ApplicationSonataClientBundle:ListDevises')->findOneById($id); $devise = $em->getRepository('ApplicationSonataDevisesBundle:Devises')->findOneByDate(new \DateTime($date->format('Y-m-01'))); /** http://redmine.testenm.com/issues/1364 */ if ($list_devises->getAlias() == self::Device) { return 1; } elseif ($devise) { $method = 'getMoney' . $list_devises->getAlias(); if (method_exists($devise, $method)) { return $devise->{$method}(); } } }
/** * @param $params * @return mixed */ protected function queryResult($params) { $admin = \AppKernel::getStaticContainer()->get('application.sonata.admin.' . strtolower($params['entity'])); /* \AppKernel::getStaticContainer()->setParameter('filter', array('client_id' => array('value' => $this->_client->getId()))); \AppKernel::getStaticContainer()->setParameter('month', $this->_month); \AppKernel::getStaticContainer()->setParameter('year', $this->_year); */ $result = $admin->createQuery()->getQuery()->execute(); unset($admin); return $result; }
public function isGranted($name, $object = null) { if ($name == 'DELETE') { $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); if ($user->hasGroup('Gestionnaire')) { return false; } } return parent::isGranted($name, $object); }
public function __construct(Client $client) { $this->client = $client; /* @var $em \Doctrine\ORM\EntityManager */ $this->em = \AppKernel::getStaticContainer()->get('doctrine')->getManager(); }
/** * @return array */ public static function getCountryEU() { return \AppKernel::getStaticContainer()->get('doctrine')->getRepository('ApplicationSonataClientBundle:ListCountries')->findEU(); }
protected function removePasDeMandat($object) { if (!$this->getClient()) { return; } $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); $docs = $em->getRepository('ApplicationSonataClientBundle:Document')->findBy(array('type_document' => \Application\Sonata\ClientBundle\Entity\ListTypeDocuments::Mandat, 'client' => $this->getClient()->getId())); if (count($docs) > 0) { $tab = $em->getRepository('ApplicationSonataClientBundle:ListClientTabs')->findOneByAlias('general'); $em->getRepository('ApplicationSonataClientBundle:ClientAlert')->createQueryBuilder('c')->delete()->andWhere('c.client = :client')->andWhere('c.tabs = :tab')->andWhere('c.text = :text')->setParameter(':client', $this->getClient())->setParameter(':tab', $tab)->setParameter(':text', 'Pas de Mandat')->getQuery()->execute(); $tab = $em->getRepository('ApplicationSonataClientBundle:ListClientTabs')->findOneByAlias('documents'); $em->getRepository('ApplicationSonataClientBundle:ClientAlert')->createQueryBuilder('c')->delete()->andWhere('c.client = :client')->andWhere('c.tabs = :tab')->andWhere('c.text = :text')->setParameter(':client', $this->getClient())->setParameter(':tab', $tab)->setParameter(':text', 'Manque Mandat')->getQuery()->execute(); } }
/** * @param $params * @return mixed */ protected function queryResult($params) { $admin = \AppKernel::getStaticContainer()->get('application.sonata.admin.' . strtolower($params['entity'])); $result = $admin->createQuery()->getQuery()->execute(); unset($admin); return $result; }
/** * Gives access if client is closed and user is supervisuer * * @return boolean */ public function hasClosedClientAccess() { $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); //return $this->_client->getDateFinMission() && $user->hasGroup('Superviseur'); if ($this->_client->getDateFinMission()) { return $user->hasGroup('Superviseur'); } return true; }
/** * Gives access if client is closed and user is supervisuer * * @return boolean */ public function hasClosedClientAccess() { $id = $this->getRequest()->get($this->getIdParameter()); $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); $client = $this->getObject($id); //$user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); //return $client->getDateFinMission() && $user->hasGroup('Superviseur'); if ($client->getDateFinMission()) { return $user->hasGroup('Superviseur'); } return true; }
/** * @param $data * @param string $action * @param string $template * @return \Symfony\Component\HttpFoundation\Response */ protected function _action($data, $action = 'create', $template = 'standard_layout') { if ($this->isXmlHttpRequest()) { return $data; } $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); $this->jsSettingsJson(array('url' => array('rdevises' => $this->admin->generateUrl('RDevises', array('filter' => array('client_id' => array('value' => $this->client_id))))), 'locked' => $this->getLocking() ? 1 : 0, 'client_ferme' => (int) $this->clientFerme(), 'isSuperviseur' => (int) $user->hasGroup('Superviseur'), 'active_tab' => $this->_tabAlias)); return $this->render('ApplicationSonataClientOperationsBundle::' . $template . '.html.twig', array('client_id' => $this->client_id, 'client' => $this->getClient(), 'client_documents' => $this->_client_documents, 'client_dir' => $this->_client_dir, 'month_list' => $this->getMonthList(), 'month' => $this->_month, 'query_month' => $this->_query_month, 'year' => $this->_year, 'content' => $data->getContent(), 'active_tab' => $this->_tabAlias, 'operation_type' => $this->_operationType, 'action' => $action, 'blocked' => $this->getLocking() ? 0 : 1, 'locked' => $this->getLocking() ? 1 : 0, 'js_settings_json' => $this->_jsSettingsJson, '_filter_json' => $this->_parameters_url, 'client_ferme' => $this->clientFerme())); }
protected function _setupAlerts($object) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); /* @var $tab \Application\Sonata\ClientBundle\Entity\ListClientTabs */ $tab = $em->getRepository('ApplicationSonataClientBundle:ListClientTabs')->findOneByAlias('numerotva'); if ($object) { $em->getRepository('ApplicationSonataClientBundle:ClientAlert')->createQueryBuilder('c')->delete()->andWhere('c.client = :client')->andWhere('c.tabs = :tab')->setParameter(':client', $this->getClient())->setParameter(':tab', $tab)->getQuery()->execute(); $nTVA = $em->getRepository('ApplicationSonataClientBundle:NumeroTVA')->findBy(array('date_de_verification' => new \DateTime('2000-01-01'), 'client' => $this->getClient())); $nTVANum = count($nTVA); if ($nTVANum > 0) { $alert = new ClientAlert(); $alert->setClient($this->getClient()); $alert->setTabs($tab); $alert->setIsBlocked(false); $alert->setText("il y a {$nTVANum} N° de TVA clients non vérifiés"); $em->persist($alert); $em->flush(); } } }
/** * @static * @param int|Client $client */ public static function scanFilesTree($client) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); if (!$client instanceof Client) { $client = $em->getRepository('ApplicationSonataClientBundle:Client')->find($client); } $client->setFiles(self::recursiveScanDir(self::getFilesAbsoluteDir($client))); $em->persist($client); $em->flush(); }
public function hasAjouterAccess() { /** @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); $garantie = $doctrine->getManager()->getRepository('ApplicationSonataClientBundle:Garantie')->findOneBy(array('client' => $this->client_id, 'type_garantie' => 2)); //var_dump($garantie->getNomDeLaBanquesId()); exit; //If status is "A établir" for "Dépôt de Garantie" if ($garantie && $garantie->getNomDeLaBanquesId() == 1) { return false; } return true; }
protected function _versementDuDepotDeGarantie($object) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); //example: http://redmine.testenm.com/issues/880 $status_object = $em->getRepository('ApplicationSonataClientBundle:ListCompteStatuts')->find(1); //1 $compte = new Compte(); $compte->setDate($object->getDateDemission()); $compte->setMontant($object->getMontant()); $compte->setOperation('Versement du dépôt de garantie'); $compte->setClient($object->getClient()); $compte->setGarantie($object); $compte->setStatut($status_object); $em->persist($compte); $em->flush(); }
/** * @return SendErrorsToMail */ public function sendMail() { /** @var $exception \Exception */ $exception = $this->getException(); if (!($this->filterFlattenException($exception) || $this->filterExceptionInstanceOf($exception))) { $content = implode("\n\n", $this->getMessage()); $subject = 'Eurotax error code ' . $this->_get_status_code . ' date ' . $this->_date; $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($this->_mailFrom)->setTo($this->_mailTo)->setBody($content); if ($this->_debug) { echo '<pre>'; echo $content; exit; } /** @var $mailer \Swift_Mailer */ $mailer = \AppKernel::getStaticContainer()->get('mailer'); $mailer->send($message); } return $this; }
/** * @return \Symfony\Component\HttpFoundation\Response */ public function listAction() { $user = \AppKernel::getStaticContainer()->get('security.context')->getToken()->getUser(); $this->jsSettingsJson(array('isSuperviseur' => $user->hasGroup('Superviseur'))); return $this->_action(parent::listAction(), 'list'); }
public function clientAction() { set_time_limit(0); //ini_set('max_execution_time', 0); //ini_set('memory_limit', '256M'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_FILES) && !empty($_FILES["inputFile"]["name"])) { $file = TMP_UPLOAD_PATH . '/' . str_replace(array(' ', '+', '(', ')'), '', $_FILES["inputFile"]["name"]); $tmpFile = $_FILES["inputFile"]["tmp_name"]; $inputFile = $_FILES['inputFile']; if (move_uploaded_file($tmpFile, $file)) { /* @var $objReader \PHPExcel_Reader_Excel2007 */ $objReader = \PHPExcel_IOFactory::createReaderForFile($file); if (get_class($objReader) == 'PHPExcel_Reader_CSV') { $this->get('session')->setFlash('sonata_flash_error', $this->admin->trans('Fichier non lisible')); return $this->render(':redirects:back.html.twig'); } $_FILES = array(); //create fake process id $pid = time(); $user = $this->get('security.context')->getToken()->getUser(); $kernel = $this->get('kernel'); $command = 'php ' . $kernel->getRootDir() . '/console clientbundle:import:initial client ' . $user->getId() . ' ' . realpath($file) . ' ' . $pid . ' --env=' . $kernel->getEnvironment(); // . ' --no-debug '; /* var_dump($command); exit; */ $process = new \Symfony\Component\Process\Process($command); $process->setTimeout(3600); $process->start(); $start = microtime(true); while ($process->isRunning()) { $total = microtime(true) - $start; if ($total / 60 >= 2) { // if process is too long (2 minutes) //var_dump(($total/60)); $em = $this->getDoctrine()->getManager(); $importNotif = new ImportNotification(); $importNotif->setPid($pid)->setUser($user)->setClientId(0); $em->persist($importNotif); $em->flush(); $this->_hasImportErrors = true; $this->get('session')->setFlash('sonata_flash_error', \AppKernel::getStaticContainer()->get('translator')->trans('There are too many data to be processed. We will just notify you once it\'s done. Check your email (' . $user->getEmail() . ') within few hours.')); break; return $this->render(':redirects:back.html.twig'); } } $output = unserialize($process->getOutput()); $messages = $output['messages']; $import_counts = $output['import_counts']; } } else { $this->get('session')->setFlash('sonata_flash_error|raw', 'Please upload a file'); } //$messages = $this->getCountMessageImports(); if (!empty($messages)) { $this->get('session')->setFlash('sonata_flash_info|raw', implode("<br />", $messages)); } return $this->render(':redirects:back.html.twig'); } return $this->render('ApplicationSonataClientBundle:InitialImport:client.html.twig'); }
public function validateDEB() { //if ($this->_is_validate_import) { $class = explode('\\', get_class($this->_object)); $class = end($class); $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); $em = $doctrine->getManager(); $client = $em->getRepository('ApplicationSonataClientBundle:Client')->findOneBy(array('id' => $this->_object->getClientId())); if ($class == 'DEBIntro') { $niveauDobligationId = $client->getNiveauDobligationId(); //INTRO } elseif ($class == 'DEBExped') { $niveauDobligationId = $client->getNiveauDobligationExpedId(); //DEB } $regime = $this->_object->getRegime(); /* On deb Exped and Deb Intro... when the user put a code for 'Nomenclature" and we have a data on the colum "Unité supplémentaire" of the file ( http://outils.prodinternet.com/mantis/view.php?id=4210) ... check that the field "Unité supplémentaire" is mandatory */ $unitesSupplementairesRequired = null; $nomenclature = $this->_object->getNomenclature(); if ($nomenclature) { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); $findNomenclature = $em->getRepository('ApplicationSonataClientBundle:Nomenclature')->findOneBy(array('code' => ltrim(str_replace(' ', '', $nomenclature), 0))); if ($findNomenclature) { if ($findNomenclature->getUnitesSupplementaires() && $this->_object->getUnitesSupplementaires()) { $unitesSupplementairesRequired = true; } else { if ($findNomenclature->getUnitesSupplementaires() && !$this->_object->getUnitesSupplementaires()) { $unitesSupplementairesRequired = true; } else { if (!$findNomenclature->getUnitesSupplementaires() && $this->_object->getUnitesSupplementaires()) { $unitesSupplementairesRequired = false; } else { if (!$findNomenclature->getUnitesSupplementaires() && !$this->_object->getUnitesSupplementaires()) { $unitesSupplementairesRequired = false; } } } } } } $requiredFields = @$this->_requiredFields[$class][$niveauDobligationId][$regime]['fields']; if (!empty($requiredFields)) { $requiredFields = array_flip($requiredFields); if (isset($requiredFields['nomenclature'])) { $this->validateNomenclature2(); } if (!is_null($unitesSupplementairesRequired)) { if ($unitesSupplementairesRequired === false) { unset($requiredFields['unites_supplementaires']); } elseif ($unitesSupplementairesRequired === true) { $requiredFields['unites_supplementaires'] = true; } } foreach ($requiredFields as $field => $v) { $method = 'get' . strtoupper(\Doctrine\Common\Util\Inflector::camelize($field)); if ($field == 'masse_mette') { $value = trim($this->_object->{$method}()); if ($value === '') { $this->_errorElement->with($field)->addViolation('La valeur de est obligatoire. ')->end(); } } else { if (!$this->_object->{$method}()) { if ($field == 'unites_supplementaires') { $this->_errorElement->with('unites_supplementaires')->addViolation('UNITES SUPPLEMENTAIRES devrait être rempli ' . ($this->_object->getNomenclature() ? 'pour ' . $this->_object->getNomenclature() : ''))->end(); } else { $this->_errorElement->with($field)->addViolation('La valeur de est obligatoire.')->end(); } } } } } $emptyFields = @$this->_emptyFields[$class][$niveauDobligationId][$regime]['fields']; if (!empty($emptyFields)) { $emptyFields = array_flip($emptyFields); if (!is_null($unitesSupplementairesRequired)) { if ($unitesSupplementairesRequired === true) { unset($emptyFields['unites_supplementaires']); } elseif ($unitesSupplementairesRequired === false) { $emptyFields['unites_supplementaires'] = true; } } foreach ($emptyFields as $field => $v) { $hasViolation = false; $method = 'get' . strtoupper(\Doctrine\Common\Util\Inflector::camelize($field)); $value = $this->_object->{$method}(); if (!is_object($value) && (int) $value != 0 || $value) { if ($field == 'unites_supplementaires') { $this->_errorElement->with('unites_supplementaires')->addViolation('UNITES SUPPLEMENTAIRES devrait être vide ' . ($this->_object->getNomenclature() ? 'pour ' . $this->_object->getNomenclature() : ''))->end(); } else { $this->_errorElement->with($field)->addViolation('La cellule doit être vide.')->end(); } } } } //} return $this; }
public function validateNomenclature2() { $nomenclature = $this->_object->getNomenclature(); if ($nomenclature) { $lenNomen = strlen($nomenclature); if ($lenNomen < 8 || $lenNomen > 9) { $this->_errorElement->with('nomenclature')->addViolation('Code incorrect')->end(); } else { /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */ $doctrine = \AppKernel::getStaticContainer()->get('doctrine'); /* @var $em \Doctrine\ORM\EntityManager */ $em = $doctrine->getManager(); $nomenclatures = $em->getRepository('ApplicationSonataClientBundle:Nomenclature')->findBy(array('code' => ltrim($nomenclature, 0))); if (count($nomenclatures) == 0) { $this->_errorElement->with('nomenclature')->addViolation('Code non trouvé')->end(); } } } return $this; }