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(PageSize.A2.rotate());

      try {

        try {
          Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());

          // Image imgWaterMark = Image.getInstance(System.getProperty("company.watermark"));

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

          String compName = null;

          String District = null;

          String Region = 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,district_branch from pb_hospitalprofile");
            java.sql.ResultSet rset4 = st4.executeQuery("SELECT date('now') as Date");
            while (rset2.next()) {
              compName = rset2.getObject(1).toString();
              District = rset2.getObject(2).toString();
            }
            while (rset4.next()) {
              date = rset4.getObject(1).toString();
            }
            com.lowagie.text.HeaderFooter headerFoter =
                new com.lowagie.text.HeaderFooter(
                    new Phrase("MINISTRY OF HEALTH : " + compName.toUpperCase()),
                    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) {

            SqlExec.printStackTrace();

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

          com.lowagie.text.HeaderFooter footer =
              new com.lowagie.text.HeaderFooter(
                  new Phrase("MOH - 204B : OP Over 5 Yrs Register : 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(21);

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

            table.setWidths(headerwidths);

            table.setWidthPercentage((100));

            table.setHeaderRows(4);

            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();

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

              table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
              table.getDefaultCell().setFixedHeight(50);
              table.addCell(Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo()));
              table.getDefaultCell().setFixedHeight(-1);
              // table.getDefaultCell().setNoWrap(false);
              phrase = new Phrase("MOH 204B_Over 5 Yrs Register", pFontHeader2);

              table.addCell(phrase);

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

              phrase = new Phrase("OP OVER 5 YEARS REGISTER", pFontHeader22);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(10);
              phrase = new Phrase("HEALTH FACILITY : " + compName, pFontHeader22);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("MONTH : " + monthString.toUpperCase(), pFontHeader22);
              table.addCell(phrase);

              table.getDefaultCell().setColspan(3);
              phrase = new Phrase("YEAR : " + yearString.toUpperCase(), pFontHeader22);
              table.addCell(phrase);

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

              table.getDefaultCell().setColspan(1);

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

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

              table.getDefaultCell().setColspan(1);

              phrase = new Phrase("#", pFontHeader11);

              table.addCell(phrase);

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

              phrase = new Phrase("OPD No.", pFontHeader11);
              table.addCell(phrase);

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

              phrase = new Phrase("Full Names", pFontHeader11);
              table.addCell(phrase);

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

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

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

              phrase = new Phrase("Phone. No.", pFontHeader11);
              table.addCell(phrase);

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

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

              phrase = new Phrase("Visual Activity RE(Right Eye), LE(LEFT EYE)", pFontHeader11);
              table.addCell(phrase);

              phrase = new Phrase("HIV: 1=Cancelled, 2=Tested", pFontHeader11);
              table.addCell(phrase);

              phrase =
                  new Phrase(
                      "HIV Status: 1=Known Positive, 2=Positive this visit, 3=Negative, 4=Uknown",
                      pFontHeader11);
              table.addCell(phrase);

              phrase =
                  new Phrase(
                      "Nutrition Status: 1=Nutrition Education, 2=Nutrition Suppliments",
                      pFontHeader11);
              table.addCell(phrase);

              phrase = new Phrase("Diagnosis/Classification", pFontHeader11);
              table.addCell(phrase);

              phrase = new Phrase("Treatment/Prescription No.", pFontHeader11);
              table.addCell(phrase);

              phrase = new Phrase("Amount Charged", pFontHeader11);
              table.addCell(phrase);

              phrase = new Phrase("Receipt No.", pFontHeader11);
              table.addCell(phrase);

              phrase =
                  new Phrase(
                      "1 = From Other HF, 2 = To Other HF, 3 = From CU, 4 = To CU", pFontHeader11);
              table.addCell(phrase);

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

              // Second header row

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            } catch (java.text.ParseException psExec) {

              psExec.printStackTrace();

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

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

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

            try {

              int noSeq = 0;

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

              System.out.println("The array has been called...");

              for (int i = 0; i < listofAct.length; i++) {

                java.sql.PreparedStatement stw =
                    connectDB.prepareStatement(
                        "SELECT DISTINCT "
                            + " date_part('day', date) ||'-'||date_part('month', date) ||'-'||date_part('year', date), patient_no,"
                            + " (CASE WHEN comments = 'Old' THEN 'YES' ELSE 'NO' END) as revisit, "
                            + " initcap(name), age::int, (SELECT initcap(gender) FROM hp_patient_register WHERE hp_patient_register.patient_no = hp_patient_visit.patient_no ORDER BY 1 DESC LIMIT 1) as gender, "
                            + " (SELECT initcap(residence) FROM hp_inpatient_register"
                            + " WHERE hp_patient_visit.patient_no = hp_inpatient_register.patient_no"
                            + " UNION SELECT initcap(residence) FROM hp_patient_register WHERE "
                            + " hp_patient_visit.patient_no = hp_patient_register.patient_no ORDER BY 1 "
                            + " DESC LIMIT 1) as village, (SELECT tel_no FROM hp_patient_register WHERE hp_patient_register.patient_no = hp_patient_visit.patient_no "
                            + " ORDER BY 1 DESC LIMIT 1) as telephone, (SELECT weight::numeric(5,1) FROM hp_signs_record WHERE hp_signs_record.patient_no = hp_patient_visit.patient_no  AND hp_signs_record.date = hp_patient_visit.date ORDER BY 1 DESC LIMIT 1) as weight,"
                            + " (SELECT height::numeric(5,1) FROM hp_signs_record WHERE hp_signs_record.patient_no = hp_patient_visit.patient_no AND hp_signs_record.date = hp_patient_visit.date  ORDER BY 1 DESC LIMIT 1) as height, "
                            + " ''," // to add eye conditions for over 5 years
                            + " (SELECT (CASE WHEN hiv_counselled = true THEN '1' ELSE '' END) || ' '||"
                            + "(CASE WHEN hiv_tested = true THEN '2' ELSE '' END) FROM key_health_indicators"
                            + " WHERE key_health_indicators.patient_no = hp_patient_visit.patient_no) as hiv_tested,"
                            + " (SELECT (CASE WHEN hiv_status ilike '%positive%' THEN '1' ELSE '' END) || ' '||"
                            + "(CASE WHEN hiv_status ilike '%visit' THEN '2' ELSE '' END)||' '||"
                            + "(CASE WHEN hiv_status ilike 'negative' THEN '3' ELSE '' END)||' '||"
                            + "(CASE WHEN hiv_status ilike 'unknown' THEN '4' ELSE '' END) FROM key_health_indicators"
                            + " WHERE key_health_indicators.patient_no = hp_patient_visit.patient_no) as hiv_status,"
                            + " (SELECT (CASE WHEN nutrition_status ilike '%education%' THEN '1' ELSE '' END)||' '||"
                            + "(CASE WHEN nutrition_status ILIKE '%suppliments%' THEN '2' ELSE '' END) "
                            + "FROM key_health_indicators WHERE key_health_indicators.patient_no = hp_patient_visit.patient_no)"
                            + " as nutrition_status, "
                            + " (SELECT disease FROM hp_patient_diagnosis WHERE hp_patient_diagnosis.patient_no = hp_patient_visit.patient_no AND"
                            + " hp_patient_diagnosis.date_recorded::date = hp_patient_visit.date::date AND disease is not null ORDER BY 1 DESC LIMIT 1) as diagnosis, "
                            + " (SELECT replace(treatment, 'null', '') FROM hp_clinical_results WHERE hp_clinical_results.patient_no ="
                            + " hp_patient_visit.patient_no AND hp_clinical_results.date = hp_patient_visit.date "
                            + "ORDER BY 1 DESC LIMIT 1) as treatment, "
                            + " (SELECT sum(credit-debit) FROM ac_ledger WHERE ac_ledger.patient_no = "
                            + "hp_patient_visit.patient_no AND ac_ledger.date = hp_patient_visit.date) "
                            + "as amount, '', "
                            + " (SELECT refer_source FROM hp_patient_register WHERE hp_patient_register.patient_no"
                            + " = hp_patient_visit.patient_no AND hp_patient_register.date = hp_patient_visit.date"
                            + " ORDER BY 1 DESC LIMIT 1) as referral,"
                            + " (SELECT comments FROM hp_clinical_results WHERE hp_clinical_results.patient_no "
                            + "= hp_patient_visit.patient_no AND hp_clinical_results.date = hp_patient_visit.date"
                            + " ORDER BY 1 DESC LIMIT 1 )as comments FROM hp_patient_visit WHERE "
                            + " date::date BETWEEN '"
                            + beginDate
                            + "' AND '"
                            + endDate
                            + "' "
                            + " AND patient_no = ?");

                stw.setObject(1, listofAct[i]);

                java.sql.ResultSet rsetw = stw.executeQuery();

                while (rsetw.next()) {

                  table.getDefaultCell().setColspan(1);

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

                  table.getDefaultCell().setColspan(1);
                  noSeq = noSeq + 1;
                  // Index
                  phrase = new Phrase(java.lang.String.valueOf(noSeq), pFontHeader1);
                  table.addCell(phrase);
                  // Lab procedure date
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(1), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Patient Number
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(2), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Lab Number
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(3), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Revisit No
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(4), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Patient names
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(5), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Age
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(6), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Gender
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(7), ""),
                          pFontHeader1);
                  table.addCell(phrase);

                  // Village
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(8), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Telephone number
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(9), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Clinical diagnosis
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(10), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Prior treatment
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(11), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Type of specimen
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(12), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Condition of specimen
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(13), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Investigation required
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(14), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Date sample taken
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(15), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Date sample received
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(16), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Amount Paid by client
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(17), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Date sample analysed
                  table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(18), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Results
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(19), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                  // Date result dispatched
                  phrase =
                      new Phrase(
                          new com.afrisoftech.lib.DBObject().getDBObject(rsetw.getString(20), ""),
                          pFontHeader1);
                  table.addCell(phrase);
                }
              }

              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());
      }

      docPdf.close();

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

    } catch (java.io.IOException IOexec) {

      IOexec.printStackTrace();

      javax.swing.JOptionPane.showMessageDialog(new javax.swing.JFrame(), IOexec.getMessage());
    }
  }
예제 #2
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());
    }
  }