public function cancelFactura(FacturaFinal $factura) { if ($factura->getCancelado() && $factura->getPago()) { return; } $cuenta = $factura->getCuenta(); $cuenta->setDebe($cuenta->getDebe() - $factura->getTotal()); $factura->setCancelado(true); foreach ($factura->getFacturasEstudiantes() as $facturaEstudiante) { $facturaEstudiante->setCancelado(true); $this->em->persist($facturaEstudiante); } $this->em->persist($factura); $this->em->persist($cuenta); $this->em->flush(); }