private function retrieveEstudianteSearchList(Estudiante $estudiante)
 {
     $searchStrings = array();
     //Generating class and hour string.
     if ($estudiante->getEgresado()) {
         $searchStrings['EGRESADOS'] = 'EGRESADOS';
     } else {
         if ($estudiante->getClase() && $estudiante->getHorario()) {
             $searchStrings[$estudiante->getClase()->getName() . ' (' . $estudiante->getHorario()->getName() . ')'] = $estudiante->getClase()->getName() . ' (' . $estudiante->getHorario()->getName() . ')';
         } else {
             $this->logger->error(sprintf('The student not has class or hourly and is active. Id: %s', $estudiante->getId()));
         }
         $searchStrings['PADRES'] = 'PADRES';
         foreach ($estudiante->getActividades() as $actividad) {
             $searchStrings[] = $actividad->getNombre();
         }
     }
     return $searchStrings;
 }
 public function generateUserBill(Estudiante $estudiante, $month = null, $year = null, $ignorePaidAndCancel = false)
 {
     if ($month === null) {
         $month = date('n');
     }
     if ($year === null) {
         $year = date('Y');
     }
     if ($estudiante->getEgresado()) {
         $this->logger->addInfo(sprintf('The student %s has already left', $estudiante->getId()));
         return;
     }
     $factura = $this->em->getRepository('AppBundle:FacturaEstudiante')->retrieveFacturaOfEstudiantePerMonthAndYear($estudiante, $month, $year);
     if ($factura) {
         if (!$ignorePaidAndCancel) {
             if ($factura->getPago()) {
                 $this->logger->addInfo(sprintf('The student %s has the bill of %s/%s paid', $estudiante->getId(), $month, $year));
                 return;
             }
             if ($factura->getCancelado()) {
                 $this->logger->addInfo(sprintf('The student %s has the bill of %s/%s cancelled', $estudiante->getId(), $month, $year));
                 return;
             }
         }
     } else {
         $factura = new FacturaEstudiante();
     }
     if ($estudiante->getAnioIngreso() > date('Y')) {
         if ($factura->getId() > 0) {
             $this->em->remove($factura);
             $this->em->flush($factura);
         }
         $this->logger->addInfo(sprintf('The student %s starting year is %s. No bill generated', $estudiante->getId(), $estudiante->getAnioIngreso()));
         return;
     }
     $factura->setEstudiante($estudiante);
     $factura->setMonth($month);
     $factura->setTotal(0);
     $factura->setYear($year);
     $factura->setFechavencimiento(new \DateTime());
     $this->em->persist($factura);
     $total = 0;
     $listadoDetalles = array();
     if ($estudiante->getHorario() !== null) {
         $costoHorario = $this->getCostoOfHorario($estudiante->getHorario());
         $total = $costoHorario;
         $detalleMensualidad = new FacturaEstudianteDetalle();
         $detalleMensualidad->setAmount($costoHorario);
         $detalleMensualidad->setDescription('Mensualidad');
         $detalleMensualidad->setFactura($factura);
         $detalleMensualidad->setAutogenerated(true);
         $listadoDetalles[$detalleMensualidad->generateUniqueHash()] = $detalleMensualidad;
     }
     // Descuento de hermano
     $activeBrother = 0;
     foreach ($estudiante->getMyBrothers() as $brother) {
         if (!$brother->getEgresado()) {
             ++$activeBrother;
         }
     }
     $descuento = $this->em->getRepository('AppBundle:Descuento')->findOneBy(array('cantidadDeHermanos' => $activeBrother));
     if ($descuento && $descuento->getPorcentaje() > 0) {
         $amount = ceil($total * $descuento->getPorcentaje() / 100 * -1);
         $detalleDescuentoHermano = new FacturaEstudianteDetalle();
         $detalleDescuentoHermano->setAmount($amount);
         $detalleDescuentoHermano->setDescription('Descuento hermano');
         $detalleDescuentoHermano->setFactura($factura);
         $detalleDescuentoHermano->setAutogenerated(true);
         $listadoDetalles[$detalleDescuentoHermano->generateUniqueHash()] = $detalleDescuentoHermano;
         $total += $amount;
     }
     if ($estudiante->getDescuento() && $estudiante->getDescuento() > 0) {
         $amount = ceil($total * $estudiante->getDescuento() / 100 * -1);
         $detalleDescuento = new FacturaEstudianteDetalle();
         $detalleDescuento->setAmount($amount);
         $detalleDescuento->setDescription('Descuento usuario');
         $detalleDescuento->setFactura($factura);
         $detalleDescuento->setAutogenerated(true);
         $listadoDetalles[$detalleDescuento->generateUniqueHash()] = $detalleDescuento;
         $total += $amount;
     }
     foreach ($estudiante->getActividades() as $actividad) {
         $detalleActividad = new FacturaEstudianteDetalle();
         $detalleActividad->setAmount($actividad->getCosto());
         $detalleActividad->setDescription($actividad->getNombre());
         $detalleActividad->setFactura($factura);
         $detalleActividad->setAutogenerated(true);
         $listadoDetalles[$detalleActividad->generateUniqueHash()] = $detalleActividad;
         $total += $actividad->getCosto();
     }
     foreach ($factura->getFacturaDetalles() as $detalle) {
         if (count($listadoDetalles) > 0) {
             $auxDetalle = array_pop($listadoDetalles);
             $detalle->setAmount($auxDetalle->getAmount());
             $detalle->setDescription($auxDetalle->getDescription());
             $this->em->persist($detalle);
         } else {
             $this->em->remove($detalle);
         }
     }
     foreach ($listadoDetalles as $detalle) {
         $this->em->persist($detalle);
     }
     $factura->setTotal($total);
     $this->em->persist($factura);
     $this->em->flush();
 }