@Override
  public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
      throws IOException, ServletException {
    arg2.doFilter(arg0, arg1);

    HttpServletRequest request = (HttpServletRequest) arg0;
    ResponseWrapper response = (ResponseWrapper) arg1;

    if ("doOperation".equals(request.getParameter("method"))
        && "PRINT_ALL_DOCUMENTS".equals(request.getParameter("operationType"))) {

      try {
        // clean the response html and make a DOM document out of it
        String responseHtml = clean(response.getContent());
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = builder.parse(new ByteArrayInputStream(responseHtml.getBytes()));

        // alter paths of link/img tags so itext can use them properly
        patchLinks(doc, request);

        // structure pdf document
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(doc, "");
        renderer.layout();

        // create the pdf
        ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
        renderer.createPDF(pdfStream);

        // concatenate with other docs
        final Person person = (Person) request.getAttribute("person");
        final StudentCandidacy candidacy = getCandidacy(request);
        ByteArrayOutputStream finalPdfStream =
            concatenateDocs(pdfStream.toByteArray(), person, candidacy);
        byte[] pdfByteArray = finalPdfStream.toByteArray();

        // associate the summary file to the candidacy
        associateSummaryFile(pdfByteArray, person.getStudent().getNumber().toString(), candidacy);

        // redirect user to the candidacy summary page
        response.reset();
        response.sendRedirect(buildRedirectURL(request, candidacy));

        response.flushBuffer();
      } catch (ParserConfigurationException e) {
        logger.error(e.getMessage(), e);
      } catch (SAXException e) {
        logger.error(e.getMessage(), e);
      } catch (DocumentException e) {
        logger.error(e.getMessage(), e);
      }
    }
  }
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          try {

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();
            java.sql.Statement st2x = connectDB.createStatement();

            java.sql.ResultSet rset2x =
                st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
            while (rset2x.next()) {
              ks = rset2x.getObject(1).toString();
            }
            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Price List - Page: "),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(5);

            int headerwidths[] = {20, 50, 30, 30, 30};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            // table.setHeaderRows(2);

            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.LEFT | Rectangle.RIGHT);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

            Phrase phrase = new Phrase(" ");
            //  table.addCell(phrase);

            try {
              table.getDefaultCell().setColspan(5);
              phrase = new Phrase("Departmental Price List ");
              table.addCell(phrase);
              table.getDefaultCell().setColspan(4);
              java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset3 =
                  st2.executeQuery(
                      "SELECT DISTINCT activity FROM pb_activity WHERE code ILIKE  '" + bank + "'");

              while (rset3.next()) {
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                phrase =
                    new Phrase(
                        rset3.getString(1).toUpperCase()
                            + " - "
                            + bank
                            + " Price List as at : "
                            + date,
                        pFontHeader);

                table.addCell(phrase);
              }
              //  Phrase phrase = new Phrase(bank +"    Balance Report"    +"  as at : "  +endDate,
              // pFontHeader);

              //  table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase = new Phrase("Printed on : " + date, pFontHeader);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("CODE", pFontHeader);
              table.addCell(phrase);

              //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase("DESCRIPTION", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              // phrase = new Phrase("",pFontHeader);
              // table.addCell(phrase);

              phrase = new Phrase("Norminal Rate (E.A) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("Special Rate (PRIVATE) " + ks, pFontHeader);
              table.addCell(phrase);

              phrase = new Phrase("NON E.A " + ks, pFontHeader);
              table.addCell(phrase);

              // phrase = new Phrase("Credit KShs.",pFontHeader);
              // table.addCell(phrase);

              // table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
              // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              double osBalance = 0.00;

              //  java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              java.sql.Statement st = connectDB.createStatement();

              //  java.sql.Statement st2 = connectDB.createStatement();

              // java.sql.ResultSet rset = st.executeQuery("select code,upper(service_type) as
              // description,rate from pricelist WHERE main_service ilike '"+bank+"%' order by
              // service_type");// tn,debit_note db WHERE tn.policy_no != '' and tn.policy_no =
              // db.policy_no GROUP BY tn.policy_no,db.policy_class");

              System.out.println("Printing Price List for GL/CODE : [" + bank + "]");

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "SELECT code, upper(service_type), rate, anaesthetist_rate,other_prices FROM pb_operating_parameters WHERE gl_account ilike  '"
                          + bank
                          + "' order by service_type");

              while (rset.next()) {
                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);

                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);

                table.addCell(phrase);

                //  table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(3)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(4)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader);
                //  osBalance = osBalance + rset1.getDouble(6);
                table.addCell(phrase);
              }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Esempio n. 3
1
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      // com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Orders - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(7);

            int headerwidths[] = {12, 10, 30, 30, 8, 8, 12};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(5);

            Phrase phrase = new Phrase("Orders list as at: " + endDate, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
            table.getDefaultCell().setColspan(2);
            phrase = new Phrase("Printed on : " + date, pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
            phrase = new Phrase("Order No", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Date Due", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Supplier", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Item", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Units", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Qty", pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
            phrase = new Phrase("Net Value", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.lang.Object[] listofAct = this.getListofActivities();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();

              for (int i = 0; i < listofAct.length; i++) {
                int w = 0;
                java.sql.ResultSet rset3 =
                    st3.executeQuery(
                        "SELECT DISTINCT order_no,date_due AS date,supplier from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY date");

                java.sql.ResultSet rset =
                    st.executeQuery(
                        "SELECT item,units,quantity,net_value from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND order_no = '"
                            + listofAct[i].toString()
                            + "' ORDER BY item");
                java.sql.ResultSet rsetTotals =
                    st2.executeQuery(
                        "SELECT SUM(net_value) from st_orders WHERE date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "'  AND order_no = '"
                            + listofAct[i].toString()
                            + "'");

                while (rset3.next()) {
                  while (rset.next()) {
                    w = w + 1;

                    if (w == 1) {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(2).toString(), pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset3.getObject(3).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);

                    } else {
                      table.getDefaultCell().setColspan(1);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);

                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                      table.addCell(phrase);
                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(3)),
                              pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(rset.getString(4)),
                              pFontHeader1);
                      table.addCell(phrase);
                    }
                  }
                }
                // table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                // table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

                while (rsetTotals.next()) {

                  table.getDefaultCell().setColspan(5);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  phrase = new Phrase("Total", pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                  phrase = new Phrase((""), pFontHeader);

                  table.addCell(phrase);

                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rsetTotals.getString(1)),
                          pFontHeader);

                  table.addCell(phrase);
                }
              }
              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Esempio n. 4
0
  /**
   * Demonstrates creating a footer with the current page number
   *
   * @param args Unused
   */
  public static void main(String[] args) {
    System.out.println("Demonstrates creating a footer with a page number");
    try {
      Document document = new Document();
      RtfWriter2.getInstance(document, new FileOutputStream("PageNumber.rtf"));

      // Create a new Paragraph for the footer
      Paragraph par = new Paragraph("Page ");
      par.setAlignment(Element.ALIGN_RIGHT);

      // Add the RtfPageNumber to the Paragraph
      par.add(new RtfPageNumber());

      // Create an RtfHeaderFooter with the Paragraph and set it
      // as a footer for the document
      RtfHeaderFooter footer = new RtfHeaderFooter(par);
      document.setFooter(footer);

      document.open();

      for (int i = 1; i <= 300; i++) {
        document.add(new Paragraph("Line " + i + "."));
      }

      document.close();
    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    } catch (DocumentException de) {
      de.printStackTrace();
    }
  }
Esempio n. 5
0
  /**
   * An example using MultiColumnText with irregular columns.
   *
   * @param args no arguments needed
   */
  public static void main(String[] args) {

    System.out.println("Simple MultiColumnText");
    try {
      Document document = new Document();
      OutputStream out = new FileOutputStream("multicolumnsimple.pdf");
      PdfWriter.getInstance(document, out);
      document.open();

      MultiColumnText mct = new MultiColumnText();

      // set up 3 even columns with 10pt space between
      mct.addRegularColumns(document.left(), document.right(), 10f, 3);

      // Write some iText poems
      for (int i = 0; i < 30; i++) {
        mct.addElement(new Paragraph(String.valueOf(i + 1)));
        mct.addElement(newPara(randomWord(noun), Element.ALIGN_CENTER, Font.BOLDITALIC));
        for (int j = 0; j < 4; j++) {
          mct.addElement(newPara(poemLine(), Element.ALIGN_LEFT, Font.NORMAL));
        }
        mct.addElement(newPara(randomWord(adverb), Element.ALIGN_LEFT, Font.NORMAL));
        mct.addElement(newPara("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
      }
      document.add(mct);
      document.close();
    } catch (DocumentException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
 public void closeColumn() {
   try {
     pdfDocument.add(mct);
   } catch (DocumentException ex) {
     WikiLogger.getLogger().severe(ex.getMessage());
     // throw new Exception(ex);
   }
 }
Esempio n. 7
0
  /**
   * Generates simple PDF, RTF and HTML files using only one Document object.
   *
   * @param args no arguments needed here
   */
  public static void main(String[] args) {

    System.out.println("Hello World in PDF, RTF and HTML");

    // step 1: creation of a document-object
    Document document = new Document();
    try {
      // step 2:
      // we create 3 different writers that listen to the document
      File file1 = new File("HelloWorldPdf.pdf");
      File file2 = new File("HelloWorldRtf.rtf");
      File file3 = new File("HelloWorldHtml.html");

      if (!file1.exists()) {
        file1.canWrite();
      }
      if (!file2.exists()) {
        file2.canWrite();
      }
      if (!file3.exists()) {
        file3.canWrite();
      }

      PdfWriter pdf = PdfWriter.getInstance(document, new FileOutputStream(file1));
      RtfWriter2 rtf = RtfWriter2.getInstance(document, new FileOutputStream(file2));
      HtmlWriter.getInstance(document, new FileOutputStream(file3));

      // step 3: we open the document
      document.open();
      // step 4: we add a paragraph to the document
      document.add(new Paragraph("Hello World"));

      // we make references
      Anchor pdfRef = new Anchor("see Hello World in PDF.");
      pdfRef.setReference("./HelloWorldPdf.pdf");

      Anchor rtfRef = new Anchor("see Hello World in RTF.");
      rtfRef.setReference("./HelloWorldRtf.rtf");

      // we add the references, but only to the HTML page:

      pdf.pause();
      rtf.pause();
      document.add(pdfRef);
      document.add(Chunk.NEWLINE);
      document.add(rtfRef);
      pdf.resume();
      rtf.resume();

    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }

    // step 5: we close the document
    document.close();
  }
 private boolean txt2Pdf(File inputFile, File outputFile, Charset inputFileCharset) {
   // // 先将txt转成odt
   // String fileName = inputFile.getAbsolutePath();
   // if (fileName.endsWith(".txt")) {
   BufferedReader bufferedReader = null;
   try {
     // 判断原始txt文件的编码格式,获取响应的文件读入
     bufferedReader =
         new BufferedReader(
             new InputStreamReader(new FileInputStream(inputFile), inputFileCharset));
     // 将txt内容直接生成pdf
     Document document = new Document();
     BaseFont bfChinese =
         BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
     Font font_normal = new Font(bfChinese, 10, Font.NORMAL); // 设置字体大小
     document.setPageSize(PageSize.A4); // 设置页面大小
     if (!outputFile.exists()) {
       outputFile.createNewFile();
     }
     try {
       PdfWriter.getInstance(document, new FileOutputStream(outputFile));
       document.open();
     } catch (Exception e) {
       e.printStackTrace();
     }
     String content = null;
     while ((content = bufferedReader.readLine()) != null) {
       document.add(new Paragraph(content, font_normal));
     }
     document.close();
     bufferedReader.close();
     return true;
   } catch (ConnectException cex) {
     cex.printStackTrace();
     // System.out.println("转换失败!");
     return false;
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     return false;
   } catch (IOException e) {
     e.printStackTrace();
     return false;
   } catch (DocumentException e) {
     e.printStackTrace();
     return false;
   } finally {
     // close the connection
     if (bufferedReader != null) {
       try {
         bufferedReader.close();
       } catch (IOException e) {
         e.printStackTrace();
       }
     }
   }
   // }
 }
  @SuppressWarnings("static-access")
  public String downloadReport() {
    String type = getParaValue("type");
    CompReportHelper helper = new CompReportHelper();
    Hashtable allData = helper.getAllDevice();
    Vector vector = null;
    List deviceList = new ArrayList();
    String file = ""; // 保存到项目文件夹下的指定文件夹
    String filePath = ""; // 获取系统文件夹路径
    if (allData != null) {
      if (allData.containsKey("deviceVec")) {
        vector = (Vector) allData.get("deviceVec");
        helper.createPie(vector);
      }
      if (allData.containsKey("deviceList")) {
        deviceList = (List) allData.get("deviceList");
        if (type.equals("doc")) {
          file = "/temp/allDevice.doc";
          filePath = ResourceCenter.getInstance().getSysPath() + file;
          try {
            helper.createDoc(vector, deviceList, filePath);
          } catch (DocumentException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        } else if (type.equals("xls")) {

          file = "/temp/allDevice.xls";
          filePath = ResourceCenter.getInstance().getSysPath() + file;

          try {
            helper.createExcel(vector, deviceList, filePath);
          } catch (WriteException e) {
            e.printStackTrace();
          }

        } else if (type.equals("pdf")) {
          file = "/temp/allDevice.pdf";
          filePath = ResourceCenter.getInstance().getSysPath() + file;
          try {
            helper.createPdf(vector, deviceList, filePath);
          } catch (DocumentException e) {
            e.printStackTrace();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
    request.setAttribute("filename", filePath);
    return "/capreport/net/download.jsp";
  }
Esempio n. 10
0
  public void geraCabecalhoPDF(
      final int tam,
      final GerencialItemInformationDTO gerencialItemDto,
      final PdfPTable tableParm,
      final PdfWriter writer,
      final Document document,
      final Rectangle page) {
    final PdfPTable table = new PdfPTable(tamTabela);
    table.setWidthPercentage(100);
    try {
      table.setWidths(tamanhoColunasReal);
    } catch (final DocumentException e1) {
      e1.printStackTrace();
    }

    for (int j = 0; j < tam; j++) {
      final PdfPCell cell = new PdfPCell();
      final GerencialFieldDTO fieldDto =
          (GerencialFieldDTO) ((List) gerencialItemDto.getListFields()).get(j);

      final GerencialGroupDTO grupoDefinicaoDto =
          this.fieldInGroupDefinition(fieldDto.getName(), gerencialItemDto.getListGroups());
      if (grupoDefinicaoDto == null) { // So mostra se nao for um agrupador
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.String")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
          cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Double")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
          cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.lang.Integer")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
          cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        }
        if (fieldDto.getClassField().getName().equalsIgnoreCase("java.sql.Date")) {
          table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
          cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        }
        cell.setBackgroundColor(Color.GRAY);
        cell.setPhrase(new Phrase(fieldDto.getTitle()));
        table.addCell(cell);
      }
    }
    final PdfPCell celula0 = new PdfPCell(new Phrase(" "));
    celula0.setColspan(2);
    celula0.setBorder(0);
    tableParm.addCell(celula0);

    final PdfPCell celula = new PdfPCell(table);
    celula.setColspan(2);
    tableParm.addCell(celula);
  }
Esempio n. 11
0
  /**
   * Generates a PDF file with the text 'Hello World'
   *
   * @param args no arguments needed here
   */
  public static byte[] getDashboardPDFAsByteArray() {

    String localProviderURL = "t3://localhost:7001";
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    System.setProperty(Context.PROVIDER_URL, localProviderURL);

    System.out.println("Generating VINSight DashBoard Reports");

    // step 1: creation of a document-object
    Document document = new Document();

    ByteArrayOutputStream baos = new ByteArrayOutputStream(100000);

    try {
      // step 2
      PdfWriter writer;
      writer = PdfWriter.getInstance(document, baos);
      // step 3
      document.open();
      // step 4: we add a paragraph to the document
      document.add(new Paragraph("VINSight Health Check"));
      document.add(new Paragraph("Report 1"));

      // create the chart1 image
      JFreeChart chart1 = VINSightDashboardReport.createVINSightDashBoardChart1();
      BufferedImage image1 = chart1.createBufferedImage(350, 350);
      image1.flush();

      document.add(com.lowagie.text.Image.getInstance(image1, null));
      document.add(new Paragraph("Report 2"));
      JFreeChart chart2 = VINSightDashboardReport.createVINSightDashBoardChart2();
      BufferedImage image2 = chart2.createBufferedImage(350, 350);
      image2.flush();

      document.add(com.lowagie.text.Image.getInstance(image2, null));

    } catch (DocumentException de) {
      de.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      // step 5
      document.close();
      try {
        baos.close();
      } catch (IOException ioe) {
        /*ignore*/
      }
    }

    return baos.toByteArray();
  }
Esempio n. 12
0
 public void exportGraphic(Picture picture, OutputStream out) throws IOException {
   int width = picture.getPictureWidth();
   int height = picture.getPictureHeight();
   Document doc = new Document(new com.lowagie.text.Rectangle(width, height));
   try {
     PdfWriter pWriter = PdfWriter.getInstance(doc, out);
     doc.open();
     Graphics2D g = pWriter.getDirectContent().createGraphics(width, height);
     picture.paintPicture(g);
     g.dispose();
     doc.close();
   } catch (DocumentException e) {
     throw (IOException) new IOException(e.getMessage()).initCause(e);
   }
 }
Esempio n. 13
0
  /**
   * Extended headers / footers example
   *
   * @param args Unused
   */
  public static void main(String[] args) {
    System.out.println("Demonstrates use of the RtfHeaderFooter for extended headers and footers");
    try {
      Document document = new Document();
      RtfWriter2.getInstance(document, new FileOutputStream("ExtendedHeaderFooter.rtf"));

      // Create the Paragraphs that will be used in the header.
      Paragraph date = new Paragraph("01.01.2010");
      date.setAlignment(Paragraph.ALIGN_RIGHT);
      Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" + "+00 99 11 22 33 44");

      // Create the RtfHeaderFooter with an array containing the Paragraphs to add
      RtfHeaderFooter header = new RtfHeaderFooter(new Element[] {date, address});

      // Set the header
      document.setHeader(header);

      // Create the table that will be used as the footer
      Table footer = new Table(2);
      footer.setBorder(0);
      footer.getDefaultCell().setBorder(0);
      footer.setWidth(100);
      footer.addCell(new Cell("(c) Mark Hall"));
      Paragraph pageNumber = new Paragraph("Page ");

      // The RtfPageNumber is an RTF specific element that adds a page number field
      pageNumber.add(new RtfPageNumber());
      pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
      footer.addCell(new Cell(pageNumber));

      // Create the RtfHeaderFooter and set it as the footer to use
      document.setFooter(new RtfHeaderFooter(footer));

      document.open();

      document.add(
          new Paragraph(
              "This document has headers and footers created"
                  + " using the RtfHeaderFooter class."));

      document.close();
    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    } catch (DocumentException de) {
      de.printStackTrace();
    }
  }
Esempio n. 14
0
  /**
   * Invokes the createPOQuotePDF method to create a purchase order quote pdf document and saves it
   * into a file which name and location are specified in the pdfParameters.
   *
   * @param po The PurchaseOrderDocument to be used to generate the pdf.
   * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
   * @param pdfFileLocation The location to save the pdf file.
   * @param pdfFilename The name for the pdf file.
   * @param campusName The campus name to be used to generate the pdf.
   * @param contractManagerCampusCode The contract manager campus code to be used to generate the
   *     pdf.
   * @param logoImage The logo image file name to be used to generate the pdf.
   * @param environment The current environment used (e.g. DEV if it is a development environment).
   */
  public void savePOQuotePDF(
      PurchaseOrderDocument po,
      PurchaseOrderVendorQuote poqv,
      PurchaseOrderParameters transmitParameters,
      String environment) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("savePOQuotePDF() started for po number " + po.getPurapDocumentIdentifier());
    }

    try {
      PurchaseOrderTransmitParameters orderTransmitParameters =
          (PurchaseOrderTransmitParameters) transmitParameters;
      CampusParameter deliveryCampus = orderTransmitParameters.getCampusParameter();
      if (deliveryCampus == null) {
        throw new RuntimeException(" delivery campus is null");
      }
      String campusName = deliveryCampus.getCampus().getName();
      if (campusName == null) {

        throw new RuntimeException("Campus Information is missing - campusName: " + campusName);
      }
      Document doc = this.getDocument(9, 9, 70, 36);
      PdfWriter writer =
          PdfWriter.getInstance(
              doc,
              new FileOutputStream(
                  orderTransmitParameters.getPdfFileLocation()
                      + orderTransmitParameters.getPdfFileName()));
      this.createPOQuotePdf(
          po,
          poqv,
          campusName,
          orderTransmitParameters.getContractManagerCampusCode(),
          orderTransmitParameters.getLogoImage(),
          doc,
          writer,
          environment);
    } catch (DocumentException de) {
      LOG.error(de.getMessage(), de);
      throw new PurError("Document Exception when trying to save a Purchase Order Quote PDF", de);
    } catch (FileNotFoundException f) {
      LOG.error(f.getMessage(), f);
      throw new PurError(
          "FileNotFound Exception when trying to save a Purchase Order Quote PDF", f);
    }
  }
Esempio n. 15
0
  public Document createForm(Document document) {
    System.out.println("[StockBalancePdfForm][createForm][Begin]");

    try {
      document.add(this.genHeader());
      document.add(this.brLine());
      document.add(this.brLine());
      document.add(this.genDetail());

    } catch (DocumentException de) {
      de.printStackTrace();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      System.out.println("[StockBalancePdfForm][createForm][End]");
    }

    return document;
  }
Esempio n. 16
0
  /**
   * Extended font example.
   *
   * @param args Unused
   */
  public static void main(String[] args) {
    System.out.println("Demonstrates the extended font support");
    try {
      Document document = new Document();
      RtfWriter2.getInstance(document, new FileOutputStream("ExtendedFont.rtf"));
      document.open();

      // Create a RtfFont with the desired font name.
      RtfFont msComicSans = new RtfFont("Comic Sans MS");

      // Use the RtfFont like any other Font.
      document.add(new Paragraph("This paragraph uses the" + " Comic Sans MS font.", msComicSans));

      // Font size, font style and font colour can also be specified.
      RtfFont bigBoldGreenArial = new RtfFont("Arial", 36, Font.BOLD, Color.GREEN);

      document.add(new Paragraph("This is a really big bold green Arial text", bigBoldGreenArial));
      document.close();
    } catch (FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    } catch (DocumentException de) {
      de.printStackTrace();
    }
  }
Esempio n. 17
0
  /**
   * Generates the purchase order quote pdf document based on the data in the given input
   * parameters, creates a pdf writer using the given byteArrayOutputStream then write the pdf
   * document into the writer.
   *
   * @param po The PurchaseOrderDocument to be used to generate the pdf.
   * @param poqv The PurchaseOrderVendorQuote to be used to generate the pdf.
   * @param campusName The campus name to be used to generate the pdf.
   * @param contractManagerCampusCode The contract manager campus code to be used to generate the
   *     pdf.
   * @param logoImage The logo image file name to be used to generate the pdf.
   * @param byteArrayOutputStream The ByteArrayOutputStream to print the pdf to.
   * @param environment The current environment used (e.g. DEV if it is a development environment).
   */
  public void generatePOQuotePDF(
      PurchaseOrderDocument po,
      PurchaseOrderVendorQuote poqv,
      String campusName,
      String contractManagerCampusCode,
      String logoImage,
      ByteArrayOutputStream byteArrayOutputStream,
      String environment) {
    if (LOG.isDebugEnabled()) {
      LOG.debug("generatePOQuotePDF() started for po number " + po.getPurapDocumentIdentifier());
    }

    Collection errors = new ArrayList();

    try {
      Document doc = getDocument(9, 9, 70, 36);
      PdfWriter writer = PdfWriter.getInstance(doc, byteArrayOutputStream);
      this.createPOQuotePdf(
          po, poqv, campusName, contractManagerCampusCode, logoImage, doc, writer, environment);
    } catch (DocumentException de) {
      LOG.error(de.getMessage(), de);
      throw new PurError("Document Exception when trying to save a Purchase Order Quote PDF", de);
    }
  }
Esempio n. 18
0
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          /*    try {

                java.lang.Class.forName("org.postgresql.Driver");

            } catch(java.lang.ClassNotFoundException cnfExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), cnfExec.getMessage());

            }
          */

          String compName = null;
          String date = null;
          try {

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));

            // com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("OP Rev BreakDown - Page: "),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(3);

            int headerwidths[] = {
              50, 20, 30,
            };

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(3);
            Phrase phrase = new Phrase("", pFontHeader);

            try {
              java.text.DateFormat dateFormat =
                  java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

              java.util.Date endDate1 =
                  dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());
              java.util.Date endDate11 =
                  dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

              System.out.println("" + endDate1);
              //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
              // pFontHeader);

              //  table.addCell(phrase);
              table.getDefaultCell().setColspan(3);

              phrase =
                  new Phrase(bank.toUpperCase() + "    Revenue Break Down Report(OP)", pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);

              phrase =
                  new Phrase(
                      "Period : From "
                          + dateFormat.format(endDate11)
                          + " To "
                          + dateFormat.format(endDate1),
                      pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase = new Phrase("Printed On  :" + date, pFontHeader);

              table.addCell(phrase);
            } catch (java.text.ParseException psExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), psExec.getMessage());
            }
            // Phrase phrase = new Phrase("Patients List As At:" +endDate, pFontHeader);

            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(2);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);

            phrase = new Phrase("Description", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            //     table.addCell("Reference No.");
            table.getDefaultCell().setColspan(1);
            phrase = new Phrase("Amount KShs.", pFontHeader);
            table.addCell(phrase);

            // phrase = new Phrase("Credit KShs.",pFontHeader);
            // table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            // table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              //  java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              java.sql.Statement st = connectDB.createStatement();

              java.sql.Statement st2 = connectDB.createStatement();

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "select UPPER(service),sum(amount) from ac_ledger WHERE date BETWEEN '"
                          + beginDate
                          + "' AND '"
                          + endDate
                          + "' AND activity_code ilike '"
                          + bank
                          + "'  AND drawer = 'OP' group by service_type order by service_type ");

              while (rset.next()) {
                table.getDefaultCell().setColspan(2);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);

                //   table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                //  phrase = new Phrase(rset.getObject(3).toString(), pFontHeader1);

                //   table.addCell(phrase);

                //   phrase = new Phrase(rset.getObject(4).toString(), pFontHeader1);

                //   table.addCell(phrase);

                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                //  phrase = new Phrase(new
                // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),pFontHeader);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(2)),
                        pFontHeader1);
                table.addCell(phrase);
                balance = balance + rset.getDouble(2);
                //  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                //  phrase = new  Phrase(new
                // com.afrisoftech.sys.Format2Currency().Format2Currency(rset.getString(6)),pFontHeader1);
                //  table.addCell(phrase);
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              // while (rsetTotals.next()) {

              table.getDefaultCell().setColspan(2);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(balance)),
                      pFontHeader);

              table.addCell(phrase);

              // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              // phrase = new Phrase(new
              // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(2)),pFontHeader);

              // table.addCell(phrase);

              // }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Esempio n. 19
0
  @Override
  public void doBody(PdfWriter writer, Document docu) {
    {
      float[] colsSize = {1f, 1f, 1f};
      PdfPTable table = new PdfPTable(colsSize);
      //      table.setTotalWidth(90);
      table.setWidthPercentage(100);
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
      PdfPCell cell = new PdfPCell();
      addCell(table, "警語", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3);
      addCell(table, "核發機關:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1);
      addCell(table, "核發案號:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1);
      addCell(table, "申請範圍:親等", cell, PDFReport.CELL_ALIGN_RIGHT, PDFReport.CELL_NO_BORDER, 1);
      addCell(table, "申請事由:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3);
      addCell(table, "法令依據:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 3);
      addCell(table, "資料最後異動日期:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1);
      addCell(table, "列印日期:", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1);
      addCell(table, " ", cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_NO_BORDER, 1);
      table.setSpacingAfter(10);
      try {
        docu.add(table);
      } catch (DocumentException e) {
        e.printStackTrace();
      }
    }

    for (int okok = 0; okok < 5; okok++) {
      float[] titleWidth = {1f};
      PdfPTable table = new PdfPTable(titleWidth);
      table.setWidthPercentage(100);
      PdfPCell titalCell = new PdfPCell();
      titalCell.setMinimumHeight(20);
      addCell(
          table, "親等關聯資料", titalCell, PDFReport.CELL_ALIGN_CENTER, PDFReport.CELL_NO_BORDER, 1, 16);
      titalCell.setMinimumHeight(5);
      try {
        docu.add(table);
      } catch (DocumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      table = new PdfPTable(new float[] {20f, 20f, 20f, 20f, 20f});
      table.setWidthPercentage(100f); // 設定整體寬度
      PdfPCell cell = new PdfPCell();
      for (int ii = 0; ii < 77; ii++) {
        addCell(table, String.valueOf(ii), cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_BOX, 1);
        if (ii > 5 && (ii % 5 == 0)) {
          addCell(
              table, String.valueOf(ii), cell, PDFReport.CELL_ALIGN_LEFT, PDFReport.CELL_BOX, 5);
        }
      }
      table.setSpacingAfter(15);

      try {
        docu.add(table);
      } catch (DocumentException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    }
  }
Esempio n. 20
0
  public void generatePdf() {

    java.util.Calendar calLast = java.util.Calendar.getInstance();

    calLast.roll(java.util.Calendar.YEAR, -1);

    dateLastyear = calLast.getTime().toString();

    System.out.println(this.dateLastyear);

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          try {

            //    java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("CORPORATION TAX - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(4);

            int headerwidths[] = {40, 40, 20, 20};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));
            Phrase phrase = new Phrase("");

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(2);
            try {
              java.text.DateFormat dateFormat =
                  java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

              java.util.Date endDate1 =
                  dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());

              System.out.println("" + endDate1);
              //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
              // pFontHeader);

              //  table.addCell(phrase);

              phrase =
                  new Phrase(
                      "Tax Computation : ".toUpperCase() + dateFormat.format(endDate1),
                      pFontHeader);

              table.addCell(phrase);
            } catch (java.text.ParseException psExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), psExec.getMessage());
            }

            table.getDefaultCell().setColspan(2);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
            phrase = new Phrase("Printed on : " + date, pFontHeader1);

            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              //       java.lang.Object[] listofAct = this.getListofActivities();

              java.lang.Object[] listofAct1 = this.getListofActivities1();

              //    java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              //                            System.out.println(listofAct.length);
              java.sql.Statement st4 = connectDB.createStatement();
              java.sql.PreparedStatement pstmt31w =
                  connectDB.prepareStatement(
                      "delete from ac_corporation_tax WHERE approved = false");
              pstmt31w.executeUpdate();

              java.sql.Statement st13 = connectDB.createStatement();
              java.sql.ResultSet rset13 =
                  st13.executeQuery(" select sum(amount) from pl_account_view");

              // rsetTotals1 = st3.executeQuery("SELECT SUM(debit),SUM(credit) from");
              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              table.getDefaultCell().setColspan(4);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.addCell("  ");

              table.getDefaultCell().setColspan(3);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              // phrase = new Phrase(rset3.getObject(1).toString().toUpperCase(), pFontHeader);
              phrase = new Phrase("NET INCOME", pFontHeader1);

              table.addCell(phrase);

              //   }

              while (rset13.next()) {

                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset13.getString(1)),
                        pFontHeader1);

                table.addCell(phrase);
                pl = rset13.getDouble(1);
                java.sql.PreparedStatement pstmtC =
                    connectDB.prepareStatement(
                        "insert into ac_corporation_tax values(?, ?, ?, ?, ?,?)");

                pstmtC.setObject(1, "" + endDate + "");
                pstmtC.setObject(2, "NET INCOME");
                pstmtC.setObject(3, "Income");
                if (pl < 0) {
                  pstmtC.setDouble(5, pl * -1);
                } else {
                  pstmtC.setDouble(5, pl);
                }
                pstmtC.setDouble(4, 0.00);
                pstmtC.setDouble(6, 0.00);

                pstmtC.executeUpdate();
              }

              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
              table.getDefaultCell().setColspan(4);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.addCell("  ");

              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
              table.getDefaultCell().setColspan(4);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Add/Less: Disallowable Items ".toUpperCase(), pFontHeader1);
              table.addCell(phrase);
              // table.addCell("Add/Less: Disallowable Items ".toUpperCase(), pFontHeader1);
              for (int i = 0; i < listofAct1.length; i++) {

                java.sql.Statement st6 = connectDB.createStatement();

                java.sql.Statement st7 = connectDB.createStatement();
                // java.sql.Statement st8 = connectDB.createStatement();

                java.sql.ResultSet rset7 =
                    st7.executeQuery(
                        "select description from ac_corporate_disallowables where gl_code = '"
                            + listofAct1[i].toString()
                            + "'");

                java.sql.Statement st8 = connectDB.createStatement();

                java.sql.ResultSet rset8 =
                    st8.executeQuery(
                        "select SUM(debit-credit) from ac_ledger where activity_code = '"
                            + listofAct1[i].toString()
                            + "' and date between '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "'");
                //  java.sql.ResultSet rset8 = st8.executeQuery("select SUM(debit-credit) from
                // ac_ledger where activity_code = '"+listofAct1[i].toString()+"' and date between
                // '"+beginDate+"' AND '"+endDate+"'");

                // rsetTotals1 = st3.executeQuery("SELECT SUM(debit),SUM(credit) from");
                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                table.addCell("  ");

                while (rset7.next()) {
                  while (rset8.next()) {
                    table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                    table.getDefaultCell().setColspan(1);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(rset7.getObject(1).toString().toUpperCase(), pFontHeader);

                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(rset8.getString(1)),
                            pFontHeader1);

                    table.addCell(phrase);

                    equity = equity + rset8.getDouble(1);

                    java.sql.PreparedStatement pstmt111 =
                        connectDB.prepareStatement(
                            "insert into ac_corporation_tax values(?, ?, ?, ?, ?,?)");

                    pstmt111.setObject(1, "" + endDate + "");
                    pstmt111.setObject(2, rset7.getObject(1).toString());
                    pstmt111.setObject(3, "Disallowable");
                    pstmt111.setDouble(4, rset8.getDouble(1));
                    pstmt111.setDouble(5, 0.00);
                    pstmt111.setDouble(6, 0.00);

                    pstmt111.executeUpdate();
                  }
                }
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(equity)),
                        pFontHeader);

                table.addCell(phrase);
              }

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.getDefaultCell().setColspan(4);
              // table.addCell("Add/Less: Allowable Items ");
              phrase = new Phrase("Add/Less: Allowable Items ".toUpperCase(), pFontHeader1);

              table.addCell(phrase);
              // for (int i = 0; i < listofAct1.length; i++) {

              java.sql.Statement st6 = connectDB.createStatement();

              java.sql.Statement st7 = connectDB.createStatement();

              java.sql.Statement st83 = connectDB.createStatement();

              java.sql.ResultSet rset83 =
                  st83.executeQuery("select sum(investment_allow) from ac_asset_allocation");

              // rsetTotals1 = st3.executeQuery("SELECT SUM(debit),SUM(credit) from");
              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              //   table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              while (rset83.next()) {
                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("  ".toUpperCase(), pFontHeader);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("Investment Allowance".toUpperCase(), pFontHeader);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset83.getString(1)),
                        pFontHeader1);

                table.addCell(phrase);

                inv = inv + rset83.getDouble(1);

                phrase = new Phrase("    ".toUpperCase(), pFontHeader);

                table.addCell(phrase);
                java.sql.PreparedStatement pstmt1A =
                    connectDB.prepareStatement(
                        "insert into ac_corporation_tax values(?, ?, ?, ?, ?,?)");

                pstmt1A.setObject(1, "" + endDate + "");
                pstmt1A.setObject(2, "Investment Allowance");
                pstmt1A.setObject(3, "Allowable");
                pstmt1A.setDouble(5, inv);
                pstmt1A.setDouble(4, 0.00);
                pstmt1A.setDouble(6, 0.00);

                pstmt1A.executeUpdate();
              }

              inv = inv;
              java.lang.Object[] listofAct2 = this.getListofActivities2();
              for (int y = 0; y < listofAct2.length; y++) {

                java.sql.Statement st81 = connectDB.createStatement();

                java.sql.ResultSet rset81 =
                    st81.executeQuery(
                        "select sum(wear_tear_allow*depreciation_rate/100) from ac_asset_allocation where gl_code = '"
                            + listofAct2[y].toString()
                            + "'");
                while (rset81.next()) {

                  table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
                  table.getDefaultCell().setColspan(1);

                  table.getDefaultCell().setColspan(1);
                  wta = wta = +rset81.getDouble(1);
                  // table.addCell(phrase);
                }
                Total = Total + wta;
              }
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase(" ".toUpperCase(), pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Wear & Tear Allowance".toUpperCase(), pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(Total)),
                      pFontHeader);
              table.addCell(phrase);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(inv + Total)),
                      pFontHeader);

              table.addCell(phrase);

              java.sql.PreparedStatement pstmtB1 =
                  connectDB.prepareStatement(
                      "insert into ac_corporation_tax values(?, ?, ?, ?, ?,?)");

              pstmtB1.setObject(1, "" + endDate + "");
              pstmtB1.setObject(2, "Wear & Tear Allowance");
              pstmtB1.setObject(3, "Allowable");
              pstmtB1.setDouble(5, Total);
              pstmtB1.setDouble(4, 0.00);
              pstmtB1.setDouble(6, 0.00);

              pstmtB1.executeUpdate();

              table.getDefaultCell().setColspan(3);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("ADJUSTED TAXABLE INCOME".toUpperCase(), pFontHeader1);

              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              if (pl < 0) {
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(
                                java.lang.String.valueOf((inv + Total + pl) - (-equity))),
                        pFontHeader);

                table.addCell(phrase);
                taxableIncome = (inv + Total + pl) - (-equity);
              } else {
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf((inv + Total + pl) - equity)),
                        pFontHeader);

                table.addCell(phrase);
                taxableIncome = (inv + Total + pl) - (equity);
              }

              java.sql.Statement st8111 = connectDB.createStatement();

              java.sql.ResultSet rset8111 =
                  st8111.executeQuery(
                      "select count(debit) from ac_corporation_tax where category Ilike 'Tax Loss BFWD'");
              while (rset8111.next()) {
                taxbf = rset8111.getInt(1);
              }

              if (taxbf > 0) {
                java.sql.Statement st811 = connectDB.createStatement();

                java.sql.ResultSet rset811 =
                    st811.executeQuery(
                        "select sum(debit-tax_divided) as debit from ac_corporation_tax WHERE category Ilike 'Tax loss BFWD'");
                while (rset811.next()) {
                  table.getDefaultCell().setColspan(3);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("TAX LOSSES BFWD".toUpperCase(), pFontHeader1);

                  table.addCell(phrase);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  table.getDefaultCell().setColspan(1);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rset811.getString(1)),
                          pFontHeader1);

                  table.addCell(phrase);
                  loss = rset811.getDouble(1);
                }
              } else {
                table.getDefaultCell().setColspan(3);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("TAX LOSSES BFWD".toUpperCase(), pFontHeader1);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(0.00)),
                        pFontHeader);

                table.addCell(phrase);

                loss = 0.00;
              }

              table.getDefaultCell().setColspan(3);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("TAXABLE INCOME".toUpperCase(), pFontHeader1);

              table.addCell(phrase);

              taxable = taxableIncome - loss;

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(taxable)),
                      pFontHeader);

              table.addCell(phrase);

              java.sql.Statement st8112 = connectDB.createStatement();

              java.sql.ResultSet rset8112 =
                  st8112.executeQuery(
                      " select ps.rate from pb_statutory ps, pb_activity pa where ps.gl_code = pa.code and pa.activity_category ilike 'CTX'");
              while (rset8112.next()) {
                table.getDefaultCell().setColspan(3);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("TAX DUE".toUpperCase(), pFontHeader1);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                table.getDefaultCell().setColspan(1);
                //   phrase = new Phrase(new
                // com.afrisoftech.sys.Format2Currency().Format2Currency(rset8112.getString(1)),
                // pFontHeader1);
                taxRate = rset8112.getDouble(1);
              }

              taxDue = taxable * taxRate / 100;

              if (taxDue > 0) {
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(taxDue)),
                        pFontHeader);

                table.addCell(phrase);
              } else {
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(0.00)),
                        pFontHeader);

                table.addCell(phrase);
              }
              java.sql.PreparedStatement pstmt1 =
                  connectDB.prepareStatement(
                      "insert into ac_corporation_tax values(?, ?, ?, ?, ?,?)");

              pstmt1.setObject(1, "" + endDate + "");
              if (taxDue < 0) {
                pstmt1.setObject(2, "Tax Loss BFWD");
                pstmt1.setObject(3, "Tax Loss BFWD");
                pstmt1.setDouble(4, taxable * -1);
                pstmt1.setDouble(6, 0.00);
              } else {
                pstmt1.setObject(2, "Tax For The Year");
                pstmt1.setObject(3, "Tax Due");
                pstmt1.setDouble(4, 0.00);
                pstmt1.setDouble(6, taxDue);
              }

              pstmt1.setDouble(5, 0.00);
              pstmt1.executeUpdate();

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) compName = rset2.getObject(1).toString();

            while (rset4.next()) date = rset4.getObject(1).toString();

            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName + "", pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Journal List - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

            int headerwidths[] = {10, 10, 8, 25, 15, 15};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(6);

            Phrase phrase = new Phrase("", pFontHeader);
            double osBalance = 0;
            double osBalance1 = 0;
            //  try {
            //      java.text.DateFormat dateFormat =
            // java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM);//MEDIUM);
            //

            //                            java.util.Date endDate1 =
            // dateFormat.parse(endDate.toLocaleString());//dateInstance.toLocaleString());
            //                            java.util.Date endDate11 =
            // dateFormat.parse(beginDate.toLocaleString());//dateInstance.toLocaleString());

            //                            System.out.println(""+endDate1);
            //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
            // pFontHeader);

            //  table.addCell(phrase);
            table.getDefaultCell().setColspan(4);

            phrase = new Phrase("Journal  No : " + Jno, pFontHeader);

            table.addCell(phrase);
            table.getDefaultCell().setColspan(2);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Printed On  : " + date, pFontHeader);

            table.addCell(phrase);
            // } catch(java.text.ParseException psExec) {

            //     javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
            // psExec.getMessage());
            //
            //  }
            // Phrase phrase = new Phrase("Patients List As At:" +endDate, pFontHeader);

            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);

            phrase = new Phrase("Date", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Activity Code", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("journal No.", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("Description", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("Debit KShs", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("Credit KShs", pFontHeader);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              java.sql.Statement st = connectDB.createStatement();

              java.sql.Statement st2 = connectDB.createStatement();

              java.sql.ResultSet rset =
                  st.executeQuery(
                      "select input_date,activity_code ,journal_no,description,debit,credit from ac_journal WHERE journal_no BETWEEN '"
                          + Jno
                          + "' AND '"
                          + Jno1
                          + "' ORDER BY journal_no"); // tn,debit_note db WHERE tn.policy_no != ''
                                                      // and tn.policy_no = db.policy_no GROUP BY
                                                      // tn.policy_no,db.policy_class");

              while (rset.next()) {

                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getObject(2).toString(), pFontHeader1);

                table.addCell(phrase);
                phrase = new Phrase(rset.getObject(3).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset.getString(4).toString(), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(5)),
                        pFontHeader1);
                osBalance = osBalance + rset.getDouble(5);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset.getString(6)),
                        pFontHeader1);
                osBalance1 = osBalance1 + rset.getDouble(6);
                table.addCell(phrase);
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              table.getDefaultCell().setColspan(4);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance)),
                      pFontHeader1);

              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance1)),
                      pFontHeader1);

              table.addCell(phrase);

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("kghostview " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  @Transactional
  public void generateSimpleMaterialBalance(
      final ViewDefinitionState viewDefinitionState,
      final ComponentState state,
      final String[] args) {
    if (state instanceof FormComponent) {
      ComponentState generated = viewDefinitionState.getComponentByReference(L_GENERATED);
      ComponentState date = viewDefinitionState.getComponentByReference(L_DATE);
      ComponentState worker = viewDefinitionState.getComponentByReference(L_WORKER);

      Entity simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      if (simpleMaterialBalance == null) {
        state.addMessage("qcadooView.message.entityNotFound", MessageType.FAILURE);
        return;
      } else if (StringUtils.hasText(simpleMaterialBalance.getStringField(L_FILE_NAME))) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalanceDetails.window.simpleMaterialBalance.documentsWasGenerated",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_ORDERS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedOrders",
            MessageType.FAILURE);
        return;
      } else if (simpleMaterialBalance
          .getHasManyField(L_SIMPLE_MATERIAL_BALANCE_LOCATIONS_COMPONENTS)
          .isEmpty()) {
        state.addMessage(
            "simpleMaterialBalance.simpleMaterialBalance.window.simpleMaterialBalance.missingAssosiatedLocations",
            MessageType.FAILURE);
        return;
      }

      if ("0".equals(generated.getFieldValue())) {
        worker.setFieldValue(securityService.getCurrentUserName());
        generated.setFieldValue("1");
        date.setFieldValue(
            new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, LocaleContextHolder.getLocale())
                .format(new Date()));
      }

      state.performEvent(viewDefinitionState, "save", new String[0]);

      if (state.getFieldValue() == null || !((FormComponent) state).isValid()) {
        worker.setFieldValue(null);
        generated.setFieldValue("0");
        date.setFieldValue(null);
        return;
      }

      simpleMaterialBalance =
          dataDefinitionService
              .get(
                  SimpleMaterialBalanceConstants.PLUGIN_IDENTIFIER,
                  SimpleMaterialBalanceConstants.MODEL_SIMPLE_MATERIAL_BALANCE)
              .get((Long) state.getFieldValue());

      try {
        generateSimpleMaterialBalanceDocuments(state, simpleMaterialBalance);
        state.performEvent(viewDefinitionState, "reset", new String[0]);
      } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
      } catch (DocumentException e) {
        throw new IllegalStateException(e.getMessage(), e);
      }
    }
  }
  public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      // com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A4.rotate());
      double osBalance1 = 0.00;
      double osBalance = 0.00;
      double current = 0.00;
      double osBalancebf = 0.00;
      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          String Messg = null;

          docPdf.open();

          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(7);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {15, 15, 30, 15, 15, 15, 15};

            table1.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            //  table1.setHeaderRows(4);
            //  }
            table1.setWidthPercentage((100));

            table1.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table1.getDefaultCell().setColspan(7);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table1.getDefaultCell().setColspan(1);
            table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st2x = connectDB.createStatement();

              java.sql.ResultSet rset2x =
                  st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
              while (rset2x.next()) {
                ks = rset2x.getObject(1).toString();
              }
              java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header");
              while (rset3.next()) {
                table1.getDefaultCell().setColspan(7);

                table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11);
                table1.addCell(phrase);
              }

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }
            docPdf.add(table1);
          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

          //  } catch(java.io.FileNotFoundException fnfExec) {

          //  javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
          // fnfExec.getMessage());

          /// }
          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {12, 10, 28, 11, 14, 12, 14, 14, 15};

            table.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            table.setHeaderRows(8);
            //  }
            table.setWidthPercentage((100));

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(9);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table.getDefaultCell().setColspan(1);
            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              double Debit = 0.00;
              double Credit = 0.00;
              java.sql.Statement st22 = connectDB.createStatement();
              java.sql.Statement st11 = connectDB.createStatement();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st1 = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st4 = connectDB.createStatement();
              java.sql.Statement st41 = connectDB.createStatement();
              java.sql.Statement st5 = connectDB.createStatement();
              java.sql.Statement st22D = connectDB.createStatement();
              java.sql.ResultSet rset3 =
                  st3.executeQuery(
                      "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile");
              java.sql.ResultSet rset4 =
                  st4.executeQuery(
                      "select scheme_name,account_no,tel_main,address from ac_schemes where account_no = '"
                          + memNo
                          + "'");
              java.sql.ResultSet rset41 =
                  st41.executeQuery(
                      "select payer_name from ac_schemes where account_no = '" + memNo + "'");
              //      java.sql.ResultSet rset1 = st1.executeQuery("select date,admission_no||'
              // '||cheque_no, upper(item),invoice_no ||'
              // '||receipt_no,debit,credit,credit_bal,balance from ac_debtors where account_no = '"
              // + memNo + "' AND date::date BETWEEN '" + beginDate + "' AND '" + endDate + "' group
              // by 1, 2, 3order by date,invoice_no");// UNION select
              // pd.date::date,initcap(pd.scheme_staff_no), (sh.first_name||' '||sh.second_name||'
              // '||sh.last_name) as name,pd.reference,sum(pd.credit),pd.patient_no from
              // hp_patient_card pd,hp_inpatient_register sh where pd.patient_no = sh.patient_no and
              // pd.isurer = '"+memNo+"' AND pd.date::date BETWEEN '"+beginDate+"' AND '"+endDate+"'
              // and pd.credit > 0 group by pd.date::date,pd.scheme_staff_no,
              // name,pd.reference,pd.invoice_no,pd.patient_no order by pd.invoice_no");
              java.sql.ResultSet rsetTotals2 =
                  st22.executeQuery(
                      "select sum(debit - credit) from ac_debtors where account_no = '"
                          + memNo
                          + "' AND date::date < '"
                          + beginDate
                          + "'");
              java.sql.ResultSet rsetTotals =
                  st2.executeQuery(
                      "select sum(debit),sum(credit) from ac_debtors where account_no = '"
                          + memNo
                          + "' AND date::date BETWEEN '"
                          + beginDate
                          + "' AND '"
                          + endDate
                          + "'");

              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP | Rectangle.BOTTOM);

              table.getDefaultCell().setColspan(9);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase("Statement of Account", pFontHeader11);
              table.addCell(phrase);

              while (rset4.next()) {
                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
                table.getDefaultCell().setColspan(9);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);

                while (rset41.next()) {
                  table.getDefaultCell().setColspan(9);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset41.getString(1), pFontHeader1);
                  table.addCell(phrase);
                }
                table.getDefaultCell().setColspan(9);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase =
                    new Phrase(
                        "Account No : " + rset4.getObject(2).toString().toUpperCase(),
                        pFontHeader1);
                table.addCell(phrase);

                phrase =
                    new Phrase(
                        dbObject.getDBObject("Tel : " + rset4.getObject(3), "-"), pFontHeader1);
                table.addCell(phrase);
                phrase = new Phrase(dbObject.getDBObject(rset4.getObject(4), "-"), pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setColspan(6);
              }
              try {
                java.text.DateFormat dateFormat =
                    java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

                java.util.Date endDate1 =
                    dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());
                java.util.Date endDate11 =
                    dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

                System.out.println("" + endDate1);
                //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
                // pFontHeader);

                //  table.addCell(phrase);

                phrase =
                    new Phrase(
                        "Period : "
                            + dateFormat.format(endDate11)
                            + " - "
                            + dateFormat.format(endDate1),
                        pFontHeader1);

                table.addCell(phrase);
              } catch (java.text.ParseException psExec) {

                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), psExec.getMessage());
              }
              // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1);
              // table.addCell(phrase);

              table.getDefaultCell().setColspan(3);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Date " + datenowSql, pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP);
              table.getDefaultCell().setColspan(1);
              // phrase = new Phrase("Date", pFontHeader1);
              // table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Staff No.", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase = new Phrase(" Staff Name", pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader1);
              table.addCell(phrase);
              phrase = new Phrase("Debit Bal. ", pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Running Amt. " + ks, pFontHeader1);
              table.addCell(phrase);

              while (rsetTotals2.next()) {
                table.getDefaultCell().setColspan(5);

                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("BAL/BF", pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                table.getDefaultCell().setColspan(4);
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rsetTotals2.getString(1)),
                        pFontHeader1);
                osBalancebf = osBalancebf + rsetTotals2.getDouble(1);
                table.addCell(phrase);
              }
              for (int i = 0; i < listofStaffNos.length; i++) {
                java.sql.ResultSet rset1 =
                    st1.executeQuery(
                        "select admission_no, upper(item), sum(debit - credit) from ac_debtors where account_no = '"
                            + memNo
                            + "' and admission_no = '"
                            + listofStaffNos[i]
                            + "' AND date::date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' GROUP BY 1, 2");
                while (rset1.next()) {
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(6);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"),
                  // pFontHeader);

                  // table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  // phrase = new Phrase(dbObject.getDBObject(rset1.getObject(4), "-"),
                  // pFontHeader);

                  // table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(5)),
                  // pFontHeader);
                  // Debit = Debit + rset1.getDouble(5);
                  // table.addCell(phrase);
                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)),
                  // pFontHeader);
                  // Credit = Credit + rset1.getDouble(6);
                  // table.addCell(phrase);

                  // phrase = new Phrase(new
                  // com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(7)),
                  // pFontHeader);
                  // osBalance1 = osBalance1 + rset1.getDouble(6);
                  // table.addCell(phrase);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rset1.getString(3)),
                          pFontHeader);
                  osBalancebf = osBalancebf + rset1.getDouble(3);
                  // osBalancebf = osBalance1;
                  table.addCell(phrase);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)),
                          pFontHeader);

                  table.addCell(phrase);
                }
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              //  while (rsetTotals.next()) {

              table.getDefaultCell().setColspan(4);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              phrase = new Phrase("", pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalancebf - osBalance1)),
                      pFontHeader);

              table.addCell(phrase);

              // phrase = new Phrase(" ");

              //     }
              try {

                java.sql.Statement st31 = connectDB.createStatement();
                // java.sql.Statement st4 = connectDB.createStatement();
                java.sql.ResultSet rset2 = st31.executeQuery("select name from pb_notice");

                // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from
                // pb_hospitalprofile");
                //   java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                while (rset2.next()) {
                  Messg = rset2.getString(1);
                }
                com.lowagie.text.HeaderFooter footer =
                    new com.lowagie.text.HeaderFooter(
                        new Phrase("" + Messg + ""),
                        false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                // Font.BOLDITALIC,java.awt.Color.blue)));

                //  com.lowagie.text.HeaderFooter headerFoter = new
                // com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);//
                // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                // Font.BOLDITALIC,java.awt.Color.blue)));
                //  headerFoter.ALIGN_CENTER;
                //  headerFoter.setRight(5);
                docPdf.setFooter(footer);

              } catch (java.sql.SQLException SqlExec) {

                SqlExec.printStackTrace();
                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), SqlExec.getMessage());
              }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              SqlExec.printStackTrace();
              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

            // }  // }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("xpdf " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  public void generatePdf() {
    java.sql.ResultSet rsetTotals1 = null;

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          try {

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) compName = rset2.getObject(1).toString();

            while (rset4.next()) date = rset4.getObject(1).toString();

            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName, pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Un Finalised Invoices List - Page: ", pFontHeader1),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          double balance = 0.00;

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(4);

            int headerwidths[] = {15, 30, 25, 15};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(2);

            Phrase phrase =
                new Phrase(
                    "In Patient Unfinalised Inv : ",
                    com.lowagie.text.FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10));

            table.addCell(phrase);

            table.getDefaultCell().setColspan(2);

            phrase =
                new Phrase(
                    "Printed On : " + date,
                    com.lowagie.text.FontFactory.getFont(FontFactory.HELVETICA_BOLD, 10));

            table.addCell(phrase);
            table.getDefaultCell().setColspan(1);

            // phrase = new Phrase("Name", pFontHeader);

            // table.addCell(phrase);

            phrase = new Phrase("Date", pFontHeader);

            table.addCell(phrase);

            phrase = new Phrase("No.", pFontHeader);

            table.addCell(phrase);

            phrase = new Phrase("Name", pFontHeader);

            table.addCell(phrase);

            phrase = new Phrase("Amount", pFontHeader);

            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {

              // java.lang.Object[] listofAct = this.getListofActivities();
              java.lang.Object[] listofAct1 = this.getListofActivities1();

              java.sql.Statement st21 = connectDB.createStatement();

              //  java.sql.ResultSet rsetTotals = st21.executeQuery("SELECT sum(amount) from
              // op_unfinalised_inv  where trans_date BETWEEN '"+beginDate+"' AND '"+endDate+"'");

              //    java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              //  System.out.println(listofAct.length);
              java.sql.Statement st2 = connectDB.createStatement();
              java.sql.Statement st22 = connectDB.createStatement();

              for (int k = 0; k < listofAct1.length; k++) {
                java.sql.ResultSet rset1 =
                    st2.executeQuery(
                        "SELECT patient_no,sum(debit-credit) from hp_patient_card WHERE patient_no ILIKE '"
                            + listofAct1[k].toString()
                            + "%' and invoice_no NOT iLike 'O%' OR invoice_no NOT iLike 'I%' AND date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' group by patient_no");
                java.sql.ResultSet rset2 =
                    st22.executeQuery(
                        "SELECT patient_name from hp_admission WHERE patient_no ILIKE '"
                            + listofAct1[k].toString()
                            + "%'");

                /*    table.getDefaultCell().setColspan(1);
                   table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                   phrase = new Phrase(" ",pFontHeader);
                   table.addCell(phrase);
                   table.getDefaultCell().setColspan(3);
                   table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  // phrase = new Phrase(listofAct1[k].toString(),pFontHeader);
                 //  table.addCell(phrase);

                   phrase = new Phrase("",pFontHeader);
                   table.addCell(phrase);
                */
                while (rset1.next()) {
                  while (rset2.next()) {
                    table.getDefaultCell().setColspan(1);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(" ", pFontNum);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(rset1.getObject(1).toString(), pFontNum);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(rset2.getString(1), pFontNum);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(rset1.getString(2)),
                            pFontHeader1);
                    table.addCell(phrase);
                    balance = balance + rset1.getDouble(2);
                  }
                }
              }
              // while (rsetTotals.next()) {

              table.getDefaultCell().setColspan(2);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(2);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              //  phrase = new Phrase(new
              // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetTotals.getString(1)),
              // pFontHeader);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(balance)),
                      pFontHeader);

              table.addCell(phrase);
              //  }

              // }

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("kghostview " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      //  com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      com.lowagie.text.Document docPdf = new com.lowagie.text.Document(PageSize.A3.rotate());

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String distName = null;
          String regiName = null;
          String date = null;
          try {

            // java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();

            java.sql.ResultSet rset2 =
                st3.executeQuery(
                    "SELECT hospital_name,rep_currency,district_branch,region from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
              ks = rset2.getString(2);
              distName = rset2.getObject(3).toString();
              regiName = rset2.getObject(4).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase(""),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
                            // Font.BOLDITALIC,java.awt.Color.blue)));

            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);

            //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
            // Phrase(""+compName+""),false);//
            // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            // headerFoter.setRight(5);
            // docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Page: "),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
                         // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(17);

            int headerwidths[] = {7, 10, 20, 7, 12, 7, 7, 12, 12, 10, 7, 7, 7, 7, 20, 12, 10};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(17);

            Phrase phrase = new Phrase("", pFontHeader);

            try {
              java.text.DateFormat dateFormat =
                  java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

              java.util.Date endDate1 =
                  dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());

              java.util.Date endDate11 =
                  dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

              com.afrisoftech.lib.DateFormatter dateFormatter =
                  new com.afrisoftech.lib.DateFormatter(
                      dateFormat.parse(endDate.toLocaleString()), "MMMM");

              java.lang.String monthString = dateFormatter.getDateString();

              com.afrisoftech.lib.DateFormatter dateFormatters =
                  new com.afrisoftech.lib.DateFormatter(
                      dateFormat.parse(endDate.toLocaleString()), "yyyy");

              java.lang.String yearString = dateFormatters.getDateString();
              System.out.println("" + endDate1);

              table.getDefaultCell().setColspan(17);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

              phrase = new Phrase("MONTHLY RETURNS ON DELIVERIES", pFontHeader2);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(5);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

              phrase = new Phrase("HOSPITAL : " + compName, pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("DISTRICT : " + distName, pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(5);
              phrase = new Phrase("REGION : " + regiName, pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("MONTH : " + monthString, pFontHeader);

              table.addCell(phrase);

              phrase = new Phrase("YEAR : " + yearString, pFontHeader);

              table.addCell(phrase);

            } catch (java.text.ParseException psExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), psExec.getMessage());
            }

            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);

            table.getDefaultCell().setColspan(10);
            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);

            table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

            phrase = new Phrase("", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setColspan(4);
            phrase = new Phrase("++ Outcome of Delivery", pFontHeader1);
            table.addCell(phrase);
            table.getDefaultCell().setColspan(3);
            phrase = new Phrase("", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setColspan(10);
            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);

            table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

            phrase = new Phrase("", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setColspan(2);
            phrase = new Phrase("Single Birth", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Multiple Birth", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setColspan(3);
            phrase = new Phrase("", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setColspan(1);

            table
                .getDefaultCell()
                .setBorder(Rectangle.BOTTOM | Rectangle.TOP | Rectangle.RIGHT | Rectangle.LEFT);
            phrase = new Phrase("No.", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Inpatient Number", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Address * \n (Town/Residence)", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Age", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Occupation", pFontHeader1);
            table.addCell(phrase);
            table.getDefaultCell().setRunDirection(0);
            phrase = new Phrase("Parity", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Duration of Pregnancy (Weeks)", pFontHeader1);
            table.addCell(phrase);
            phrase = new Phrase("Date of Admission", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Date of Discharge", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("+ Type of Delivery", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("M", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("F", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("M", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("F", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Complications of Pregnancy", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("**Outcome of Admission", pFontHeader1);
            table.addCell(phrase);

            phrase = new Phrase("Cost of Treatment", pFontHeader1);
            table.addCell(phrase);

            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            //
            double osBalance = 0.00;
            try {

              java.lang.Object[] listofAct = this.getListofActivities();

              //    java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              System.out.println(listofAct.length);

              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st11 = connectDB.createStatement();
              java.sql.Statement st22 = connectDB.createStatement();
              java.sql.Statement st33 = connectDB.createStatement();

              java.sql.Statement st31 = connectDB.createStatement();
              for (int i = 0; i < listofAct.length; i++) {
                String outComeSingle = "-";
                String outComeTwins = "-";
                String infantState = "-";
                String babyGender = "-";
                String infantState1 = "-";
                String babyGender1 = "-";
                String parity = "-";

                int ages = 0;
                java.sql.ResultSet rset =
                    st11.executeQuery(
                        "SELECT patient_no,address||' '||residence,ROUND(pat_age),occupation,'','',date_admitted,discharge_date::date,'','','','','',diagnosis1,transaction_type,balance FROM hp_admission WHERE patient_no = '"
                            + listofAct[i]
                            + "' AND discharge_date::date BETWEEN '"
                            + beginDate
                            + "'::date AND '"
                            + endDate
                            + "'::date AND discharge = true AND diagnosed = true");
                java.sql.ResultSet rset1 =
                    st22.executeQuery(
                        "SELECT DISTINCT duration_of_preg,delivery_method,birth_complications FROM rh.post_natal_services WHERE mother_serial_no = '"
                            + listofAct[i]
                            + "' AND service_date::date BETWEEN '"
                            + beginDate
                            + "'::date AND '"
                            + endDate
                            + "'::date");
                java.sql.ResultSet rset2 =
                    st.executeQuery(
                        "SELECT DISTINCT state_of_infant_at_birth,baby_gender FROM rh.post_natal_services WHERE mother_serial_no = '"
                            + listofAct[i]
                            + "' AND service_date::date BETWEEN '"
                            + beginDate
                            + "'::date AND '"
                            + endDate
                            + "'::date AND type_of_birth ilike 'Single'");
                java.sql.ResultSet rset3 =
                    st33.executeQuery(
                        "SELECT DISTINCT state_of_infant_at_birth,baby_gender FROM rh.post_natal_services WHERE mother_serial_no = '"
                            + listofAct[i]
                            + "' AND service_date::date BETWEEN '"
                            + beginDate
                            + "'::date AND '"
                            + endDate
                            + "'::date AND type_of_birth ilike 'Twins'");
                java.sql.ResultSet rset31 =
                    st31.executeQuery(
                        "SELECT DISTINCT parity FROM rh.post_natal_services WHERE mother_serial_no = '"
                            + listofAct[i]
                            + "' AND service_date::date BETWEEN '"
                            + beginDate
                            + "'::date AND '"
                            + endDate
                            + "'::date");
                while (rset31.next()) {
                  parity = dbObject.getDBObject(rset31.getObject(1), "-");
                }
                while (rset2.next()) {
                  infantState = rset2.getString(1);
                  babyGender = rset2.getString(2);
                  if (infantState.equalsIgnoreCase("Live Birth")) {
                    outComeSingle = "A";
                  } else {
                    outComeSingle = "D";
                  }
                }

                while (rset3.next()) {
                  infantState1 = rset3.getString(1);
                  babyGender1 = rset3.getString(2);
                  if (infantState1.equalsIgnoreCase("Both Alive")) {
                    outComeTwins = "AA";
                  } else {
                    if (infantState1.equalsIgnoreCase("Both Dead")) {
                      outComeTwins = "DD";
                    } else {
                      if (infantState1.equalsIgnoreCase("One Dead")) {
                        outComeTwins = "AD";
                      }
                    }
                  }
                }

                while (rset.next()) {
                  while (rset1.next()) {
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    table.getDefaultCell().setColspan(1);
                    numberSeq = numberSeq + 1;
                    phrase = new Phrase("" + numberSeq + "   ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(2), "-"), pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    ages = rset.getInt(3);
                    if (ages < 1) {
                      phrase = new Phrase("<1", pFontHeader1);

                      table.addCell(phrase);
                    } else {
                      //     phrase = new Phrase(dbObject.getDBObject(rset.getObject(3), "-"),
                      // pFontHeader1);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2IntCurrency()
                                  .Format2IntCurrency(java.lang.String.valueOf(ages)),
                              pFontHeader1);

                      table.addCell(phrase);
                    }

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(4), "-"), pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(parity, pFontHeader1);
                    table.addCell(phrase);

                    phrase =
                        new Phrase(dbObject.getDBObject(rset1.getObject(1), "-"), pFontHeader1);
                    table.addCell(phrase);

                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(7), "-"), pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(8), "-"), pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase =
                        new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader1);
                    table.addCell(phrase);
                    if (babyGender.startsWith("M")) {
                      phrase = new Phrase(outComeSingle, pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                    } else {
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);

                      table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                      phrase = new Phrase(outComeSingle, pFontHeader1);
                      table.addCell(phrase);
                    }
                    if (babyGender.startsWith("M")) {
                      phrase = new Phrase(outComeTwins, pFontHeader1);
                      table.addCell(phrase);

                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);
                    } else {
                      phrase = new Phrase("", pFontHeader1);
                      table.addCell(phrase);

                      phrase = new Phrase(outComeTwins, pFontHeader1);
                      table.addCell(phrase);
                    }
                    phrase =
                        new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"), pFontHeader1);
                    table.addCell(phrase);
                    phrase =
                        new Phrase(dbObject.getDBObject(rset.getObject(15), "-"), pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase =
                        new Phrase(dbObject.getDBObject(rset.getObject(16), "-"), pFontHeader1);
                    table.addCell(phrase);
                    /*  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(15), "-"), pFontHeader1);
                    table.addCell(phrase);
                     */
                  }
                }
              }

              table.getDefaultCell().setColspan(17);
              phrase = new Phrase("   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("*    Address             ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(12);
              phrase =
                  new Phrase(
                      "= This does not mean birth-place,unless the latter is the usual residence. It also excludes temporary residence of less than one month duration",
                      pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("+   Type of Delivery             ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(12);
              phrase =
                  new Phrase(
                      "= N-normal; N.E-Normal with Episiotomy; F.E.-Ferceps with Episiotomy; M-Surgical Manipulation; C.S.-Caesarian Section; An-Any Other",
                      pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("++    Outcome of Delivery   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(12);
              phrase =
                  new Phrase(
                      "= A-Alive; D-Foetal Death; AA-Both Alive; DD-Both Dead; AD-One Dead",
                      pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("**    Outcome of Admission   ", pFontHeader);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(12);
              phrase = new Phrase("= Discharge, Transferred, Died, Abscond", pFontHeader);
              table.addCell(phrase);

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

            // }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Esempio n. 26
0
  /**
   * Constructs a new RtfList for the specified List.
   *
   * @param doc The RtfDocument this RtfList belongs to
   * @param list The List this RtfList is based on
   */
  public RtfList(RtfDocument doc, List list) {
    super(doc);

    this.listNumber = document.getDocumentHeader().getListNumber(this);

    this.items = new ArrayList();
    if (list.getSymbolIndent() > 0 && list.getIndentationLeft() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent =
          (int) ((list.getIndentationLeft() + list.getSymbolIndent()) * RtfElement.TWIPS_FACTOR);
    } else if (list.getSymbolIndent() > 0) {
      this.firstIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR * -1);
      this.leftIndent = (int) (list.getSymbolIndent() * RtfElement.TWIPS_FACTOR);
    } else if (list.getIndentationLeft() > 0) {
      this.firstIndent = 0;
      this.leftIndent = (int) (list.getIndentationLeft() * RtfElement.TWIPS_FACTOR);
    } else {
      this.firstIndent = 0;
      this.leftIndent = 0;
    }
    this.rightIndent = (int) (list.getIndentationRight() * RtfElement.TWIPS_FACTOR);
    this.symbolIndent =
        (int) ((list.getSymbolIndent() + list.getIndentationLeft()) * RtfElement.TWIPS_FACTOR);

    if (list instanceof RomanList) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_ROMAN;
      } else {
        this.listType = LIST_TYPE_UPPER_ROMAN;
      }
    } else if (list.isNumbered()) {
      this.listType = LIST_TYPE_NUMBERED;
    } else if (list.isLettered()) {
      if (list.isLowercase()) {
        this.listType = LIST_TYPE_LOWER_LETTERS;
      } else {
        this.listType = LIST_TYPE_UPPER_LETTERS;
      }
    }

    for (int i = 0; i < list.getItems().size(); i++) {
      try {
        Element element = (Element) list.getItems().get(i);
        if (element.type() == Element.CHUNK) {
          element = new ListItem((Chunk) element);
        }
        if (element instanceof ListItem) {
          this.alignment = ((ListItem) element).getAlignment();
        }
        RtfBasicElement rtfElement = doc.getMapper().mapElement(element);
        if (rtfElement instanceof RtfList) {
          ((RtfList) rtfElement).setListNumber(listNumber);
          ((RtfList) rtfElement).setListLevel(listLevel + 1);
          ((RtfList) rtfElement).setParent(this);
        } else if (rtfElement instanceof RtfListItem) {
          ((RtfListItem) rtfElement).setParent(this);
          ((RtfListItem) rtfElement).inheritListSettings(listNumber, listLevel + 1);
        }
        items.add(rtfElement);
      } catch (DocumentException de) {
        de.printStackTrace();
      }
    }

    if (this.listLevel == 0) {
      correctIndentation();
    }

    fontNumber =
        new RtfFont(document, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, new Color(0, 0, 0)));
    if (list.getSymbol() != null
        && list.getSymbol().getFont() != null
        && !list.getSymbol().getContent().startsWith("-")
        && list.getSymbol().getContent().length() > 0) {
      // only set this to bullet symbol is not default
      this.fontBullet = new RtfFont(document, list.getSymbol().getFont());
      this.bulletCharacter = list.getSymbol().getContent().substring(0, 1);
    } else {
      this.fontBullet =
          new RtfFont(document, new Font(Font.SYMBOL, 10, Font.NORMAL, new Color(0, 0, 0)));
    }
  }
  public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();
      double osBalanceAmt = 0.00;
      double osBalanceQty = 0.00;
      double osBalanceQtybf = 0.00;
      double osBalanceAmtbf = 0.00;
      double ClosingQtyBalance = 0.00;
      double ClosingAmtBalance = 0.00;
      double osBalanceQty1 = 0.00;
      double osBalanceQty13 = 0.00;
      double osBalanceQty14 = 0.00;
      double osBalanceAmt1 = 0.00;
      double osBalanceAmt12 = 0.00;
      double current = 0.00;

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          String Messg = null;

          /*  try {


                  java.sql.Statement st3 = connectDB.createStatement();
                  java.sql.Statement st4 = connectDB.createStatement();
                    // java.sql.ResultSet rset2 = st3.executeQuery("select name from pb_notice");

                  java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
               //   java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                  while(rset2.next())
                      Messg = rset2.getObject(1).toString();



                //  while(rset4.next())
                  //    date = rset4.getObject(1).toString();

                 // com.lowagie.textHeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase(""+Messg+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));

                    headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+Messg+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                //  headerFoter.ALIGN_CENTER;
                   headerFoter.setRight(5);


              } catch(java.sql.SQLException SqlExec) {

                  javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

              }

          */
          /*
           try {


                java.sql.Statement st3 = connectDB.createStatement();
                java.sql.Statement st4 = connectDB.createStatement();
                   java.sql.ResultSet rset2 = st3.executeQuery("select name from pb_notice");

               // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
             //   java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                while(rset2.next())
                    Messg = rset2.getObject(1).toString();



              //  while(rset4.next())
                //    date = rset4.getObject(1).toString();

                com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase(""+Messg+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));

                //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
              //  headerFoter.ALIGN_CENTER;
               //  headerFoter.setRight(5);
                docPdf.setFooter(footer);




            } catch(java.sql.SQLException SqlExec) {

                javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

            }
          */
          docPdf.open();

          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table1 = new com.lowagie.text.pdf.PdfPTable(7);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {15, 15, 30, 15, 15, 15, 15};

            table1.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            //  table1.setHeaderRows(4);
            //  }
            table1.setWidthPercentage((100));

            table1.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table1.getDefaultCell().setColspan(7);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table1.getDefaultCell().setColspan(1);
            table1.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table1.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.ResultSet rset3 = st3.executeQuery("select header_name from pb_header");
              while (rset3.next()) table1.getDefaultCell().setColspan(7);

              table1.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader11);
              table1.addCell(phrase);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }
            docPdf.add(table1);
          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

          //  } catch(java.io.FileNotFoundException fnfExec) {

          //  javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(),
          // fnfExec.getMessage());

          /// }
          try {

            java.util.Calendar calendar = java.util.Calendar.getInstance();

            long dateNow = calendar.getTimeInMillis();

            java.sql.Date datenowSql = new java.sql.Date(dateNow);

            System.out.println(datenowSql.toString());

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(5);
            //  com.lowagie.text.Table table = new com.lowagie.text.Table(7);

            // table.endHeaders();

            int headerwidths[] = {10, 40, 15, 15, 20};

            table.setWidths(headerwidths);
            //  if (docPdf.getPageNumber() > 1) {
            table.setHeaderRows(3);
            //  }
            table.setWidthPercentage((100));

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(5);

            Phrase phrase = new Phrase();

            //  table.addCell(phrase);

            table.getDefaultCell().setColspan(1);
            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            try {
              java.sql.Statement st22 = connectDB.createStatement();
              java.sql.Statement st11 = connectDB.createStatement();
              java.sql.Statement st111 = connectDB.createStatement();
              java.sql.Statement st = connectDB.createStatement();
              java.sql.Statement st1 = connectDB.createStatement();
              java.sql.Statement st1q = connectDB.createStatement();
              java.sql.Statement st2 = connectDB.createStatement();
              java.sql.Statement st3 = connectDB.createStatement();
              java.sql.Statement st4 = connectDB.createStatement();
              java.sql.Statement st41 = connectDB.createStatement();
              java.sql.Statement st5 = connectDB.createStatement();
              java.sql.ResultSet rset3 =
                  st3.executeQuery(
                      "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile");
              java.sql.ResultSet rset1 =
                  st1.executeQuery(
                      "select '-' as sno, item,sum(qty)  ,sum(purchases),sum(sales),case when sum(sales) > 0 then sum(sales)*-1 else sum(purchases) end as balance  from drug_movt where date BETWEEN '"
                          + beginDate
                          + "' AND '"
                          + endDate
                          + "' and qty > 0 group by item order by item"); // UNION ALL SELECT
              // trans_date,store_name,user_name,issuing,total from st_sub_stores where (sub_store =
              // 'Pharmacy' OR sub_store = 'IP Pharmacy') and item ilike '"+memNo+"' AND trans_date
              // BETWEEN '"+beginDate+"' AND '"+endDate+"'");
              java.sql.ResultSet rset11 =
                  st11.executeQuery(
                      "select sum(purchases),sum(sales) from drug_movt"); // UNION ALL SELECT
              // trans_date,store_name,user_name,issuing,total from st_sub_stores where (sub_store =
              // 'Pharmacy' OR sub_store = 'IP Pharmacy') and item ilike '"+memNo+"' AND trans_date
              // BETWEEN '"+beginDate+"' AND '"+endDate+"'");
              // java.sql.ResultSet rset111 = st111.executeQuery("select sum(issuing),sum(amount)
              // from st_sub_stores where item ilike '"+memNo1+"' and sub_store ilike '"+memNo+"%'
              // AND date BETWEEN '"+beginDate+"' AND '"+endDate+"'");// UNION ALL SELECT
              // trans_date,store_name,user_name,issuing,total from st_sub_stores where (sub_store =
              // 'Pharmacy' OR sub_store = 'IP Pharmacy') and item ilike '"+memNo+"' AND trans_date
              // BETWEEN '"+beginDate+"' AND '"+endDate+"'");
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP | Rectangle.BOTTOM);

              table.getDefaultCell().setColspan(5);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase = new Phrase(" ", pFontHeader11);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(5);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              phrase =
                  new Phrase(
                      "Drug Movement(Supplies Vs Sales) for all stockables items", pFontHeader11);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);

              try {
                java.text.DateFormat dateFormat =
                    java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

                java.util.Date endDate1 =
                    dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());
                java.util.Date endDate11 =
                    dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

                System.out.println("" + endDate1);
                //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
                // pFontHeader);

                //  table.addCell(phrase);

                phrase =
                    new Phrase(
                        "Period : "
                            + dateFormat.format(endDate11)
                            + " - "
                            + dateFormat.format(endDate1),
                        pFontHeader1);

                table.addCell(phrase);
              } catch (java.text.ParseException psExec) {

                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), psExec.getMessage());
              }
              // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              // phrase = new Phrase("Period : '"+beginDate+"' - '"+endDate+"'", pFontHeader1);
              // table.addCell(phrase);

              table.getDefaultCell().setColspan(2);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Date " + datenowSql, pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
              table.getDefaultCell().setBorderWidth(Rectangle.TOP);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("SNo.", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Item", pFontHeader1);
              table.addCell(phrase);
              phrase = new Phrase("Qty", pFontHeader1);
              table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Purchases.", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);
              phrase = new Phrase("Sales", pFontHeader1);
              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);

              // table
              while (rset1.next()) {
                seq = seq + 1;
                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("" + seq + ".", pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(dbObject.getDBObject(rset1.getObject(2), "-"), pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase = new Phrase(dbObject.getDBObject(rset1.getObject(3), "-"), pFontHeader);
                osBalanceQty13 = osBalanceQty13 + rset1.getDouble(3);
                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(rset1.getString(4)),
                        pFontHeader);
                osBalanceQty1 = osBalanceQty1 + rset1.getDouble(4);
                table.addCell(phrase);
                phrase = new Phrase(dbObject.getDBObject(rset1.getObject(5), "0"), pFontHeader);
                osBalanceQty14 = osBalanceQty14 + rset1.getDouble(5);
                table.addCell(phrase);
                /*

                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset1.getString(6)),pFontHeader);
                osBalanceAmt1 = osBalanceAmt1 + rset1.getDouble(5);
                 osBalanceAmt12 = osBalanceAmt12 + rset1.getDouble(6);
                table.addCell(phrase);
                */
              }
              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              //  while (rsetTotals.next()) {

              table.getDefaultCell().setColspan(2);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("TOTAL", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalanceQty13)),
                      pFontHeader);

              table.addCell(phrase);

              // phrase = new Phrase(" ");

              // table.addCell(phrase);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalanceQty1)),
                      pFontHeader);

              // phrase = new Phrase(" ",pFontHeader);
              // phrase = new Phrase(" ",pFontHeader);

              table.addCell(phrase);

              // table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalanceQty14)),
                      pFontHeader);

              // phrase = new Phrase(" ",pFontHeader);
              // phrase = new Phrase(" ",pFontHeader);

              table.addCell(phrase);
              /*
                table.getDefaultCell().setColspan(3);

                 table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                 phrase = new Phrase("Totals", pFontHeader);

                 table.addCell(phrase);

                 table.getDefaultCell().setColspan(2);

                 table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              */
              while (rset11.next()) {
                /*
                // phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf((osBalanceQtybf + osBalanceQty) - osBalanceQty1)),pFontHeader);
                //  phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(closingBal+osBalanceQty)),pFontHeader);
                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset11.getString(1)),pFontHeader);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset11.getString(2)),pFontHeader);

                //  phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf((closingBal+osBalanceQty)*buyingPrice)),pFontHeader);

                table.addCell(phrase);
                */
              }
              /*
                                   try {


                  java.sql.Statement st31 = connectDB.createStatement();
                 // java.sql.Statement st4 = connectDB.createStatement();
                     java.sql.ResultSet rset2 = st31.executeQuery("select name from pb_notice");

                 // java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
               //   java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                  while(rset2.next())
                      Messg = rset2.getString(1);

                  com.lowagie.text.HeaderFooter footer = new com.lowagie.text.HeaderFooter(new Phrase(""+Messg+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));

                  //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new Phrase(""+compName+""),false);// FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14, Font.BOLDITALIC,java.awt.Color.blue)));
                //  headerFoter.ALIGN_CENTER;
                 //  headerFoter.setRight(5);
                  docPdf.setFooter(footer);




              } catch(java.sql.SQLException SqlExec) {

                  javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), SqlExec.getMessage());

              }
                           */
              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

            // }  // }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
Esempio n. 28
0
  @Override
  public boolean performFinish() {

    // create the document
    Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize());
    Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize); // rotate if we need landscape

    Document document = new Document(pageSize);

    try {

      // Basic setup of the Document, and get instance of the iText Graphics2D
      //   to pass along to uDig's standard "printing" code.
      String outputFile =
          page1.getDestinationDir()
              + System.getProperty("file.separator")
              + //$NON-NLS-1$
              page1.getOutputFile();
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
      document.open();
      Graphics2D graphics = null;
      Template template = getTemplate();

      int i = 0;
      int numPages = 1;
      do {

        // sets the active page
        template.setActivePage(i);

        PdfContentByte cb = writer.getDirectContent();

        Page page = makePage(pageSize, document, template);

        graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight());

        // instantiate a PrinterEngine (pass in the Page instance)
        PrintingEngine engine = new PrintingEngine(page);

        // make page format
        PageFormat pageFormat = new PageFormat();
        pageFormat.setOrientation(PageFormat.PORTRAIT);
        java.awt.print.Paper awtPaper = new java.awt.print.Paper();
        awtPaper.setSize(pageSize.getWidth() * 3, pageSize.getHeight() * 3);
        awtPaper.setImageableArea(0, 0, pageSize.getWidth(), pageSize.getHeight());
        pageFormat.setPaper(awtPaper);

        // run PrinterEngine's print function
        engine.print(graphics, pageFormat, 0);

        graphics.dispose();
        document.newPage();
        if (i == 0) {
          numPages = template.getNumPages();
        }
        i++;

      } while (i < numPages);

      // cleanup
      document.close();
      writer.close();
    } catch (DocumentException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    } catch (PrinterException e) {
      e.printStackTrace();
    }
    return true;
  }
Esempio n. 29
0
  public void generatePdf() {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          try {

            java.lang.Class.forName("org.postgresql.Driver");

          } catch (java.lang.ClassNotFoundException cnfExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), cnfExec.getMessage());
          }

          String compName = null;
          String date = null;
          try {

            //   java.sql.Connection conDb =
            // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

            java.sql.Statement st3 = connectDB.createStatement();
            java.sql.Statement st4 = connectDB.createStatement();
            java.sql.Statement st2x = connectDB.createStatement();

            java.sql.ResultSet rset2x =
                st2x.executeQuery("SELECT rep_currency from pb_hospitalprofile");
            while (rset2x.next()) {
              ks = rset2x.getObject(1).toString();
            }
            java.sql.ResultSet rset2 =
                st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("" + compName + "", pFontHeader),
                    false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
            // Font.BOLDITALIC,java.awt.Color.blue)));
            headerFoter.setAlignment(com.lowagie.text.HeaderFooter.ALIGN_CENTER);
            headerFoter.setRight(5);
            docPdf.setHeader(headerFoter);

          } catch (java.sql.SQLException SqlExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), SqlExec.getMessage());
          }

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("Transaction List - Page: ", pFontHeader),
                  true); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 12,
          // Font.BOLDITALIC,java.awt.Color.blue));

          docPdf.setFooter(footer);

          docPdf.open();

          try {

            com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(9);

            int headerwidths[] = {5, 25, 10, 10, 14, 10, 14, 14, 8};

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(2);

            table.getDefaultCell().setBorder(Rectangle.BOTTOM);

            table.getDefaultCell().setColspan(9);

            Phrase phrase = new Phrase("", pFontHeader);

            try {
              java.text.DateFormat dateFormat =
                  java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM); // MEDIUM);

              java.util.Date endDate1 =
                  dateFormat.parse(endDate.toLocaleString()); // dateInstance.toLocaleString());
              java.util.Date endDate11 =
                  dateFormat.parse(beginDate.toLocaleString()); // dateInstance.toLocaleString());

              System.out.println("" + endDate1);
              //  phrase = new Phrase(bank +" Report: " +dateFormat.format(formattedDate),
              // pFontHeader);

              //  table.addCell(phrase);
              table.getDefaultCell().setColspan(5);

              phrase =
                  new Phrase(
                      "Sales ["
                          + CashPoint
                          + "] Report :     Period : From "
                          + dateFormat.format(endDate11)
                          + " To "
                          + dateFormat.format(endDate1),
                      pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(4);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase = new Phrase("Printed On  : " + date, pFontHeader);

              table.addCell(phrase);
            } catch (java.text.ParseException psExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), psExec.getMessage());
            }
            // Phrase phrase = new Phrase("Patients List As At:" +endDate, pFontHeader);

            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);

            table.getDefaultCell().setColspan(1);

            //    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
            phrase = new Phrase("No", pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("ITEM", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("UNIT", pFontHeader);
            // table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("COUNT", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("UNIT COST", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("TOTAL COST", pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

            phrase = new Phrase("SELLING PRICE", pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("TOTAL " + ks, pFontHeader);
            table.addCell(phrase);

            phrase = new Phrase("PROFIT " + ks, pFontHeader);
            table.addCell(phrase);
            phrase = new Phrase("MARKUP%", pFontHeader);
            table.addCell(phrase);
            table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
            table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

            double osBalance11 = 0.00;
            double osBalance31 = 0.00;

            double current = 0.00;
            double osBalance1 = 0.00;

            double osBalance3 = 0.00;
            try {
              java.lang.Object[] listofAct1 = this.getDates();
              // for (int k = 0; k < listofAct1.length; k++) {
              double osBalance21 = 0.00;
              double osBalance22 = 0.00;
              double osBalance23 = 0.00;
              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);
              table.getDefaultCell().setColspan(8);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              //     phrase = new Phrase(listofAct1[k].toString().toUpperCase(), pFontHeader);
              //  table.addCell(phrase);
              java.lang.Object[] listofAct = this.getListofActivities();

              // java.lang.Object[] listofAct = this.getListofActivities();

              //    java.sql.Connection conDb1 =
              // java.sql.DriverManager.getConnection("jdbc:postgresql://localhost:5432/sako","postgres","pilsiner");

              System.out.println(listofAct.length);

              //  java.sql.Statement pSet1 = connectDB.createStatement();
              java.sql.Statement st = connectDB.createStatement();

              for (int i = 0; i < listofAct.length; i++) {
                double qtys = 0.00;
                double osBalance2 = 0.00;
                // AND st.transfer_price > 0
                System.out.println("item" + listofAct[i]);
                //  java.sql.Statement stbx = connectDB.createStatement();
                java.sql.Statement st2 = connectDB.createStatement();
                // java.sql.PreparedStatement st1 = connectDB.prepareStatement("select
                // ph.description,sum(ph.quantity) as quantity,avg(st.transfer_price)::numeric(10,2)
                // as bprice,sum((ph.quantity * st.transfer_price)::numeric(10,2)) as cost, CASE
                // WHEN (sum(ph.quantity) > 0 ) THEN
                // (sum(ph.amount)/sum(ph.quantity))::numeric(10,2) ELSE 1.00 END AS
                // sprice,sum(amount)::numeric(10,2) as amt,sum(amount) - sum(ph.quantity *
                // st.transfer_price)::numeric(10,2),CASE WHEN (sum(transfer_price) = 0) THEN 0.00
                // ELSE (avg(st.selling_price)/avg(st.transfer_price))::numeric(10,2) END AS markup
                // from hp_pharmacy ph,st_stock_prices st WHERE ph.main_service ilike
                // '"+CashPoint+"%' AND st.department ilike '"+CashPoint+"%' and ph.description = ?
                // AND ph.date_prescribed BETWEEN '"+beginDate+"' AND '"+endDate+"' AND
                // ph.description ilike st.product GROUP BY ph.description");
                java.sql.PreparedStatement st1 =
                    connectDB.prepareStatement(
                        "select ph.description,sum(ph.quantity) as quantity,avg(st.transfer_price)::numeric(10,2) as bprice,sum((ph.quantity * st.transfer_price)::numeric(10,2)) as cost, CASE WHEN (sum(ph.quantity) > 0 ) THEN (sum(ph.amount)/sum(ph.quantity))::numeric(10,2) ELSE 1.00 END AS sprice,sum(amount)::numeric(10,2) as amt,sum(amount) - sum(ph.quantity * st.transfer_price)::numeric(10,2),CASE WHEN (sum(transfer_price) = 0) THEN 0.00 ELSE (avg(st.selling_price)/avg(st.transfer_price))::numeric(10,2) END AS markup from hp_pharmacy ph,st_stock_prices st WHERE ph.main_service ilike '"
                            + CashPoint
                            + "%' AND st.department ilike '"
                            + CashPoint
                            + "%' and ph.description = ? AND ph.date_prescribed BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' AND ph.description = st.product GROUP BY ph.description");

                // java.sql.PreparedStatement stbx = connectDB.prepareStatement("select
                // sum(credit-debit) FROM ac_ledger WHERE activity_code ilike '"+gAccount+"%' and
                // service_type ilike ? AND date BETWEEN '"+beginDate+"' AND '"+endDate+"' AND
                // (transaction_type = 'Revenue' OR transaction_type = 'Refunds') GROUP BY
                // service_type");
                java.sql.PreparedStatement stbx =
                    connectDB.prepareStatement(
                        "select sum(credit-debit) FROM ac_ledger WHERE activity_code = '"
                            + gAccount
                            + "' and service_type = ? AND date::date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' GROUP BY service_type");
                st1.setString(1, listofAct[i].toString());
                java.sql.ResultSet rset = st1.executeQuery();
                stbx.setString(1, listofAct[i].toString());
                java.sql.ResultSet rsetbx = stbx.executeQuery();
                while (rset.next()) {
                  while (rsetbx.next()) {
                    // table.getDefaultCell().setColspan(1);
                    table.getDefaultCell().setColspan(1);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    counter = counter + 1;
                    phrase = new Phrase("" + counter, pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(dbObject.getDBObject(rset.getObject(1), "-"), pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(rset.getString(2)),
                            pFontHeader1);
                    table.addCell(phrase);
                    qtys = rset.getDouble(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(rset.getString(3)),
                            pFontHeader1);
                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(rset.getString(4)),
                            pFontHeader1);
                    osBalance1 = rset.getDouble(4);
                    osBalance21 = osBalance21 + rset.getDouble(4);
                    osBalance11 = rset.getDouble(4);
                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    /* phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(rset.getString(6)),pFontHeader1);
                    osBalance2 = osBalance2 + rset.getDouble(6);
                    osBalance22 = osBalance22 + rset.getDouble(6);
                    table.addCell(phrase);
                    */

                    // phrase = new Phrase(new
                    // com.afrisoftech.sys.Format2Currency().Format2Currency(rsetbx.getString(1)),pFontHeader1);
                    osBalance2 = rsetbx.getDouble(1);
                    osBalance22 = osBalance22 + rsetbx.getDouble(1);
                    if (qtys > 0) {
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(java.lang.String.valueOf(osBalance2 / qtys)),
                              pFontHeader1);
                      table.addCell(phrase);
                    } else {
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(java.lang.String.valueOf(osBalance2 / 1)),
                              pFontHeader1);
                      table.addCell(phrase);
                    }

                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(java.lang.String.valueOf(osBalance2)),
                            pFontHeader1);

                    table.addCell(phrase);

                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    // phrase = new Phrase(new
                    // com.afrisoftech.sys.Format2Currency().Format2Currency(rset.getString(7)),pFontHeader1);
                    phrase =
                        new Phrase(
                            new com.afrisoftech.sys.Format2Currency()
                                .Format2Currency(java.lang.String.valueOf(osBalance2 - osBalance1)),
                            pFontHeader1);

                    /* osBalance3 = osBalance3 + rset.getDouble(7);
                    osBalance23 = osBalance23 + rset.getDouble(7);
                    osBalance31 = rset.getDouble(7);
                    */

                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    if (osBalance1 > 0) {
                      // phrase = new Phrase(new
                      // com.afrisoftech.sys.Format2Currency().Format2Currency(rset.getString(8)),pFontHeader1);
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(
                                      java.lang.String.valueOf(osBalance2 / osBalance1)),
                              pFontHeader1);

                      table.addCell(phrase);
                    } else {
                      phrase =
                          new Phrase(
                              new com.afrisoftech.sys.Format2Currency()
                                  .Format2Currency(java.lang.String.valueOf(osBalance2 / 1)),
                              pFontHeader1);

                      table.addCell(phrase);
                    }
                  }
                }
              }

              table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

              table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

              //  while (rsetTotals.next()) {
              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("" + counter, pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(2);
              phrase = new Phrase("  ", pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase("Total", pFontHeader);

              table.addCell(phrase);

              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance21)),
                      pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
              phrase = new Phrase(" ", pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance22)),
                      pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

              phrase =
                  new Phrase(
                      new com.afrisoftech.sys.Format2Currency()
                          .Format2Currency(java.lang.String.valueOf(osBalance22 - osBalance21)),
                      pFontHeader);

              table.addCell(phrase);
              table.getDefaultCell().setColspan(1);

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
              //   phrase = new Phrase(" ", pFontHeader);
              if (osBalance21 > 0) {
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(osBalance22 / osBalance21)),
                        pFontHeader);

                table.addCell(phrase);
              } else {
                phrase =
                    new Phrase(
                        new com.afrisoftech.sys.Format2Currency()
                            .Format2Currency(java.lang.String.valueOf(0.00)),
                        pFontHeader);

                table.addCell(phrase);
              }
              //  }
              /*   table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

                //  while (rsetTotals.next()) {
                table.getDefaultCell().setColspan(2);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("  ", pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("Sum Total", pFontHeader);

                table.addCell(phrase);

                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(osBalance1)), pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(" ", pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(osBalance2)), pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                phrase = new Phrase(new com.afrisoftech.sys.Format2Currency().Format2Currency(java.lang.String.valueOf(osBalance3)), pFontHeader);

                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(" ", pFontHeader);

                table.addCell(phrase);
              */

              docPdf.add(table);

            } catch (java.sql.SQLException SqlExec) {

              javax.swing.JOptionPane.showMessageDialog(
                  new javax.swing.JFrame(), SqlExec.getMessage());
            }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();
      docPdf.close();
      com.afrisoftech.lib.PDFRenderer.renderPDF(tempFile);

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
  public void generatePdf(java.lang.String memNo) {

    java.lang.Process wait_for_Pdf2Show;

    java.util.Calendar cal = java.util.Calendar.getInstance();

    java.util.Date dateStampPdf = cal.getTime();

    java.lang.String pdfDateStamp = dateStampPdf.toString();

    try {

      java.io.File tempFile =
          java.io.File.createTempFile("REP" + this.getDateLable() + "_", ".pdf");

      tempFile.deleteOnExit();

      java.lang.Runtime rt = java.lang.Runtime.getRuntime();

      java.lang.String debitTotal = null;

      java.lang.String creditTotal = null;

      com.lowagie.text.Document docPdf = new com.lowagie.text.Document();

      try {

        try {

          com.lowagie.text.pdf.PdfWriter.getInstance(
              docPdf, new java.io.FileOutputStream(tempFile));

          String compName = null;
          String date = null;
          /*   try {


                 java.sql.Statement st3 = connectDB.createStatement();
                 java.sql.Statement st4 = connectDB.createStatement();

                 java.sql.ResultSet rset2 = st3.executeQuery("SELECT hospital_name from pb_hospitalprofile");
                 java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
                 while(rset2.next())
                     compName = rset2.getObject(1).toString();

                 while(rset4.next())
                     date = rset4.getObject(1).toString();
          */
          com.lowagie.text.HeaderFooter headerFoter =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("FINAL VOUCHER"),
                  false); // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
          // Font.BOLDITALIC,java.awt.Color.blue)));

          //  com.lowagie.text.HeaderFooter headerFoter = new com.lowagie.text.HeaderFooter(new
          // Phrase(""+compName+""),false);//
          // FontFactory.getFont(com.lowagie.text.FontFactory.HELVETICA, 14,
          // Font.BOLDITALIC,java.awt.Color.blue)));
          headerFoter.setRight(5);
          docPdf.setHeader(headerFoter);

          docPdf.open();

          try {

            java.lang.Object listofStaffNos[] = this.getListofStaffNos();

            for (int j = 0; j < listofStaffNos.length; j++) {
              com.lowagie.text.pdf.PdfPTable table = new com.lowagie.text.pdf.PdfPTable(6);

              int headerwidths[] = {25, 25, 20, 15, 15, 15};

              table.setWidths(headerwidths);

              table.setWidthPercentage((100));

              table.getDefaultCell().setBorder(Rectangle.BOTTOM);

              table.getDefaultCell().setColspan(6);

              Phrase phrase = new Phrase();

              //  table.addCell(phrase);

              table.getDefaultCell().setColspan(1);
              table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
              table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

              try {

                java.sql.Statement st = connectDB.createStatement();
                java.sql.Statement st1 = connectDB.createStatement();
                java.sql.Statement st2 = connectDB.createStatement();
                java.sql.Statement st3 = connectDB.createStatement();
                java.sql.Statement st4 = connectDB.createStatement();
                java.sql.Statement st5 = connectDB.createStatement();
                java.sql.ResultSet rset3 =
                    st3.executeQuery(
                        "select hospital_name,postal_code||' '||box_no||' '||town,main_telno||' '||other_telno,initcap(street),main_faxno,email,website,room_no from pb_hospitalprofile");
                java.sql.ResultSet rset4 =
                    st4.executeQuery("select dealer,description from ac.cash_book");
                // java.sql.ResultSet rset = st.executeQuery("select DISTINCT member_code,
                // member_name,date from shares_transactions order by member_code");
                java.sql.ResultSet rset =
                    st.executeQuery(
                        "select patient_no,initcap(first_name||' '||second_name||' '||last_name),address,residence,tel_no from hp_patient_register where patient_no = '"
                            + listofStaffNos[j]
                            + "'");
                java.sql.ResultSet rset5 =
                    st5.executeQuery(
                        "select staff_no,staff_name from hp_schemestaff sh, hp_patient_card pc where pc.patient_no = '"
                            + listofStaffNos[j]
                            + "' AND pc.scheme_staff_no = sh.staff_no");
                java.sql.ResultSet rset1 =
                    st1.executeQuery(
                        "select date::date,initcap(service) as service,dosage,reference,debit from hp_patient_card where patient_no = '"
                            + listofStaffNos[j]
                            + "' AND paid = true order by date");
                java.sql.ResultSet rsetTotals =
                    st2.executeQuery(
                        "select sum(debit) from hp_patient_card where patient_no = '"
                            + listofStaffNos[j]
                            + "' AND paid = true");

                while (rset3.next()) {
                  table.getDefaultCell().setColspan(6);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                  phrase = new Phrase(rset3.getObject(1).toString(), pFontHeader1);
                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(6);
                  table.getDefaultCell().setBorderColor(java.awt.Color.white);

                  table.getDefaultCell().setColspan(2);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase =
                      new Phrase("Address:" + "\t" + rset3.getObject(2).toString(), pFontHeader);
                  table.addCell(phrase);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Tel:" + "\t" + rset3.getObject(3).toString(), pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Fax:" + "\t" + rset3.getObject(5).toString(), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setBorderColor(java.awt.Color.white);
                  table.getDefaultCell().setColspan(3);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Email:" + "\t" + rset3.getObject(6).toString(), pFontHeader);
                  table.addCell(phrase);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase =
                      new Phrase("Website:" + "\t" + rset3.getObject(7).toString(), pFontHeader);

                  table.addCell(phrase);
                  /// table.addCell("  ");

                }
                table.getDefaultCell().setColspan(6);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                phrase = new Phrase("Voucher", pFontHeader1);
                table.addCell(phrase);

                while (rset4.next()) table.getDefaultCell().setColspan(6);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase(rset4.getObject(1).toString(), pFontHeader1);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("Address:  " + rset4.getObject(2).toString(), pFontHeader);
                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("Tel:       " + rset4.getObject(3).toString(), pFontHeader);

                table.addCell(phrase);

                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                phrase = new Phrase("Fax:       " + rset4.getObject(4).toString(), pFontHeader);

                table.addCell(phrase);
                /*    table.getDefaultCell().setBorderColor(java.awt.Color.white);
                  table.getDefaultCell().setColspan(3);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Email:"+"\t"+rset3.getObject(6).toString(), pFontHeader);
                  table.addCell(phrase);


                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Website:"+"\t" +rset3.getObject(7).toString(), pFontHeader);

                  table.addCell(phrase);
                  /// table.addCell("  ");
                */

                while (rset5.next()) {

                  table.getDefaultCell().setColspan(6);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Member No.  " + rset5.getObject(1).toString(), pFontHeader);
                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(6);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Member Name  " + rset5.getObject(2).toString(), pFontHeader);
                  table.addCell(phrase);
                }
                while (rset.next()) {

                  table.getDefaultCell().setColspan(6);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Patient No.  " + rset.getObject(1).toString(), pFontHeader);
                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(6);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Patient Name  " + rset.getObject(2).toString(), pFontHeader);
                  table.addCell(phrase);

                  /*
                  table.getDefaultCell().setColspan(2);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Address  "+rset.getObject(3).toString(), pFontHeader);
                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(2);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Town  "+rset.getObject(4).toString(), pFontHeader);
                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(2);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("TEl No. "+rset.getObject(5).toString(), pFontHeader);
                  table.addCell(phrase);
                  */

                }
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);
                table.getDefaultCell().setBorderWidth(Rectangle.TOP);
                table.getDefaultCell().setColspan(1);
                phrase = new Phrase("Date", pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setColspan(2);
                phrase = new Phrase("Description", pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setColspan(1);
                phrase = new Phrase("Qty", pFontHeader1);
                table.addCell(phrase);

                table.getDefaultCell().setColspan(1);
                phrase = new Phrase("Ref", pFontHeader1);
                table.addCell(phrase);
                table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                table.getDefaultCell().setColspan(1);
                phrase = new Phrase("Amount KShs", pFontHeader1);
                table.addCell(phrase);

                while (rset1.next()) {
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setBorderColor(java.awt.Color.WHITE);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset1.getObject(1).toString(), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(2);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset1.getObject(2).toString(), pFontHeader);

                  table.addCell(phrase);
                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset1.getObject(3).toString(), pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase(rset1.getObject(4).toString(), pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(1);
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rset1.getString(5)),
                          pFontHeader);

                  table.addCell(phrase);
                }

                table.getDefaultCell().setBorderColor(java.awt.Color.BLACK);

                table.getDefaultCell().setBorder(Rectangle.BOTTOM | Rectangle.TOP);

                while (rsetTotals.next()) {

                  table.getDefaultCell().setColspan(3);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase = new Phrase("Total", pFontHeader);

                  table.addCell(phrase);

                  table.getDefaultCell().setColspan(3);

                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);

                  phrase =
                      new Phrase(
                          new com.afrisoftech.sys.Format2Currency()
                              .Format2Currency(rsetTotals.getString(1)),
                          pFontHeader);

                  table.addCell(phrase);

                  // phrase = new Phrase(" ");

                }

                docPdf.add(table);

              } catch (java.sql.SQLException SqlExec) {

                javax.swing.JOptionPane.showMessageDialog(
                    new javax.swing.JFrame(), SqlExec.getMessage());
              }
            } // }

          } catch (com.lowagie.text.BadElementException BadElExec) {

            javax.swing.JOptionPane.showMessageDialog(
                new javax.swing.JFrame(), BadElExec.getMessage());
          }

        } catch (java.io.FileNotFoundException fnfExec) {

          javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), fnfExec.getMessage());
        }
      } catch (com.lowagie.text.DocumentException lwDocexec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), lwDocexec.getMessage());
      }

      docPdf.close();

      try {

        if (System.getProperty("os.name").equalsIgnoreCase("Linux")) {

          System.out.println(tempFile);

          wait_for_Pdf2Show = rt.exec("kghostview " + tempFile + "");

          wait_for_Pdf2Show.waitFor();

        } else {

          wait_for_Pdf2Show =
              rt.exec("c:/Program Files/Adobe/Acrobat 5.0/Reader/AcroRd32.exe " + tempFile);

          wait_for_Pdf2Show.waitFor();
        }

      } catch (java.lang.InterruptedException intrExec) {

        javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), intrExec.getMessage());
      }

    } catch (java.io.IOException IOexec) {

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }