Ejemplo n.º 1
0
  public void generarPDFComprobante(Comprobante c) throws DocumentException, FileNotFoundException {
    Document documento = new Document();

    FileOutputStream archivoPDF;

    Calendar cal;
    cal = Calendar.getInstance();
    cal.setTime(c.getFecha());
    SimpleDateFormat d = new SimpleDateFormat("dd-MM-yyyy");
    String fecha = d.format(c.getFecha());

    String nombre =
        "./impresiones/comprobantes/comp" + c.getClaseLicencia().getNombre() + "_" + fecha + ".PDF";

    archivoPDF = new FileOutputStream(nombre);

    PdfWriter.getInstance(documento, archivoPDF).setInitialLeading(20);

    documento.open();

    PdfPTable tabla = new PdfPTable(2);

    tabla.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    PdfPCell celda1 =
        new PdfPCell(
            new Phrase(
                "Nombre: "
                    + c.getTitular().getIdUsuario().getNombre()
                    + " "
                    + c.getTitular().getIdUsuario().getApellido()));
    celda1.setBorder(Rectangle.LEFT | Rectangle.TOP);

    PdfPCell celda2 = new PdfPCell(new Phrase("Clase: " + c.getClaseLicencia().getNombre()));
    celda2.setBorder(Rectangle.RIGHT | Rectangle.TOP);

    PdfPCell celda3 = new PdfPCell(new Phrase("Monto: $" + c.getMontoAbonado()));
    celda3.setBorder(Rectangle.LEFT | Rectangle.BOTTOM);

    PdfPCell celda4 = new PdfPCell(new Phrase("Fecha: " + fecha));
    celda4.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);

    tabla.addCell(celda1);
    tabla.addCell(celda2);
    tabla.addCell(celda3);
    tabla.addCell(celda4);

    documento.add(tabla);

    documento.close();
  }
Ejemplo n.º 2
0
 public void destroy(Integer id) throws NonexistentEntityException {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Comprobante comprobante;
     try {
       comprobante = em.getReference(Comprobante.class, id);
       comprobante.getIdComprobante();
     } catch (EntityNotFoundException enfe) {
       throw new NonexistentEntityException(
           "The comprobante with id " + id + " no longer exists.", enfe);
     }
     Operador administrativoResponsable = comprobante.getAdministrativoResponsable();
     if (administrativoResponsable != null) {
       administrativoResponsable.getComprobanteCollection().remove(comprobante);
       administrativoResponsable = em.merge(administrativoResponsable);
     }
     Clase claseLicencia = comprobante.getClaseLicencia();
     if (claseLicencia != null) {
       claseLicencia.getComprobanteCollection().remove(comprobante);
       claseLicencia = em.merge(claseLicencia);
     }
     Titular titular = comprobante.getTitular();
     if (titular != null) {
       titular.getComprobanteCollection().remove(comprobante);
       titular = em.merge(titular);
     }
     em.remove(comprobante);
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
Ejemplo n.º 3
0
 public void create(Comprobante comprobante) {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Operador administrativoResponsable = comprobante.getAdministrativoResponsable();
     if (administrativoResponsable != null) {
       administrativoResponsable =
           em.getReference(
               administrativoResponsable.getClass(), administrativoResponsable.getIdOperador());
       comprobante.setAdministrativoResponsable(administrativoResponsable);
     }
     Clase claseLicencia = comprobante.getClaseLicencia();
     if (claseLicencia != null) {
       claseLicencia = em.getReference(claseLicencia.getClass(), claseLicencia.getIdClase());
       comprobante.setClaseLicencia(claseLicencia);
     }
     Titular titular = comprobante.getTitular();
     if (titular != null) {
       titular = em.getReference(titular.getClass(), titular.getIdTitular());
       comprobante.setTitular(titular);
     }
     em.persist(comprobante);
     if (administrativoResponsable != null) {
       administrativoResponsable.getComprobanteCollection().add(comprobante);
       administrativoResponsable = em.merge(administrativoResponsable);
     }
     if (claseLicencia != null) {
       claseLicencia.getComprobanteCollection().add(comprobante);
       claseLicencia = em.merge(claseLicencia);
     }
     if (titular != null) {
       titular.getComprobanteCollection().add(comprobante);
       titular = em.merge(titular);
     }
     em.getTransaction().commit();
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }
Ejemplo n.º 4
0
 public void edit(Comprobante comprobante) throws NonexistentEntityException, Exception {
   EntityManager em = null;
   try {
     em = getEntityManager();
     em.getTransaction().begin();
     Comprobante persistentComprobante =
         em.find(Comprobante.class, comprobante.getIdComprobante());
     Operador administrativoResponsableOld = persistentComprobante.getAdministrativoResponsable();
     Operador administrativoResponsableNew = comprobante.getAdministrativoResponsable();
     Clase claseLicenciaOld = persistentComprobante.getClaseLicencia();
     Clase claseLicenciaNew = comprobante.getClaseLicencia();
     Titular titularOld = persistentComprobante.getTitular();
     Titular titularNew = comprobante.getTitular();
     if (administrativoResponsableNew != null) {
       administrativoResponsableNew =
           em.getReference(
               administrativoResponsableNew.getClass(),
               administrativoResponsableNew.getIdOperador());
       comprobante.setAdministrativoResponsable(administrativoResponsableNew);
     }
     if (claseLicenciaNew != null) {
       claseLicenciaNew =
           em.getReference(claseLicenciaNew.getClass(), claseLicenciaNew.getIdClase());
       comprobante.setClaseLicencia(claseLicenciaNew);
     }
     if (titularNew != null) {
       titularNew = em.getReference(titularNew.getClass(), titularNew.getIdTitular());
       comprobante.setTitular(titularNew);
     }
     comprobante = em.merge(comprobante);
     if (administrativoResponsableOld != null
         && !administrativoResponsableOld.equals(administrativoResponsableNew)) {
       administrativoResponsableOld.getComprobanteCollection().remove(comprobante);
       administrativoResponsableOld = em.merge(administrativoResponsableOld);
     }
     if (administrativoResponsableNew != null
         && !administrativoResponsableNew.equals(administrativoResponsableOld)) {
       administrativoResponsableNew.getComprobanteCollection().add(comprobante);
       administrativoResponsableNew = em.merge(administrativoResponsableNew);
     }
     if (claseLicenciaOld != null && !claseLicenciaOld.equals(claseLicenciaNew)) {
       claseLicenciaOld.getComprobanteCollection().remove(comprobante);
       claseLicenciaOld = em.merge(claseLicenciaOld);
     }
     if (claseLicenciaNew != null && !claseLicenciaNew.equals(claseLicenciaOld)) {
       claseLicenciaNew.getComprobanteCollection().add(comprobante);
       claseLicenciaNew = em.merge(claseLicenciaNew);
     }
     if (titularOld != null && !titularOld.equals(titularNew)) {
       titularOld.getComprobanteCollection().remove(comprobante);
       titularOld = em.merge(titularOld);
     }
     if (titularNew != null && !titularNew.equals(titularOld)) {
       titularNew.getComprobanteCollection().add(comprobante);
       titularNew = em.merge(titularNew);
     }
     em.getTransaction().commit();
   } catch (Exception ex) {
     String msg = ex.getLocalizedMessage();
     if (msg == null || msg.length() == 0) {
       Integer id = comprobante.getIdComprobante();
       if (findComprobante(id) == null) {
         throw new NonexistentEntityException(
             "The comprobante with id " + id + " no longer exists.");
       }
     }
     throw ex;
   } finally {
     if (em != null) {
       em.close();
     }
   }
 }