예제 #1
0
 /**
  * @param \Application\Sonata\ClientBundle\Entity\Garantie $object
  * @return mixed|void
  */
 public function preRemove($object)
 {
     //2 => Dépôt de Garantie
     if ($object->getTypeGarantie() && $object->getTypeGarantie()->getId() == 2) {
         /* @var $doctrine \Doctrine\Bundle\DoctrineBundle\Registry */
         $doctrine = \AppKernel::getStaticContainer()->get('doctrine');
         /* @var $em \Doctrine\ORM\EntityManager */
         $em = $doctrine->getManager();
         /** @var $compte_de_depot CompteDeDepot */
         list($compte_de_depot) = $em->getRepository('ApplicationSonataClientBundle:CompteDeDepot')->createQueryBuilder('c')->select('SUM(c.montant) as total')->setMaxResults(1)->getQuery()->execute();
         if ($compte_de_depot['total'] != 0) {
             echo '<div class="alert alert-error">' . $this->trans("Impossible de supprimer le dépot de garantie car le solde du compte de dépot n'est pas nul") . '</div>';
             exit;
         } else {
             //DELETE
             /** @var $compte Compte */
             $compte = $em->getRepository('ApplicationSonataClientBundle:Compte')->findByGarantie($object->getId());
             foreach ($compte as $c) {
                 $c->setGarantie(NULL);
                 $em->persist($c);
             }
             /** @var $compte_de_depot CompteDeDepot */
             $compte_de_depot = $em->getRepository('ApplicationSonataClientBundle:CompteDeDepot')->findByGarantie($object->getId());
             foreach ($compte_de_depot as $c) {
                 $c->setGarantie(NULL);
                 $em->persist($c);
             }
             $em->flush();
             unset($c, $compte_de_depot, $compte);
         }
     }
 }
예제 #2
0
 /**
  * @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;
 }
 /**
  *statut | nom_de_la_banques_id
  */
 protected function _getNomDeLaBanquesId($value)
 {
     //return $this->_getStatutDocument($value);
     $choices = array_flip(\Application\Sonata\ClientBundle\Entity\Garantie::getNomDeLaBanques());
     if (isset($choices[$value])) {
         return $choices[$value];
     }
     if ('obtenu' == strtolower($value)) {
         return 0;
     }
     return $value;
 }