Search in sources :

Example 1 with MReportColumn

use of org.compiere.report.MReportColumn in project adempiere by adempiere.

the class SmjPdfReport method generate.

/**
	 * genera el PDF en un ByteArrayOutputStream ** Generate PDF Report into
	 * ByteArrayOutputStream
	 * 
	 * @return ByteArrayOutputStream
	 */
public ByteArrayOutputStream generate(LinkedList<ReportTO> dataReport, String nameTrx, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String codeFont, String city, Integer logoId) {
    baosPDF = new ByteArrayOutputStream();
    data = dataReport;
    String[] fontPar = codeFont.split("-");
    Integer lFont = Integer.parseInt(fontPar[2]);
    titleFont = FontFactory.getFont(fontPar[0], lFont + 5, Font.BOLDITALIC);
    titleTableFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLDITALIC);
    catFont = FontFactory.getFont(fontPar[0], lFont + 2, Font.BOLD);
    subFont = FontFactory.getFont(fontPar[0], lFont, Font.NORMAL);
    try {
        // izq-der-arrib
        document = new Document(PageSize.LETTER, 20, 20, 20, 40);
        writer = PdfWriter.getInstance(document, baosPDF);
        document.open();
        // metadata del documento
        document.addTitle(generalTitle[0]);
        document.addAuthor("SmartJSP S.A.S.");
        document.addCreator("SmartJSP S.A.S.");
        onOpenDocument(writer, document);
        onEndPage(writer, document);
        // //////////////////////////////////////////////////////////////////////////////////////
        // agrega el logo
        // add logo
        java.awt.Image img;
        if (logoId > 0) {
            MImage mimage = MImage.get(Env.getCtx(), logoId);
            byte[] imageData = mimage.getData();
            img = Toolkit.getDefaultToolkit().createImage(imageData);
        } else {
            // 48x15
            img = org.compiere.Adempiere.getImageLogoSmall(true);
        }
        com.lowagie.text.Image logo = com.lowagie.text.Image.getInstance(img, null);
        logo.scaleToFit(100, 30);
        document.add(logo);
        // Titulo General - general Title
        Paragraph genTitle = new Paragraph(dataNull(generalTitle[0]).toUpperCase(), titleFont);
        genTitle.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(genTitle);
        // empresa - Company
        Paragraph clitName = new Paragraph(dataNull(clientName).toUpperCase(), titleFont);
        clitName.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(clitName);
        // Ciudad - City
        Paragraph cliCity = new Paragraph(dataNull(city).toUpperCase(), titleFont);
        cliCity.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(cliCity);
        // NIT
        Paragraph cliNIT = new Paragraph(dataNull(clientNIT).toUpperCase(), titleFont);
        cliNIT.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(cliNIT);
        // periodo - Period
        String pn = "";
        if (generalTitle[1] != null && generalTitle[1].length() > 0) {
            pn = generalTitle[1] + " " + periodName;
        } else {
            pn = periodName;
        }
        if (generalTitle[2] != null && generalTitle[2].length() > 0) {
            pn = pn + " " + generalTitle[2];
        }
        Paragraph perName = new Paragraph(dataNull(pn).toUpperCase(), titleTableFont);
        perName.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(perName);
        // tipo moneda - currency
        Paragraph currency = new Paragraph(dataNull(currencyName), titleTableFont);
        currency.setAlignment(Paragraph.ALIGN_CENTER);
        addEmptyLine(currency, 2);
        document.add(currency);
        cols = m_columns.length + 2;
        float[] columnWidths = new float[cols];
        columnWidths[0] = 1f;
        columnWidths[1] = 3f;
        for (int i = 2; i < cols; i++) {
            columnWidths[i] = 1f;
        }
        table = new PdfPTable(columnWidths);
        // //Titulos de la tabla - Table titles
        // Nombre - name
        PdfPCell cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "name").toUpperCase(), catFont));
        cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
        cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cellTitle);
        // Desripcion - description
        cellTitle = new PdfPCell(new Paragraph(Msg.translate(Env.getCtx(), "description").toUpperCase(), catFont));
        cellTitle.setHorizontalAlignment(Paragraph.ALIGN_LEFT);
        cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
        table.addCell(cellTitle);
        // columnas de valores - Value Columns
        for (MReportColumn mcol : m_columns) {
            String colName = mcol.getName();
            cellTitle = new PdfPCell(new Paragraph(colName.toUpperCase(), catFont));
            cellTitle.setHorizontalAlignment(Paragraph.ALIGN_RIGHT);
            cellTitle.setBackgroundColor(Color.LIGHT_GRAY);
            table.addCell(cellTitle);
        }
        //for columnas
        // TABLA DEL REPORTE - REPORT TABLE
        reportTable();
        document.add(table);
        // funciones que ponen el pie del porte - put footer
        onEndPage(writer, document);
        onCloseDocument(writer, document);
        document.close();
    } catch (Exception e) {
        System.out.println("SMpdfReport(generar)ERROR:: al crear el documento PDF");
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    return baosPDF;
}
Also used : PdfPCell(com.lowagie.text.pdf.PdfPCell) MReportColumn(org.compiere.report.MReportColumn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.lowagie.text.Document) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Paragraph(com.lowagie.text.Paragraph) MImage(org.compiere.model.MImage) PdfPTable(com.lowagie.text.pdf.PdfPTable)

Example 2 with MReportColumn

use of org.compiere.report.MReportColumn in project adempiere by adempiere.

the class ReportColumnSet_Copy method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message
	 *  @throws Exception
	 */
protected String doIt() throws Exception {
    int to_ID = super.getRecord_ID();
    log.info("From PA_ReportColumnSet_ID=" + m_PA_ReportColumnSet_ID + ", To=" + to_ID);
    if (to_ID < 1)
        throw new Exception(MESSAGE_SaveErrorRowNotFound);
    //
    MReportColumnSet to = new MReportColumnSet(getCtx(), to_ID, get_TrxName());
    MReportColumnSet rcSet = new MReportColumnSet(getCtx(), m_PA_ReportColumnSet_ID, get_TrxName());
    MReportColumn[] rcs = rcSet.getColumns();
    for (int i = 0; i < rcs.length; i++) {
        MReportColumn rc = MReportColumn.copy(getCtx(), to.getAD_Client_ID(), to.getAD_Org_ID(), to_ID, rcs[i], get_TrxName());
        rc.saveEx();
    }
    //	Oper 1/2 were set to Null !
    return "@Copied@=" + rcs.length;
}
Also used : MReportColumn(org.compiere.report.MReportColumn) MReportColumnSet(org.compiere.report.MReportColumnSet)

Example 3 with MReportColumn

use of org.compiere.report.MReportColumn in project adempiere by adempiere.

the class SmjXlsReport method titleTable.

// generate
/**
	 * Crea la fila de titulos - create title row
	 * @param wb
	 * @param hs
	 * @param fila
	 * @param colsName
	 */
private void titleTable(HSSFWorkbook book, HSSFSheet sheet, int fila, MReportColumn[] m_columns) {
    short col = 0;
    // crea fuente - create font
    HSSFFont font = book.createFont();
    font.setFontHeightInPoints((short) 13);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    //		font.setColor(HSSFColor.BLUE.index);
    // estio celda - cell style
    HSSFCellStyle cellStyle = book.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    //		cellStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
    //		cellStyle.setFillBackgroundColor(HSSFColor.GREY_40_PERCENT.index);
    cellStyle.setFont(font);
    // //Titulos de la tabla - Table titles
    HSSFRow row = sheet.createRow(fila);
    // Nombre - name
    HSSFRichTextString text = new HSSFRichTextString(Msg.translate(Env.getCtx(), "name").toUpperCase());
    HSSFCell cell = row.createCell(col++);
    cell.setCellStyle(cellStyle);
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue(text);
    // Desripcion - description
    text = new HSSFRichTextString(Msg.translate(Env.getCtx(), "description").toUpperCase());
    cell = row.createCell(col++);
    cell.setCellStyle(cellStyle);
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue(text);
    // columnas de valores - Value Columns
    for (MReportColumn mcol : m_columns) {
        String colName = mcol.getName();
        text = new HSSFRichTextString(colName.toUpperCase());
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
    }
//for columnas
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) MReportColumn(org.compiere.report.MReportColumn) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Aggregations

MReportColumn (org.compiere.report.MReportColumn)3 Document (com.lowagie.text.Document)1 Paragraph (com.lowagie.text.Paragraph)1 PdfPCell (com.lowagie.text.pdf.PdfPCell)1 PdfPTable (com.lowagie.text.pdf.PdfPTable)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)1 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)1 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)1 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)1 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)1 MImage (org.compiere.model.MImage)1 MReportColumnSet (org.compiere.report.MReportColumnSet)1