Example usage for com.itextpdf.text.pdf GrayColor GrayColor

List of usage examples for com.itextpdf.text.pdf GrayColor GrayColor

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf GrayColor GrayColor.

Prototype

public GrayColor(float floatGray) 

Source Link

Usage

From source file:Almacen.formatosAlmacen.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*w  w  w. j  a va 2 s  .  co  m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        if (almacen.getPedido() != null) {
            reporte.contenido.roundRectangle(35, 695, 180, 10, 0);
            reporte.contenido.roundRectangle(35, 625, 180, 80, 0);

            reporte.contenido.roundRectangle(215, 695, 180, 10, 0);
            reporte.contenido.roundRectangle(215, 625, 180, 80, 0);
        }
        reporte.contenido.roundRectangle(395, 695, 180, 10, 0);
        reporte.contenido.roundRectangle(395, 625, 180, 80, 0);

        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 30, -40, 60));
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (almacen.getPedido() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Movimiento en almacen: "
                    + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(), 35, 710, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Movimiento en almacen: " + almacen.getIdAlmacen(), 35, 710, 0);
        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 710, 0);

        ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos del proveedor****************************
        if (almacen.getPedido() != null) {
            DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS DEL PROVEEDOR", 73, 697, 0);

            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    almacen.getPedido().getProveedorByIdProveedor().getNombre(), 40, 687, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getDireccion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        almacen.getPedido().getProveedorByIdProveedor().getDireccion(), 40, 677, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Dir:", 40, 677, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getColonia() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Col: " + almacen.getPedido().getProveedorByIdProveedor().getColonia(), 40, 667, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Col:", 40, 667, 0);

            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "Edo: " + almacen.getPedido().getProveedorByIdProveedor().getEstado(), 40, 657, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getTel1() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Tel: " + almacen.getPedido().getProveedorByIdProveedor().getTel1(), 40, 647, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tel:", 40, 647, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getTel1() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Cto: " + almacen.getPedido().getProveedorByIdProveedor().getRepresentante(), 40, 637,
                        0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Cto:", 40, 637, 0);

            if (almacen.getPedido().getProveedorByIdProveedor().getEmail() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Email: " + almacen.getPedido().getProveedorByIdProveedor().getEmail(), 40, 627, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Email: ", 40, 627, 0);

            //**********************datos de facturacion*****************************
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS DE FACTURACIN", 250, 697, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    almacen.getPedido().getProveedorByIdEmpresa().getNombre(), 220, 687, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getDireccion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        almacen.getPedido().getProveedorByIdEmpresa().getDireccion(), 220, 677, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Dir:", 220, 677, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getColonia() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Col: " + almacen.getPedido().getProveedorByIdEmpresa().getColonia(), 220, 667, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Col:", 220, 667, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getPoblacion() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Pob: " + almacen.getPedido().getProveedorByIdEmpresa().getPoblacion(), 220, 657, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Pob:", 220, 657, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getCp() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "CP: " + almacen.getPedido().getProveedorByIdEmpresa().getCp(), 220, 647, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "CP:", 220, 647, 0);
            if (almacen.getPedido().getProveedorByIdEmpresa().getRfc() != null)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "RFC: " + almacen.getPedido().getProveedorByIdEmpresa().getRfc(), 220, 637, 0);
            else
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RFC:", 220, 537, 0);
        }
        //**********************datos de la unidad*****************************
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "DATOS LA UNIDAD", 450, 697, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Orden: " + ord.getIdOrden(), 410, 687,
                0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo: " + ord.getTipo().getTipoNombre(),
                410, 677, 0);
        if (ord.getNoSerie() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Serie: " + ord.getNoSerie(), 410,
                    667, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Serie: ", 410, 667, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Modelo: " + ord.getModelo(), 410, 657, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Compaia: " + ord.getCompania().getNombre(), 410, 647, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Cli:" + ord.getClientes().getNombre(),
                410, 637, 0);
        if (ord.getSiniestro() != null)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Siniestro:" + ord.getSiniestro(),
                    410, 627, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "No Siniestro:", 410, 627, 0);

        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Costo c/u", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Total", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));

        reporte.contenido.roundRectangle(50, 40, 180, 1, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Almacen", 120, 30, 0);
        reporte.contenido.roundRectangle(370, 40, 180, 1, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Proveedor", 440, 30, 0);
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.formatosOrden.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//from w  w  w . j  a  va 2s .c  o m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        reporte.contenido.roundRectangle(35, 755, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 735, 280, 20, 0);
        ////*2
        reporte.contenido.roundRectangle(35, 388, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 368, 280, 20, 0);
        ////         
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 335, -23, 30));
        /*2*/reporte.agregarImagen(reporte.crearImagen("imagenes/grande300115.jpg", 100, -390, 30));
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (miAlmacen.getTipoMovimiento() == 1) {
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos en Almacn (Entrada de Material): " + almacen.getIdAlmacen(), 35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Devolucin de material de operarios): "
                                + almacen.getIdAlmacen(),
                        35, 767, 0);
            //*********2
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos en Almacn (Entrada de Material): " + almacen.getIdAlmacen(), 35, 400, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Devolucin de material de operarios): "
                                + almacen.getIdAlmacen(),
                        35, 400, 0);
            ////
        } else {
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Entrega de material a operarios): " + almacen.getIdAlmacen(),
                        35, 767, 0);
            //*********2
            if (miAlmacen.getOperacion() == 4)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimientos de Almacn (Entrega de material a operarios): " + almacen.getIdAlmacen(),
                        35, 400, 0);
            ///
        }

        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 390, 0);

        ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos de movimiento****************************
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Materiales y Refacciones del Almacn",
                40, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Materiales y Refacciones del Almacn", 40, 390, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 747, 0);
        /*2*/ reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 380, 0);
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    747, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    747, 0);
        ////**2
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    380, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    380, 0);
        ////

        if (almacen.getOperacion() == 4)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Compaa", 220,
                    747, 0);
        if (almacen.getOperacion() == 5)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Operarios", 220,
                    747, 0);

        ////**2
        if (almacen.getOperacion() == 4)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Compaa", 220,
                    380, 0);
        if (almacen.getOperacion() == 5)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Operarios", 220,
                    380, 0);
        ////

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(), 40, 737,
                0);
        /*2*/ reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(),
                40, 370, 0);

        //Firmas de material 
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 440, 0);
        } else {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    440, 0);
        }

        /*2*/if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 20, 0);
        } else {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    20, 0);
        }
        ///
        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio(tabla)
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
    } catch (Exception e) {
        System.out.println(e);
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.formatosPedido.java

private void cabeceraCompra(PDF reporte, BaseFont bf, PdfPTable tabla, Almacen almacen, Orden ord) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from www  . j a v  a  2 s. c  o  m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));
        reporte.contenido.roundRectangle(35, 755, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 735, 280, 20, 0);
        ////*2
        reporte.contenido.roundRectangle(35, 388, 280, 10, 0);
        reporte.contenido.roundRectangle(35, 368, 280, 20, 0);
        ////         
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 13);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.agregaObjeto(reporte.crearImagen("imagenes/grande300115.jpg", 335, -23, 30));
        /*2*/reporte.agregarImagen(reporte.crearImagen("imagenes/grande300115.jpg", 100, -390, 30));//-390//-375
        reporte.contenido.setFontAndSize(bf, 12);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        if (miAlmacen.getTipoMovimiento() == 1) {
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimiento en Almacn (Entrada de Material): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 5)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Devolucin de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            ////*2
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimiento en Almacn (Entrada de Material): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Devolucin de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            /////
        } else {
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Entrega de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 767, 0);
            ///**2
            if (miAlmacen.getOperacion() == 1 || miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 3)
                reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                        "Movimiento de Almacn (Devolucin de material a proveedor): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            if (miAlmacen.getOperacion() == 6)
                reporte.contenido.showTextAligned(
                        PdfContentByte.ALIGN_LEFT, "Movimientos de Almacn (Entrega de ventas): "
                                + almacen.getIdAlmacen() + " Pedido:" + almacen.getPedido().getIdPedido(),
                        35, 400, 0);
            ///
        }

        reporte.contenido.setFontAndSize(bf, 7);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 306, 390, 0);
        if (ord != null)
            ord = (Orden) session.get(Orden.class, ord.getIdOrden());

        //************************datos de movimiento****************************
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");//YYYY-MM-DD HH:MM:SS
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Materiales y Refacciones del Almacn",
                40, 757, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "Materiales y Refacciones del Almacn", 40, 390, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 747, 0);
        /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                "N. Movimiento: " + almacen.getIdAlmacen(), 40, 380, 0);
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    747, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    747, 0);
        ////2
        if (almacen.getTipoMovimiento() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Entrada", 120,
                    380, 0);
        else
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Movimiento : Salida", 120,
                    380, 0);
        ////
        if (almacen.getOperacion() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido", 220,
                    747, 0);
        if (almacen.getOperacion() == 2)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido E.", 220,
                    747, 0);
        if (almacen.getOperacion() == 3)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido A.", 220,
                    747, 0);
        if (almacen.getOperacion() == 6)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Venta", 220, 747,
                    0);
        ////2
        if (almacen.getOperacion() == 1)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido", 220,
                    380, 0);
        if (almacen.getOperacion() == 2)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido E.", 220,
                    380, 0);
        if (almacen.getOperacion() == 3)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Pedido A.", 220,
                    380, 0);
        if (almacen.getOperacion() == 6)
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "Tipo de Operacin : Venta", 220, 380,
                    0);
        ////
        if (ord != null) {
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(), 40,
                    737, 0);
            /*2*/reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "N. Orden: " + ord.getIdOrden(),
                    40, 370, 0);
        }

        //Firmas de material 
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 440, 0);
        } else {
            reporte.contenido.roundRectangle(45, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 440, 0);
            reporte.contenido.roundRectangle(250, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 440, 0);
            reporte.contenido.roundRectangle(440, 450, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    440, 0);
        }

        ///2
        if (miAlmacen.getTipoMovimiento() == 1) {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ENTREGA: " + almacen.getEntrego(), 45,
                    20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "RECIBE: " + almacen.getUsuario().getEmpleado().getNombre(), 440, 20, 0);
        } else {
            reporte.contenido.roundRectangle(45, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT,
                    "ENTREGA: " + almacen.getUsuario().getEmpleado().getNombre(), 45, 20, 0);
            reporte.contenido.roundRectangle(250, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "AUTORIZA: ", 250, 20, 0);
            reporte.contenido.roundRectangle(440, 30, 130, 1, 0);
            reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "RECIBE: " + almacen.getEntrego(), 440,
                    20, 0);
        }
        ///

        reporte.finTexto();
        reporte.contenido.setFontAndSize(bf, 12);
        //agregamos renglones vacios para dejar un espacio(tabla)
        reporte.agregaObjeto(new Paragraph(" "));
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);
        BaseColor cabecera = BaseColor.GRAY;
        int centro = Element.ALIGN_CENTER;

        tabla.addCell(reporte.celda("N", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("#", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("N Parte", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Descripcin", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Med", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        tabla.addCell(reporte.celda("Cant", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        if (tabla.getNumberOfColumns() > 6) {
            tabla.addCell(reporte.celda("Costo c/u", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
            tabla.addCell(reporte.celda("Total", font, cabecera, centro, 0, 1, Rectangle.RECTANGLE));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.Reporte2.java

public void cabecera(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {/*from w  w  w .  j a  va2s  .  co m*/
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 755, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;
        if (op == 1) {
            if (t_fecha1.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " del " + t_fecha1.getText();
            if (t_fecha2.getText().compareTo("AAAA-MM-DD") != 0)
                titulo += " al " + t_fecha2.getText();
        }
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 745, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 745, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;
        int izquierda = Element.ALIGN_LEFT;
        int derecha = Element.ALIGN_RIGHT;
        if (op == 1) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
        if (op == 2) {
            for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
                tabla.addCell(reporte.celda(t_datos1.getColumnName(a), font, cabecera, centro, 0, 1,
                        Rectangle.RECTANGLE));
            }
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Almacen.Reporte2.java

public void cabecera1(PDF reporte, BaseFont bf, PdfPTable tabla, String titulo1, int op) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    try {//  www. j a v  a 2 s . co  m
        reporte.contenido.setLineWidth(0.5f);
        reporte.contenido.setColorStroke(new GrayColor(0.2f));
        reporte.contenido.setColorFill(new GrayColor(0.9f));

        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        reporte.inicioTexto();
        reporte.contenido.setFontAndSize(bf, 14);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, con.getEmpresa(), 35, 755, 0);
        reporte.contenido.setFontAndSize(bf, 8);
        reporte.contenido.setColorFill(BaseColor.BLACK);
        String titulo = titulo1;

        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, titulo, 35, 745, 0);
        reporte.contenido.showTextAligned(PdfContentByte.ALIGN_RIGHT,
                "Fecha:" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()), 570, 745, 0);

        reporte.finTexto();
        //agregamos renglones vacios para dejar un espacio
        reporte.agregaObjeto(new Paragraph(" "));

        Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD);

        BaseColor cabecera = BaseColor.GRAY;
        BaseColor contenido = BaseColor.WHITE;
        int centro = Element.ALIGN_CENTER;

        for (int a = 0; a < tabla.getNumberOfColumns(); a++) {
            tabla.addCell(reporte.celda(t_datos2.getColumnName(a), font, cabecera, centro, 0, 1,
                    Rectangle.RECTANGLE));
        }
    } catch (Exception e) {
        System.out.println(e);
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteInventario() {
    Connection con;/*  ww  w.j  ava 2s  .  c o  m*/
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Cantidad, Cantidadmin,  Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.Composicion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento ");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_inventario " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Elaboracion");
            table.addCell("Fecha de Vencimiento");
            table.addCell("Cantidad minima");
            table.addCell("Cantidad actual");
            table.addCell("Cantidad maxima");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("FechaElaboracion"));
            table.addCell(res.getString("FechaVencimiento"));
            table.addCell(res.getString("Cantidadmin"));
            table.addCell(res.getString("Cantidad"));
            table.addCell(res.getString("Cantidadmax"));
        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Inventario generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }

}

From source file:Capa_Modelo.Reportes.java

public void generarReporteVencimiento() {
    Connection con;//  w w w  .jav a2  s.c o  m
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Cantidad, Cantidadmin, Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento ");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_vencimiento " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Vencimiento", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(4);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Vencimiento");
            table.addCell("Cantidad actual");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            if (vencido(res.getDate("FechaVencimiento"))) {
                table.addCell(res.getString("Nombre"));
                table.addCell(res.getString("Laboratorio"));
                table.addCell(res.getString("FechaVencimiento"));
                table.addCell(res.getString("Cantidad"));
            }
        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Vencimiento generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error en conectar con base de datos");
    } catch (DocumentException ex) {
        Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "El documento no se pudo generar");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "EL archivo no se abri");
    }
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteConsumoMedicamentos() {
    DecimalFormat df = new DecimalFormat("####0.00");
    Connection con;// www .jav  a  2s.c  o  m
    ResultSet res;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    double consumo, cantidad;
    double porcentaje;
    consumo = cantidad = 0;
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Inventario.Cantidad, SUM(MedicinaPaciente.Cantidad) as Consumo FROM MedicinaPaciente INNER JOIN Medicamento ON MedicinaPaciente.ID_Medicamento = Medicamento.ID_Medicamento INNER JOIN Inventario ON MedicinaPaciente.ID_Medicamento = Inventario.ID_Medicamento  GROUP BY Medicamento.Nombre, Medicamento.Composicion , Medicamento.Laboratorio, Inventario.Cantidad ORDER BY Consumo");
        PdfWriter.getInstance(documento, new FileOutputStream(
                "reportes/reporte_de_consumo_medicamentos " + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Consumo Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Cantidad");
            table.addCell("Unidades consumidas");
            table.addCell("Porcentaje de consumo");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            consumo = res.getInt("Consumo");
            cantidad = res.getInt("Cantidad");
            porcentaje = consumo / cantidad * 100;
            System.out.println("consumo: " + consumo + " cantidad: " + cantidad + " porcentaje: " + porcentaje);
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("Cantidad"));
            table.addCell(res.getString("Consumo"));
            table.addCell(((df.format(porcentaje))) + "%");

        }
        documento.add(table);
        documento.close();
        JOptionPane.showMessageDialog(null, "Reporte de Consumo de Medicamentos generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }
}

From source file:Capa_Modelo.Reportes.java

public void generarReporteESMedicamentos() {
    Connection con;/*from w ww. java 2s  .  c  om*/
    ResultSet res, res2;
    Statement sentencia;
    Document documento = new Document(PageSize.A4);
    con = ConexionDB.GetConnection();
    try {
        sentencia = con.createStatement();
        res = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Medicamento.FechaLlegada, Inventario.Cantidad FROM Medicamento INNER JOIN Inventario ON Medicamento.ID_Medicamento = Inventario.ID_Medicamento ORDER BY Inventario.Cantidad, Medicamento.Nombre desc");
        PdfWriter.getInstance(documento, new FileOutputStream("reportes/reporte_de_entrada-salida_medicamentos "
                + fechaActual() + " " + horaActual() + ".pdf"));
        documento.open();
        float[] columnWidths = { 2, 2, 2, 2, 2 };
        PdfPTable table = new PdfPTable(columnWidths);
        table.setWidthPercentage(100);
        table.getDefaultCell().setUseAscender(true);
        table.getDefaultCell().setUseDescender(true);
        Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell cell = new PdfPCell(new Phrase("Reporte de Entrada de Medicamentos", f));
        cell.setBackgroundColor(GrayColor.GRAYBLACK);
        cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell.setColspan(8);
        table.addCell(cell);
        table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table.addCell("Medicamento");
            table.addCell("Composicion");
            table.addCell("Laboratorio");
            table.addCell("Fecha de Entrada");
            table.addCell("Cantidad");
        }
        table.setHeaderRows(3);
        table.setFooterRows(1);
        table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res.next()) {
            table.addCell(res.getString("Nombre"));
            table.addCell(res.getString("Composicion"));
            table.addCell(res.getString("Laboratorio"));
            table.addCell(res.getString("FechaLlegada"));
            table.addCell(res.getString("Cantidad"));
        }
        documento.add(table);
        documento.newPage();
        res2 = sentencia.executeQuery(
                "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, MedicinaPaciente.FechaEntrega, SUM(MedicinaPaciente.Cantidad) AS Entregados FROM Medicamento INNER JOIN MedicinaPaciente ON Medicamento.ID_Medicamento = MedicinaPaciente.ID_Medicamento  group by Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio,MedicinaPaciente.FechaEntrega ORDER BY Entregados");
        float[] columnWidths2 = { 2, 2, 2, 2, 2 };
        PdfPTable table2 = new PdfPTable(columnWidths);
        table2.setWidthPercentage(100);
        table2.getDefaultCell().setUseAscender(true);
        table2.getDefaultCell().setUseDescender(true);
        PdfPCell cell2 = new PdfPCell(new Phrase("Reporte de Salida de Medicamentos", f));
        cell2.setBackgroundColor(GrayColor.GRAYBLACK);
        cell2.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        cell2.setColspan(8);
        table2.addCell(cell2);
        table2.getDefaultCell().setBackgroundColor(new GrayColor(0.75f));
        for (int i = 0; i < 2; i++) {
            table2.addCell("Medicamento");
            table2.addCell("Composicion");
            table2.addCell("Laboratorio");
            table2.addCell("Fecha de Salida");
            table2.addCell("Cantidad");
        }
        table2.setHeaderRows(3);
        table2.setFooterRows(1);
        table2.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE);
        table2.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER);
        while (res2.next()) {
            table2.addCell(res2.getString("Nombre"));
            table2.addCell(res2.getString("Composicion"));
            table2.addCell(res2.getString("Laboratorio"));
            table2.addCell(res2.getString("FechaEntrega"));
            table2.addCell(res2.getString("Entregados"));
        }
        documento.add(table2);
        documento.close();
        JOptionPane.showMessageDialog(null,
                "Reporte de Entrada y Salida de Medicamentos generado correctamente");
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos");
    } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al generar el archivo");
    }
}

From source file:com.mycompany.mavenproject1.SubmitForm.java

public void extractFromPdf(String src, String dest) throws DocumentException, IOException {

    PdfReader reader = new PdfReader(src);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));

    PushbuttonField button = new PushbuttonField(stamper.getWriter(), new Rectangle(36, 700, 112, 730), "get");

    //stamper.getWriter().addJavaScript(Utilities.readFileToString(RESOURCE));
    button.setText("SAVE My INFO");
    button.setBackgroundColor(new GrayColor(0.7f));
    button.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
    PdfFormField submit = button.getField();

    /*/*from w ww. j  a v a2 s  . c  om*/
          button.setBackgroundColor(new GrayColor(0.7f));
          button.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
     */

    //PdfFormField pull_data = upload_info.getField();
    //  pull_data.setAction(PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter()));
    stamper.getWriter().addJavaScript(Utilities.readFileToString(checkbox));
    stamper.getWriter().addJavaScript(Utilities.readFileToString(upload_info));
    //PushbuttonField submitButton=stamper.getAcroFields().getNewPushbuttonFromField("UseSavedInfo");
    //PdfFormField field=submitButton.getField();
    //field.setAction(PdfAction.javaScript("app.alert('hello')" ,stamper.getWriter()));
    /*
     PushbuttonField useMySavedInfo = new PushbuttonField(
      stamper.getWriter(), new Rectangle(36, 1000, 559, 806), "MySavedInfo" );
      useMySavedInfo.setText("Upload info");
      useMySavedInfo.setBackgroundColor(new GrayColor(0.7f));
      useMySavedInfo.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
       PdfFormField  extractInfo=useMySavedInfo.getField();
    */
    //  extractInfo.setAction(PdfAction.javaScript("alert('hello')", stamper.getWriter()));
    //  extractInfo.setAction(PdfAction.);
    //stamper.

    /*
    AcroFields fields = stamper.getAcroFields();
     PushbuttonField submitButton=fields.getNewPushbuttonFromField("SubmitForm");
    */
    //System.out.println(submitButton.getAppearance().getHeight());
    //System.out.println(submitButton.getAppearance().getWidth());
    //System.out.println(submitButton.getAppearance());
    //submitButton
    //submitButton.getField().get
    //submitButton.getWriter().setAdditionalAction(, PdfAction.javaScript("app.alert('os')",stamper.getWriter()));
    //submitButton.getWriter().setAdditionalAction(PdfName., action);
    //PdfFormField sb=submitButton.getField();
    //sb.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter()));

    // sumbitInfo.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter()));
    //submit.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter()));

    //PushbuttonField useInfo = fields.getNewPushbuttonFromField("UseSavedInfo");
    //PdfAnnotation getInfo=useInfo.getField();
    //getInfo.setAction(PdfAction.javaScript("app.alert('action!')", stamper.getWriter()));

    // ffield.SetAdditionalActions(PdfName.E, PdfAction("app.alert('action!')"));

    AcroFields fields = stamper.getAcroFields();

    // PushbuttonField saveInfo = fields.getNewPushbuttonFromField("SaveInfo");
    //   PdfFormField fd=saveInfo.getField();
    //fd.setAction(PdfAction.createSubmitForm("http://127.0.0.1/index.php",null,PdfAction.SUBMIT_HTML_FORMAT));
    //PdfAppearance pa =saveInfo.getAppearance();
    // pa.setAction(PdfAction.createSubmitForm("http://127.0.0.1/index.php",null,PdfAction.SUBMIT_HTML_FORMAT), 0, 0, 0, 0);
    Set<String> fldNames = fields.getFields().keySet();

    //AcroFields fields = stamper.getAcroFields();
    for (String fldName : fldNames) {
        System.out.println(fldName + ": " + fields.getField(fldName));
    }
    //submit.setAdditionalAction(PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter()));
    //http://www.mycrewid.com/Alexander/index.php
    //submit.setAction(PdfAction.createSubmitForm(
    //       "http://127.0.0.1/index.php", null,
    //     PdfAction.SUBMIT_HTML_FORMAT));
    submit.setAction(
            PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter()));
    stamper.addAnnotation(submit, 1);
    stamper.close();
    //PdfAction.javaScript("this.getField('FirstName').value=util.printd(\"dd mmmm yyyy\",new Date())",stamper.getWriter());

    //stamper.addAnnotation(submitButton, 1);
    //stamper.addAnnotation(sb,1);
    // submit.setAdditionalActions(PdfName.E, PdfAction.javaScript(Utilities.readFileToString(submit_button_script),stamper.getWriter()));

}