Example usage for com.lowagie.text Rectangle BOTTOM

List of usage examples for com.lowagie.text Rectangle BOTTOM

Introduction

In this page you can find the example usage for com.lowagie.text Rectangle BOTTOM.

Prototype

int BOTTOM

To view the source code for com.lowagie.text Rectangle BOTTOM.

Click Source Link

Document

This represents one side of the border of the Rectangle.

Usage

From source file:com.afrisoftech.reports.PatientRegReprintFormPdf.java

public void generatePdf(java.sql.Connection con, String patientNo, String type, String receipt_no,
        String receipt_time) {/*from  www.  java  2 s .c om*/

    String patientName = null;
    String patientAge = null;
    String PatientGender = null;
    String patientNationality = null;
    String patientIDPassport = null;
    String placeofBirth = null;
    String patientOccupation = null;
    String maritalStatus = null;
    String patientReligion = null;
    String patientTelephone = null;
    String patientEmail = null;
    String patientVillage = null;
    String patientLocation = null;
    String patientHomeCounty = null;
    String patientResidenceCounty = null;
    String patientNOK = null;
    String patientRelation = null;
    String patientNOKTelephone = null;
    String patientReferFrom = null;
    String bookingDate = null;
    String specialtyClinic = null;
    String statusNHIF = null;
    String NHIFNumber = null;
    String educationLevel = null;
    String employerTelephone = null;
    String patientEmployer = null;
    String paidAmount = null;
    String receiptNumber = null;
    String cSheetNo = null;
    String invoiceNumber = null;
    String interviewerName = null;
    String interviewDate = null;
    String servicePoint = null;
    String unitNumber = null;
    String patientNumber = null;
    String admissionWard = null;
    String admissionDate = null;
    String admissionType = null;
    String claimNumber = null;
    java.util.Date date = null;
    String gender = null;
    String typeofAccident = null;
    String modeofArrival = null;
    String nameofPoliceOfficer = null;
    String policeForceNO = null;
    String policeStationAccident = null;
    String dateAccident = null;
    String nameofDriver = null;
    String accidentVehicleNo = null;
    String driverLicenceNo = null;
    String driversIDNo = null;
    String patNo = null;
    patNo = patientNo;
    try {

        //            java.sql.ResultSet rse124 = stm124.executeQuery("SELECT first_name, second_name, nok, residence, \n" +
        //"       address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, \n" +
        //"       description, category, expiry_date, last_visit, department, member_name, \n" +
        //"       card_no, emails, id_no, nok_add, old_patient_no, pat_nationality, \n" +
        //"       nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status, \n" +
        //"       tribe, district, locations, sub_location, chief_name, sub_chief, \n" +
        //"       information_source, education_level, occupation, pat_religion, \n" +
        //"       patient_race, birth_place, waiting_patient, email, home_county, \n" +
        //"       residence_county, nhif_status, nhif_number, employer_name, employer_telephone, \n" +
        //"       refer_source, charge_sheet_no, specialty_clinic\n" +
        //"  FROM hp_patient_register; where patient_no='"+patNo+"' ");
        if (type.equals("OP")) {

            java.sql.Statement stm12456 = con.createStatement();
            java.sql.ResultSet rse124 = stm12456
                    .executeQuery("SELECT   hp.patient_no, first_name, second_name, last_name, nok, residence,"
                            + " address, year_of_birth, tel_no, sex, date, pay_mode, payer, account_no, "
                            + " description, category, expiry_date, last_visit, department, member_name,"
                            + " card_no, emails, id_no, nok_add, old_patient_no, pat_nationality,"
                            + " nok_telno, nok_relationship, nok_residence, nok_email, pat_marital_status,"
                            + " tribe, district, locations, sub_location, chief_name, sub_chief,"
                            + " information_source, education_level, occupation, pat_religion,"
                            + " patient_race, birth_place, waiting_patient, email, home_county,"
                            + " residence_county, nhif_status, nhif_number, employer_name, employer_telephone,"
                            + " refer_source, charge_sheet_no, specialty_clinic, accident_type, arrival_mode, police_officer_no, police_station,date_time, driver_name, accident_vehicle_no, driver_license, driver_id_no,service_point,user_name FROM  hp_patient_register hp LEFT JOIN rta_info rt  on hp.patient_no=rt.patient_no WHERE hp.patient_no='"
                            + patNo + "' ORDER BY date_time desc  limit 1 ");
            while (rse124.next()) {

                patientName = rse124.getString(2).toUpperCase() + " " + rse124.getString(3).toUpperCase();
                patientAge = PatientAge.getPatientActualAge(con,
                        com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("year_of_birth")));
                PatientGender = rse124.getString("sex");
                patientNationality = rse124.getString("pat_nationality");
                patientIDPassport = rse124.getString("id_no");
                placeofBirth = rse124.getString("birth_place");
                patientOccupation = rse124.getString("occupation");
                maritalStatus = rse124.getString("pat_marital_status");
                patientReligion = rse124.getString("pat_religion");
                patientTelephone = rse124.getString("tel_no");
                patientEmail = rse124.getString("emails");
                patientVillage = rse124.getString("residence");
                patientLocation = rse124.getString("locations");
                patientHomeCounty = rse124.getString("home_county");
                patientResidenceCounty = rse124.getString("residence_county");
                patientNOK = rse124.getString("nok");
                patientRelation = rse124.getString("nok_relationship");
                //jddfsjdsj
                patientNOKTelephone = rse124.getString("nok_telno");
                patientReferFrom = rse124.getString("refer_source");
                bookingDate = rse124.getString("date");
                specialtyClinic = rse124.getString("specialty_clinic");
                statusNHIF = rse124.getString("nhif_status");
                NHIFNumber = rse124.getString("nhif_number");
                educationLevel = rse124.getString("education_level");
                employerTelephone = rse124.getString("employer_telephone");
                patientEmployer = rse124.getString("employer_name");
                paidAmount = "";
                receiptNumber = "";
                cSheetNo = rse124.getString("charge_sheet_no");
                invoiceNumber = "";
                interviewerName = rse124.getString("user_name");
                interviewDate = rse124.getString("date");
                servicePoint = rse124.getString("service_point");
                unitNumber = rse124.getString("patient_race");
                patientNumber = rse124.getString("patient_no");
                admissionWard = "";
                admissionDate = "";
                admissionType = "";
                claimNumber = "";
                date = com.afrisoftech.lib.SQLDateFormat.getSQLDate(rse124.getDate("date"));
                gender = rse124.getString("sex");
                typeofAccident = rse124.getString("accident_type");
                modeofArrival = rse124.getString("arrival_mode");
                nameofPoliceOfficer = rse124.getString("police_officer_no");
                policeForceNO = rse124.getString("police_officer_no");
                policeStationAccident = rse124.getString("police_station");
                dateAccident = rse124.getString("date_time");
                nameofDriver = rse124.getString("driver_name");
                accidentVehicleNo = rse124.getString("accident_vehicle_no");
                driverLicenceNo = rse124.getString("driver_license");
                driversIDNo = rse124.getString("driver_id_no");
                System.out.println("");

            }

            ///getting the receipt details
            try {
                java.sql.Statement stmt11 = connectDB.createStatement();
                //java.sql.ResultSet rset11 = stmt11.executeQuery("SELECT  description,receipt_no, debit  FROM ac_cash_collection where  patient_no='" + patientNumberTxt.getText() + "' and receipt_time::date >= current_date-1 ");
                java.sql.ResultSet rset11 = stmt11.executeQuery(
                        "SELECT  description,receipt_no, debit  FROM ac_cash_collection where  patient_no='"
                                + patNo + "'   and receipt_no='" + receipt_no + "' and receipt_time::date='"
                                + receipt_time + "'::date ");
                while (rset11.next()) {
                    receiptNumber = rset11.getObject(2).toString();
                    paidAmount = rset11.getObject(3).toString();

                    System.out.println("This is the receipt no " + receiptNumber + " and this is the AMOUNT "
                            + paidAmount);
                }

            } catch (Exception ex) {
                ex.printStackTrace();
                ex.getMessage();
            }

            ///end
        } else if (type.equals("IP")) {
        }

    } catch (java.sql.SQLException sq) {
        javax.swing.JOptionPane.showMessageDialog(null, sq.getMessage(), "Error Message!",
                javax.swing.JOptionPane.ERROR_MESSAGE);

        System.out.println(sq.getMessage());
    }

    java.util.Date date111 = date;
    java.lang.String formLabel = null;

    //        if(admissionWard.toCharArray().length < 1){
    //            
    //            formLabel = "PATIENT REGISTRATION FORM";
    //            
    //        } else {
    //            formLabel = "PATIENT ADMISSION FORM";
    //        }
    if (type.equals("OP")) {

        formLabel = "PATIENT REGISTRATION FORM";

    } else {
        formLabel = "PATIENT ADMISSION FORM";
    }

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

        try {

            try {

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

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

                docPdf.setFooter(footer);

                docPdf.open();

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

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

                    int headerwidths[] = { 16, 16, 16, 16, 16, 16 };

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

                    com.lowagie.text.pdf.PdfPTable table2 = new com.lowagie.text.pdf.PdfPTable(2);

                    int headerwidths2[] = { 30, 70 };

                    table2.setWidths(headerwidths2);

                    table2.setWidthPercentage((100));

                    table2.getDefaultCell().setFixedHeight(50);
                    //phrase = new Phrase("", pFontHeader1);

                    //table.addCell(phrase);
                    table2.getDefaultCell().setColspan(2);
                    table2.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    Image img = Image.getInstance(com.afrisoftech.lib.CompanyLogo.getPath2Logo());
                    img.scalePercent(50);
                    // img.sc//aleAbsolute(200, 200);
                    table2.addCell(img);
                    String compName = null;
                    String District = null;
                    String Region = null;
                    String date2 = 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,region 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();
                            Region = rset2.getObject(3).toString();
                        }
                        while (rset4.next()) {
                            date2 = rset4.getObject(1).toString();
                        }
                    } catch (java.sql.SQLException ex) {
                        javax.swing.JOptionPane.showMessageDialog(new java.awt.Frame(), ex.getMessage());
                        ex.printStackTrace();
                    }
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    // table.getDefaultCell().set
                    Phrase phrase = new Phrase(compName.toUpperCase(), pFontHeader3);
                    table2.addCell(phrase);

                    table.addCell(table2); // painting the logo

                    table.setWidths(headerwidths);

                    table.setWidthPercentage((105));

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

                    table.getDefaultCell().setColspan(5);

                    phrase = new Phrase(formLabel, pFontHeader2);

                    table.addCell(phrase);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_RIGHT);
                    table.getDefaultCell().setColspan(1);
                    phrase = new Phrase("FORM: 260", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    // table.getDefaultCell().set
                    phrase = new Phrase("1. PATIENT PERSONAL DETAILS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);

                    dbObject = new com.afrisoftech.lib.DBObject();

                    phrase = new Phrase("Patient Name: " + patientName, pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Age: " + dbObject.getDBObject((Object) patientAge, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Nationality: " + dbObject.getDBObject(patientNationality, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("ID-Passport: " + dbObject.getDBObject(patientIDPassport, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Place of Birth: " + dbObject.getDBObject(placeofBirth, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Occupation: " + dbObject.getDBObject(patientOccupation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Marital Status: " + dbObject.getDBObject(maritalStatus, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Religion: " + dbObject.getDBObject(patientReligion, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Tel.: " + dbObject.getDBObject(patientTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Email.: " + dbObject.getDBObject(patientEmail, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Patient Gender.: " + dbObject.getDBObject(gender, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("2. PATIENT RESIDENCE", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Home Village: " + dbObject.getDBObject(patientVillage, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Home Location: " + dbObject.getDBObject(patientLocation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("County of Birth: " + dbObject.getDBObject(patientHomeCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(
                            "County of Residence: " + dbObject.getDBObject(patientResidenceCounty, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("3. NEXT OF KIN", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Next of Kin: " + dbObject.getDBObject(patientNOK, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Relationship: " + dbObject.getDBObject(patientRelation, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NOK Telephone: " + dbObject.getDBObject(patientNOKTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("4. CURRENT ATTENDANCE AT KNH", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Referred From: " + dbObject.getDBObject(patientReferFrom, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Appointment Dates: " + dbObject.getDBObject(date111, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Specialty Clinic: " + dbObject.getDBObject(specialtyClinic, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("5. PATIENT SOCIAL ECONOMIC HISTORY", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    if (statusNHIF != null) {
                        if (statusNHIF.contains("f")) {
                            statusNHIF = "NO";
                        } else {
                            statusNHIF = "YES";
                        }
                    } else {
                        statusNHIF = "NO";
                    }

                    phrase = new Phrase("NHIF Registered: " + dbObject.getDBObject(statusNHIF, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("NHIF No.: " + dbObject.getDBObject(NHIFNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Education Level: " + dbObject.getDBObject(educationLevel, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Employer: " + dbObject.getDBObject(patientEmployer, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Telephone: " + dbObject.getDBObject(employerTelephone, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("6. DEPOSITS AND OTHER PAYMENTS", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Amount Paid: " + dbObject.getDBObject(paidAmount, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Receipt No.: " + dbObject.getDBObject(receiptNumber, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("C-Sheet No.: " + dbObject.getDBObject(cSheetNo, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Invoice Number: " + dbObject.getDBObject(invoiceNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(4);
                    phrase = new Phrase("NHIF Claim No.: " + dbObject.getDBObject(claimNumber, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase(" ", pFontHeader);
                    // table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("7. INTERVIEWERS INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Interviewer: " + dbObject.getDBObject(interviewerName, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Date: " + dbObject.getDBObject(interviewDate, ""), pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Service Point: " + dbObject.getDBObject(servicePoint, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.LIGHT_GRAY);
                    phrase = new Phrase("8. ADMISSION INFORMATION", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(2);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase("Admission Ward: " + dbObject.getDBObject(admissionWard, ""),
                            pFontHeader);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Date: " + dbObject.getDBObject(admissionDate, ""),
                            pFontHeader2);
                    table.addCell(phrase);
                    phrase = new Phrase("Admission Type: " + dbObject.getDBObject(admissionType, ""),
                            pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

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

                    ///RTA DETAILS
                    //                            if(typeofAccident.length()>0 || modeofArrival.length()>0 ||
                    //                                    nameofPoliceOfficer.length()>0 || policeForceNO.length()>0 ||
                    //                                    policeStationAccident.length()>0 ||  dateAccident.length()>0 ||
                    //                                    nameofDriver.length()>0 || accidentVehicleNo.length()>0 ||
                    //                                    driverLicenceNo.length()>0 || driversIDNo.length()>0 ){
                    if (typeofAccident != null || modeofArrival != null || nameofPoliceOfficer != null
                            || policeForceNO != null || policeStationAccident != null || dateAccident != null
                            || nameofDriver != null || accidentVehicleNo != null || driverLicenceNo != null
                            || driversIDNo != null) {

                        table.getDefaultCell().setColspan(3);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase("RTA DETAILS : ", pFontHeader2);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(3);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(dbObject.getDBObject("Accident Date:-" + dateAccident, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Type of Accident:- " + typeofAccident, "") + ""
                                        + dbObject.getDBObject(". MODE of ARRIVAL:-" + modeofArrival, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name Of Police Officer :- " + nameofPoliceOfficer, "")
                                        + "." + "" + dbObject
                                                .getDBObject(" Police Officer Force No:-" + policeForceNO, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject(
                                        "Police Station Accident Scene :- " + policeStationAccident, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                dbObject.getDBObject("Name of Driver:- " + nameofDriver, "") + dbObject
                                        .getDBObject(". Accident Vehicle NO:-" + accidentVehicleNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                        table.getDefaultCell().setColspan(6);
                        table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                        table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                        phrase = new Phrase(
                                "Driving Licence No:- " + dbObject.getDBObject(driverLicenceNo, "")
                                        + ". Driver's ID No :-" + dbObject.getDBObject(driversIDNo, ""),
                                pFontHeader);
                        table.addCell(phrase);

                    }

                    ///RTA END

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(" ", pFontHeader1);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setBorder(PdfCell.RECTANGLE);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase(
                            " Patient Number : ".toUpperCase() + dbObject.getDBObject(patNo.toUpperCase(), ""),
                            pFontHeader2);
                    table.addCell(phrase);
                    //   phrase = new Phrase(" ", pFontHeader);
                    //   table.addCell(phrase);
                    table.getDefaultCell().setColspan(3);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    phrase = new Phrase("Unit Number : ".toUpperCase() + dbObject.getDBObject(unitNumber, ""),
                            pFontHeader3);

                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);
                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT);
                    table.getDefaultCell().setBackgroundColor(java.awt.Color.WHITE);
                    phrase = new Phrase(" ", pFontHeader);
                    table.addCell(phrase);

                    table.getDefaultCell().setColspan(6);
                    table.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER);
                    //PdfWriter writer = PdfWriter.getInstance(docPdf, new FileOutputStream(tempFile));
                    PdfContentByte cb = writer.getDirectContent();

                    Barcode128 code128 = new Barcode128();

                    System.out.println("PATIENT NO " + patNo + " NAME " + patientName);
                    code128.setCode(patNo + " " + patientName);

                    code128.setBarHeight(16);

                    code128.setTextAlignment(Element.ALIGN_LEFT);

                    docPdf.add(table);

                    docPdf.add(code128.createImageWithBarcode(cb, null, null));

                    //  docPdf.add(table);

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

    }
}

From source file:com.bcpv.webapp.displaytag.decorators.ItextTotalWrapper.java

License:Artistic License

/**
 * Writes cell border at bottom of cell.
 */
public String startRow() {
    this.table.setDefaultCellBorder(Rectangle.BOTTOM);
    return null;
}

From source file:com.krawler.esp.servlets.ExportLeavePdfServlet.java

License:Open Source License

private ByteArrayOutputStream createLeaveForm(String cname, HttpServletRequest request, Session session,
        boolean isEmm) throws JSONException, SessionExpiredException, ParseException {

    String companyid = AuthHandler.getCompanyid(request);
    Company com = (Company) session.get(Company.class, companyid);
    String from = "";
    String to = "";
    String formTitle = "Absence Leave Form";
    int i = 0;// w ww. jav a  2s .c o  m
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    DecimalFormat decfm = new DecimalFormat("#,##0.00");
    Date d2 = null;
    Date d3 = null;
    Calendar cal1 = Calendar.getInstance();
    Calendar cal2 = Calendar.getInstance();
    String month = "";
    int days = 0;
    boolean showborder = true;
    if (!StringUtil.isNullOrEmpty(request.getParameter("showborder"))) {
        showborder = Boolean.parseBoolean(request.getParameter("showborder"));
    }
    SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
    String stDate = request.getParameter("stdate").replace("/", "-");
    String endDate = request.getParameter("enddate").replace("/", "-");
    d2 = sdf.parse(stDate);
    d3 = sdf.parse(endDate);

    days = getWorkingDays(request, session, companyid);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;
    try {

        String empname = "";
        String design = "";
        String historyid = "";
        String net = "";
        String name = "";
        String wtot = "";
        String dtot = "";
        String ttot = "";
        Date generatedOn = null;
        DateFormat monthformat = new SimpleDateFormat("MMMM");
        DateFormat monthformat2 = new SimpleDateFormat("MMMM dd yyyy");
        Query query = null;

        //            if (request.getParameter("flagpdf").equals("datewise")) {
        //                query = session.createQuery("from masterDB.Payhistory t where t.userID.userID=:empid and t.paymonth=:month");
        //                query.setString("empid", request.getParameter("empid"));
        //                query.setString("month", month);
        //            }
        //            if (request.getParameter("flagpdf").equals("monthwise")) {
        //                month = request.getParameter("month");
        //                query = session.createQuery("from masterDB.Payhistory t where t.userID.userID=:empid and t.paymonth=:month");
        //                query.setString("empid", request.getParameter("empid"));
        //                query.setString("month", request.getParameter("month"));
        //            }
        query = session.createQuery(
                "from masterDB.Payhistory t where t.userID.userID=:empid and t.paycyclestart=:paycyclestart and t.paycycleend=:paycycleend");
        query.setString("empid", request.getParameter("empid"));
        query.setDate("paycyclestart", d2);
        query.setDate("paycycleend", d3);

        String currSymbol = "";
        String curid = AuthHandler.getCurrencyID(request);
        Query queryx = session.createQuery("from KWLCurrency where currencyID=:curid");
        queryx.setString("curid", curid);
        KWLCurrency curncy = (KWLCurrency) queryx.uniqueResult();
        String currsym = curncy.getHtmlcode();
        String currname = curncy.getName();
        try {
            char a1 = (char) Integer.parseInt(currsym, 16);
            currSymbol = Character.toString(a1);
        } catch (Exception e) {
            currSymbol = currsym;
        }

        List lst = (List) query.list();
        if (lst.size() == 0) {
            throw new Exception("Exception occured");
        }
        if (lst.size() > 0) {
            masterDB.Payhistory wage = (masterDB.Payhistory) lst.get(0);
            empname = wage.getName();
            design = wage.getDesign();
            historyid = wage.getHistoryid();
            net = String.format("%.2f", Float.valueOf(wage.getNet().trim()).floatValue());
            name = wage.getName();
            wtot = wage.getWagetot();
            ttot = wage.getTaxtot();
            dtot = wage.getDeductot();
            double unpaidleaves = wage.getUnpaidleaves();
            generatedOn = wage.getGeneratedon();
            String gen = monthformat2.format(generatedOn);
            String startdate = monthformat2.format(wage.getCreatedon());
            String enddate = monthformat2.format(wage.getCreatedfor());

            Document document = new Document(PageSize.A4, 15, 15, 15, 15);
            writer = PdfWriter.getInstance(document, baos);
            writer.setPageEvent(new EndPage(request));
            document.open();

            String userid = request.getParameter("empid");

            query = session.createQuery("from com.krawler.common.admin.User as t where t.userID=:empid ");
            query.setString("empid", userid);
            lst = (List) query.list();
            com.krawler.common.admin.User userinfo = (com.krawler.common.admin.User) lst.get(0);
            Useraccount ua = (Useraccount) session.get(Useraccount.class, userinfo.getUserID());
            String uname = userinfo.getLastName() != null ? userinfo.getLastName() : "";
            String empid = "";
            if (ua.getEmployeeIdFormat() == null) {
                empid = ua.getEmployeeid() == null ? ""
                        : hrmsManager.getEmpidFormatEdit(session, request, ua.getEmployeeid());
            } else {
                HashMap<String, Object> requestParams = new HashMap<String, Object>();
                requestParams.put("standardEmpId",
                        hrmsManager.getEmpidFormatEdit(session, request, ua.getEmployeeid()));
                requestParams.put("employeeIdFormat", ua.getEmployeeIdFormat());
                empid = hrmsManager.getNewEmployeeIdFormat(requestParams);
            }

            String department = wage.getDepartment();
            String designation = getUserDesignation(ua);
            String bankacc = ua.getAccno() != null ? ua.getAccno() : "";
            Empprofile empprof = null;
            String epf = "";
            String dateofjoin = "";
            try {
                empprof = (Empprofile) session.get(Empprofile.class, userid);
                epf = StringUtil.isNullOrEmpty(empprof.getPfno()) ? "" : empprof.getPfno();
                dateofjoin = empprof.getJoindate() != null ? empprof.getJoindate().toString() : "";
            } catch (Exception ex) {
                epf = "";
            }
            PdfPTable mainTable = new PdfPTable(1);
            mainTable.setWidthPercentage(100);
            PdfPTable table1 = new PdfPTable(3);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 40, 40, 20 });
            PdfPTable userTable1 = new PdfPTable(1);
            imgPath = "images/logo1.gif";
            String cmpid = AuthHandler.getCompanyid(request);
            ServletContext sc = getServletContext();
            userTable1.setHorizontalAlignment(Element.ALIGN_MIDDLE);
            userTable1.setWidthPercentage(10);
            PdfPCell cell11 = null;

            PdfPCell cell1x = new PdfPCell(new Paragraph("  ", fontMediumBold));
            cell1x.setBorder(0);
            userTable1.addCell(cell1x);
            try {
                Image img = Image.getInstance(StorageHandler.GetProfileImgStorePath() + cmpid + ".png");
                cell11 = new PdfPCell(img);
                cell11.setPaddingLeft(5);
            } catch (Exception e) {
                cell11 = new PdfPCell(new Paragraph(AuthHandler.getCompanyName(request), fontTblLargeBold));
                cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            if (cell11 != null) {
                cell11.setBorder(0);
                userTable1.addCell(cell11);
            }

            PdfPCell cell1 = new PdfPCell(new Paragraph("", fontMediumBold));
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell1.setBorder(0);
            userTable1.addCell(cell1);

            PdfPTable userTable2 = new PdfPTable(1);
            userTable2.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(new Paragraph(com.getCompanyName(), fontMediumBold));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setPaddingTop(15);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(com.getCity(), fontSmallRegular));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(com.getAddress(), fontSmallRegular));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(com.getState(), fontSmallRegular));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(com.getZipCode(), fontSmallRegular));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.payslip.period.params",
                    new Object[] { request.getParameter("stdate"), request.getParameter("enddate") },
                    RequestContextUtils.getLocale(request)), fontSmallBold));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);

            PdfPTable userTable3 = new PdfPTable(1);
            userTable3.setWidthPercentage(100);
            PdfPCell cell2 = new PdfPCell(new Paragraph("", fontSmallBold));
            cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2.setBorder(0);
            userTable1.addCell(cell2);

            PdfPCell mainCell11 = new PdfPCell(userTable1);
            if (!showborder) {
                mainCell11.setBorder(0);
            } else {
                mainCell11.setBorder(Rectangle.LEFT);
            }

            table1.addCell(mainCell11);
            PdfPCell mainCell13 = new PdfPCell(userTable2);
            mainCell13.setBorder(0);
            table1.addCell(mainCell13);
            PdfPCell mainCell15 = new PdfPCell(userTable3);
            if (!showborder) {
                mainCell15.setBorder(0);
            } else {
                mainCell15.setBorder(Rectangle.RIGHT);
            }
            table1.addCell(mainCell15);

            PdfPCell mainCell12 = new PdfPCell(new Paragraph(""));
            if (!showborder) {
                mainCell12.setBorder(0);
            } else {
                mainCell12.setBorder(Rectangle.LEFT);
            }
            table1.addCell(mainCell12);
            PdfPCell mainCell14 = new PdfPCell(new Paragraph(""));
            mainCell14.setBorder(0);
            table1.addCell(mainCell14);
            PdfPCell mainCell16 = new PdfPCell(new Paragraph(""));
            if (!showborder) {
                mainCell16.setBorder(0);
            } else {
                mainCell16.setBorder(Rectangle.RIGHT);
            }
            table1.addCell(mainCell16);

            PdfPCell mainCell1 = new PdfPCell(table1);
            if (!showborder) {
                mainCell1.setBorder(0);
            } else {
                mainCell1.setBorder(1);
            }
            mainTable.addCell(mainCell1);
            // __________________________________________________________________________
            PdfPTable table2 = new PdfPTable(4);
            table2.setWidthPercentage(100);
            table2.setWidths(new float[] { 20, 30, 20, 30 });

            PdfPCell h11 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.employee.code",
                    null, RequestContextUtils.getLocale(request)), fontSmallBold));
            h11.setHorizontalAlignment(Element.ALIGN_LEFT);
            h11.setPadding(5);
            if (!showborder) {
                h11.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h11);
            PdfPCell h12 = new PdfPCell(new Paragraph("" + empid, fontSmallRegular));
            h12.setHorizontalAlignment(Element.ALIGN_LEFT);
            h12.setPadding(5);
            if (!showborder) {
                h12.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h12);
            PdfPCell h13 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.employee.name",
                    null, RequestContextUtils.getLocale(request)), fontSmallBold));
            h13.setHorizontalAlignment(Element.ALIGN_LEFT);
            h13.setPadding(5);
            if (!showborder) {
                h13.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h13);
            PdfPCell h14 = new PdfPCell(new Paragraph(userinfo.getFirstName() + " " + uname, fontSmallRegular));
            h14.setHorizontalAlignment(Element.ALIGN_LEFT);
            h14.setPadding(5);
            if (!showborder) {
                h14.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h14);

            PdfPCell h21 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.department", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            h21.setHorizontalAlignment(Element.ALIGN_LEFT);
            h21.setPadding(5);
            if (!showborder) {
                h21.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h21);
            PdfPCell h22 = new PdfPCell(new Paragraph(department, fontSmallRegular));
            h22.setHorizontalAlignment(Element.ALIGN_LEFT);
            h22.setPadding(5);
            if (!showborder) {
                h22.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h22);
            PdfPCell h33 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.designation", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            h33.setHorizontalAlignment(Element.ALIGN_LEFT);
            h33.setPadding(5);
            if (!showborder) {
                h33.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h33);
            PdfPCell h34 = new PdfPCell(new Paragraph(designation, fontSmallRegular));
            h34.setHorizontalAlignment(Element.ALIGN_LEFT);
            h34.setPadding(5);
            if (!showborder) {
                h34.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h34);
            PdfPCell h43 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.bank.ac.no", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            h43.setHorizontalAlignment(Element.ALIGN_LEFT);
            h43.setPadding(5);
            if (!showborder) {
                h43.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h43);
            PdfPCell h44 = new PdfPCell(new Paragraph(bankacc, fontSmallRegular));
            h44.setHorizontalAlignment(Element.ALIGN_LEFT);
            h44.setPadding(5);
            if (!showborder) {
                h44.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h44);
            PdfPCell h61 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.working.days", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            h61.setHorizontalAlignment(Element.ALIGN_LEFT);
            h61.setPadding(5);
            if (!showborder) {
                h61.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h61);
            PdfPCell h62 = new PdfPCell(new Paragraph(String.valueOf(days), fontSmallRegular));
            h62.setHorizontalAlignment(Element.ALIGN_LEFT);
            h62.setPadding(5);
            if (!showborder) {
                h62.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h62);
            PdfPCell h63 = new PdfPCell(new Paragraph(
                    messageSource.getMessage("hrms.common.e.p.f", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold));
            h63.setHorizontalAlignment(Element.ALIGN_LEFT);
            h63.setPadding(5);
            if (!showborder) {
                h63.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h63);
            PdfPCell h64 = new PdfPCell(new Paragraph(epf, fontSmallRegular));
            h64.setHorizontalAlignment(Element.ALIGN_LEFT);
            h64.setPadding(5);
            if (!showborder) {
                h64.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h64);
            PdfPCell h65 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.common.DateofJoining",
                    null, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            h65.setHorizontalAlignment(Element.ALIGN_LEFT);
            h65.setPadding(5);
            if (!showborder) {
                h65.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h65);
            PdfPCell h66 = new PdfPCell(new Paragraph(dateofjoin, fontSmallRegular));
            h66.setHorizontalAlignment(Element.ALIGN_LEFT);
            h66.setPadding(5);
            if (!showborder) {
                h66.setBorder(0);
            }
            //                else{
            //                    mainCell1.setBorder(1);
            //                }
            table2.addCell(h66);

            for (int y = 0; y < 2; y++) {
                PdfPCell h71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    h71.setBorder(0);
                } else {
                    h71.setBorder(Rectangle.LEFT);
                }
                table2.addCell(h71);
                for (i = 0; i < 2; i++) {
                    h71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                    h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                    h71.setBorder(0);
                    table2.addCell(h71);
                }
                h71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    h71.setBorder(0);
                } else {
                    h71.setBorder(Rectangle.RIGHT);
                }
                table2.addCell(h71);
            }
            PdfPCell mainCell2 = new PdfPCell(table2);
            if (!showborder) {
                mainCell2.setBorder(0);
            } else {
                mainCell2.setBorder(1);
            }
            mainTable.addCell(mainCell2);

            PdfPTable table3main = new PdfPTable(1);
            table3main.setWidthPercentage(100);
            PdfPTable table7main = new PdfPTable(1);
            table7main.setWidthPercentage(100);

            PdfPTable table31 = new PdfPTable(4);
            table31.setWidthPercentage(100);
            //table31.setWidths(new float[]{20,15,15,20,15,15});
            table31.setWidths(new float[] { 30, 20, 30, 20 });
            PdfPTable table41 = new PdfPTable(2);
            table41.setWidthPercentage(100);
            //table31.setWidths(new float[]{20,15,15,20,15,15});
            table41.setWidths(new float[] { 50, 50 });

            //***************************************************************************************************************
            PdfPCell s11 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.Earnings", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s11.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s11.setBorder(0);
            } else {
                s11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            s11.setPadding(5);
            table31.addCell(s11);
            PdfPCell s12 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.amount.params",
                    new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s12.setHorizontalAlignment(Element.ALIGN_RIGHT);
            s12.setPadding(5);
            if (!showborder) {
                s12.setBorder(0);
            } else {
                s12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            table31.addCell(s12);
            //                PdfPCell s13 = new PdfPCell(new Paragraph("Year to Date", fontTblMediumBold));
            //                s13.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //                s13.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            //                s13.setPadding(5);
            //                table31.addCell(s13);
            PdfPCell s14 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.Deduction", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s14.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s14.setBorder(0);
            } else {
                s14.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            s14.setPadding(5);
            table31.addCell(s14);
            PdfPCell s15 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.amount.params",
                    new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s15.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s15.setBorder(0);
            } else {
                s15.setBorder(Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM);
            }
            s15.setPadding(5);
            table31.addCell(s15);
            //                PdfPCell s16 = new PdfPCell(new Paragraph("Year to Date", fontTblMediumBold));
            //                s16.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //                s16.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.BOTTOM);
            //                s16.setPadding(5);
            //                table31.addCell(s16);
            int Wcount = 0;
            float taxtotal = 0;

            Query queryw = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.userID=:userid and createdfor >=:stdate and createdfor <=:enddate and t.type =:type");
            Query basicquery1 = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name and t.type=:type ");
            basicquery1.setString("historyid", historyid);
            basicquery1.setString("name", "Wages");
            basicquery1.setString("type", "Basic");
            List lst1 = (List) basicquery1.list();
            Query query1 = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name and t.type<>:type order by t.amount");
            query1.setString("historyid", historyid);
            query1.setString("name", "Wages");
            query1.setString("type", "Basic");
            lst1.addAll((List) query1.list());

            Query query2 = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount");
            query2.setString("historyid", historyid);
            query2.setString("name", "Taxes");
            List lst2 = (List) query2.list();

            CompanyPreferences comp = (CompanyPreferences) session.get(CompanyPreferences.class, cmpid);
            int financialMonth = comp.getFinancialmonth();
            Calendar c1 = Calendar.getInstance();
            c1.setTime(d3);
            c1.set(Calendar.MONTH, financialMonth);
            c1.set(Calendar.DATE, 1);
            Date d = c1.getTime();
            Date DOJ = new java.util.Date(empprof.getJoindate().getTime());
            if (d3.before(d)) {
                int currentYear = c1.get(Calendar.YEAR) - 1;
                c1.set(Calendar.YEAR, currentYear);
                d = c1.getTime();
            }
            if (DOJ.after(d)) {
                c1.setTime(DOJ);
                c1.set(Calendar.DATE, 1);
                d = c1.getTime();
            }
            Query query3 = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount");
            query3.setString("historyid", historyid);
            query3.setString("name", "Deduction");
            List lst3 = (List) query3.list();
            int size = lst1.size() > (lst2.size() + lst3.size()) ? lst1.size() : lst2.size() + lst3.size();
            float wagetotal = 0;
            double totalYTDEarning = 0, totalYTDDeduction = 0;
            for (i = 0; i < size; i++) {
                masterDB.Historydetail hd = null;
                if (i < lst1.size()) {
                    hd = (masterDB.Historydetail) lst1.get(i);
                    PdfPCell s21 = new PdfPCell(new Paragraph(hd.getType(), fontSmallRegular));
                    s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                    if (!showborder) {
                        s21.setBorder(0);
                    } else {
                        s21.setBorder(Rectangle.LEFT);
                    }
                    s21.setPadding(5);
                    table31.addCell(s21);

                    BigDecimal bd = new BigDecimal(hd.getAmount());
                    bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                    double newamount = bd.doubleValue();

                    PdfPCell s22 = new PdfPCell(
                            new Paragraph(String.valueOf(decfm.format(newamount)), fontSmallRegular));
                    s22.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    if (!showborder) {
                        s22.setBorder(0);
                    } else {
                        s22.setBorder(Rectangle.LEFT);
                    }
                    s22.setPadding(5);
                    table31.addCell(s22);

                    queryw.setString("userid", request.getParameter("empid"));
                    queryw.setTimestamp("stdate", d);
                    queryw.setTimestamp("enddate", d3);
                    queryw.setString("type", hd.getType());
                    List lstw = (List) queryw.list();
                    double wageAmt = 0;
                    masterDB.Historydetail hd1 = null;
                    for (int y = 0; y < lstw.size(); y++) {
                        hd1 = (masterDB.Historydetail) lstw.get(y);
                        wageAmt += Double.parseDouble(hd1.getAmount());
                    }
                    //                        PdfPCell s23 = new PdfPCell(new Paragraph(String.valueOf(decfm.format(wageAmt)), fontSmallRegular));
                    //                        s23.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    //                        s23.setBorder(Rectangle.LEFT);
                    //                        s23.setPadding(5);
                    //                        table31.addCell(s23);
                    wagetotal = wagetotal + Float.parseFloat(hd.getAmount());
                    totalYTDEarning = totalYTDEarning + wageAmt;
                    Wcount++;
                } else {
                    for (int j = 0; j < 2; j++) {
                        PdfPCell s21 = new PdfPCell(new Paragraph("", fontSmallRegular));
                        s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                        if (!showborder) {
                            s21.setBorder(0);
                        } else {
                            s21.setBorder(Rectangle.LEFT);
                        }
                        s21.setPadding(5);
                        table31.addCell(s21);
                    }
                }
                if (i < lst2.size()) {
                    hd = (masterDB.Historydetail) lst2.get(i);
                    PdfPCell s24 = new PdfPCell(new Paragraph(hd.getType(), fontSmallRegular));
                    s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                    if (!showborder) {
                        s24.setBorder(0);
                    } else {
                        s24.setBorder(Rectangle.LEFT);
                    }
                    s24.setPadding(5);
                    table31.addCell(s24);

                    BigDecimal bd = new BigDecimal(hd.getAmount());
                    bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                    double newamount = bd.doubleValue();

                    PdfPCell s25 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
                    s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    if (!showborder) {
                        s25.setBorder(0);
                    } else {
                        s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                    }
                    s25.setPadding(5);
                    table31.addCell(s25);

                    queryw.setString("userid", request.getParameter("empid"));
                    queryw.setTimestamp("stdate", d);
                    queryw.setTimestamp("enddate", d3);
                    queryw.setString("type", hd.getType());
                    List lstw1 = (List) queryw.list();
                    double taxAmt = 0;
                    masterDB.Historydetail hd2 = null;
                    for (int y = 0; y < lstw1.size(); y++) {
                        hd2 = (masterDB.Historydetail) lstw1.get(y);
                        taxAmt += Double.parseDouble(hd2.getAmount());
                    }
                    //                        PdfPCell s26 = new PdfPCell(new Paragraph(decfm.format(taxAmt), fontSmallRegular));
                    //                        s26.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    //                        s26.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                    //                        s26.setPadding(5);
                    //                        table31.addCell(s26);
                    taxtotal = taxtotal + Float.parseFloat(hd.getAmount());
                    totalYTDDeduction = totalYTDDeduction + taxAmt;
                } else {
                    if (i - lst2.size() < lst3.size()) {
                        hd = (masterDB.Historydetail) lst3.get(i - lst2.size());
                        PdfPCell s24 = new PdfPCell(new Paragraph(hd.getType(), fontSmallRegular));
                        if (hd.getType().equals("Unpaid_leaves")) {
                            s24 = new PdfPCell(
                                    new Paragraph(hd.getType() + "(" + unpaidleaves + ")", fontSmallRegular));
                        }
                        s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                        if (!showborder) {
                            s24.setBorder(0);
                        } else {
                            s24.setBorder(Rectangle.LEFT);
                        }
                        s24.setPadding(5);
                        table31.addCell(s24);

                        BigDecimal bd = new BigDecimal(hd.getAmount());
                        bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                        double newamount = bd.doubleValue();

                        PdfPCell s25 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
                        s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        if (!showborder) {
                            s25.setBorder(0);
                        } else {
                            s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                            ;
                        }
                        s25.setPadding(5);
                        table31.addCell(s25);

                        queryw.setString("userid", request.getParameter("empid"));
                        queryw.setTimestamp("stdate", d);
                        queryw.setTimestamp("enddate", d3);
                        queryw.setString("type", hd.getType());
                        List lstw2 = (List) queryw.list();
                        masterDB.Historydetail hd3 = null;
                        double deductAmt = 0;
                        for (int y = 0; y < lstw2.size(); y++) {
                            hd3 = (masterDB.Historydetail) lstw2.get(y);
                            deductAmt += Double.parseDouble(hd3.getAmount());
                        }

                        //                        PdfPCell s26 = new PdfPCell(new Paragraph(decfm.format(deductAmt), fontSmallRegular));
                        //                        s26.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        //                        s26.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                        //                        s26.setPadding(5);
                        //                        table31.addCell(s26);
                        taxtotal = taxtotal + Float.parseFloat(hd.getAmount());
                        totalYTDDeduction = totalYTDDeduction + deductAmt;
                    } else {
                        //                          if(i-lst2.size()-lst3.size() < lst4.size()){
                        //                                hd = (masterDB.Historydetail) lst4.get(i-lst2.size()-lst3.size());
                        //                                PdfPCell v24 = new PdfPCell(new Paragraph(hd.getType(), fontSmallRegular));
                        //                                v24.setHorizontalAlignment(Element.ALIGN_LEFT);
                        //                                v24.setBorder(Rectangle.LEFT);
                        //                                v24.setPadding(5);
                        //                                table31.addCell(v24);
                        //
                        //                                BigDecimal bd = new BigDecimal(hd.getAmount());
                        //                                bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                        //                                double newamount = bd.doubleValue();
                        //
                        //                                PdfPCell s25 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
                        //                                s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        //                                s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);;
                        //                                s25.setPadding(5);
                        //                                table31.addCell(s25);
                        //                          }else{
                        for (int j = 0; j < 2; j++) {
                            PdfPCell s21 = new PdfPCell(new Paragraph("", fontSmallRegular));
                            s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                            if (!showborder) {
                                s21.setBorder(0);
                            } else {
                                s21.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                            }
                            s21.setPadding(5);
                            table31.addCell(s21);
                        }
                    }
                }
            }
            //                }
            PdfPCell s91 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.total.earnings",
                    null, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s91.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s91.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s91.setBorder(0);
            } else {
                s91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s91.setPadding(5);
            table31.addCell(s91);
            BigDecimal bd = new BigDecimal(String.valueOf(wagetotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            double newamount = bd.doubleValue();
            PdfPCell s92 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
            s92.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s92.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s92.setBorder(0);
            } else {
                s92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s92.setPadding(5);
            table31.addCell(s92);
            //                PdfPCell s93 = new PdfPCell(new Paragraph(decfm.format(totalYTDEarning), fontSmallRegular));
            //                s93.setHorizontalAlignment(Element.ALIGN_BASELINE);
            //                s93.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //                s93.setBorder(Rectangle.LEFT + Rectangle.TOP);
            //                s93.setPadding(5);
            //                table31.addCell(s93);
            PdfPCell s94 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.total.deductions",
                    null, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            s94.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s94.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s94.setBorder(0);
            } else {
                s94.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s94.setPadding(5);
            table31.addCell(s94);
            bd = new BigDecimal(String.valueOf(taxtotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            newamount = bd.doubleValue();
            PdfPCell s95 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
            s95.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s95.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s95.setBorder(0);
            } else {
                s95.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s95.setPadding(5);
            table31.addCell(s95);
            //                PdfPCell s96 = new PdfPCell(new Paragraph(decfm.format(totalYTDDeduction), fontSmallRegular));
            //                s96.setHorizontalAlignment(Element.ALIGN_BASELINE);
            //                s96.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //                s96.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP);
            //                s96.setPadding(5);
            //                table31.addCell(s96);

            for (int y = 0; y < 2; y++) {
                PdfPCell he71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    he71.setBorder(0);
                } else {
                    he71.setBorder(Rectangle.LEFT);
                }
                table31.addCell(he71);
                for (i = 0; i < 2; i++) {
                    he71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                    he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                    he71.setBorder(0);
                    table31.addCell(he71);
                }
                he71 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                //      he71.setBorder(Rectangle.RIGHT);
                if (!showborder) {
                    he71.setBorder(0);
                } else {
                    he71.setBorder(Rectangle.RIGHT);
                }
                table31.addCell(he71);
            }

            Query query4 = session.createQuery(
                    "from masterDB.Historydetail t where t.payhistory.historyid=:historyid and t.name=:name order by t.amount");
            query4.setString("historyid", historyid);
            query4.setString("name", "Employer Contribution");
            List lst4 = (List) query4.list();
            double ectotal = 0;
            PdfPCell ec11 = new PdfPCell(
                    new Paragraph(messageSource.getMessage("hrms.payroll.EmployerContribution", null,
                            RequestContextUtils.getLocale(request)), fontTblMediumBold));
            ec11.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                ec11.setBorder(0);
            } else {
                ec11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            ec11.setPadding(5);
            table41.addCell(ec11);
            PdfPCell ec12 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.amount.params",
                    new Object[] { currSymbol }, RequestContextUtils.getLocale(request)), fontTblMediumBold));
            ec12.setHorizontalAlignment(Element.ALIGN_RIGHT);
            ec12.setPadding(5);
            if (!showborder) {
                ec12.setBorder(0);
            } else {
                ec12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT);
            }
            table41.addCell(ec12);
            masterDB.Historydetail hd1 = null;
            for (i = 0; i < lst4.size(); i++) {
                hd1 = (masterDB.Historydetail) lst4.get(i);
                PdfPCell s24 = new PdfPCell(new Paragraph(hd1.getType(), fontSmallRegular));
                s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    s24.setBorder(0);
                } else {
                    s24.setBorder(Rectangle.LEFT);
                }
                s24.setPadding(5);
                table41.addCell(s24);
                bd = new BigDecimal(hd1.getAmount());
                bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                newamount = bd.doubleValue();
                ectotal = ectotal + newamount;

                PdfPCell s25 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
                s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                if (!showborder) {
                    s25.setBorder(0);
                } else {
                    s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                }
                s25.setPadding(5);
                table41.addCell(s25);
            }

            PdfPCell se91 = new PdfPCell(
                    new Paragraph(messageSource.getMessage("hrms.payroll.total.contribution", null,
                            RequestContextUtils.getLocale(request)), fontTblMediumBold));
            se91.setHorizontalAlignment(Element.ALIGN_BASELINE);
            se91.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                se91.setBorder(0);
            } else {
                se91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            se91.setPadding(5);
            table41.addCell(se91);
            bd = new BigDecimal(String.valueOf(ectotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            newamount = bd.doubleValue();
            PdfPCell se92 = new PdfPCell(new Paragraph(decfm.format(newamount), fontSmallRegular));
            se92.setHorizontalAlignment(Element.ALIGN_BASELINE);
            se92.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                se92.setBorder(0);
            } else {
                se92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM + Rectangle.RIGHT);
            }
            se92.setPadding(5);
            table41.addCell(se92);

            PdfPCell Cell31 = new PdfPCell(table31);
            if (!showborder) {
                Cell31.setBorder(0);
            } else {
                Cell31.setBorder(1);
            }
            table3main.addCell(Cell31);

            PdfPCell mainCell4 = new PdfPCell(table3main);
            if (!showborder) {
                mainCell4.setBorder(0);
            } else {
                mainCell4.setBorder(1);
            }
            mainTable.addCell(mainCell4);

            PdfPCell Cell41 = new PdfPCell(table41);
            if (!showborder) {
                Cell41.setBorder(0);
            } else {
                Cell41.setBorder(1);
            }
            table7main.addCell(Cell41);

            PdfPCell mainCell44 = new PdfPCell(table7main);
            if (!showborder) {
                mainCell44.setBorder(0);
            } else {
                mainCell44.setBorder(1);
            }
            mainTable.addCell(mainCell44);

            //***************************************************************************************************************

            PdfPTable table4 = new PdfPTable(2);
            table4.setWidthPercentage(100);
            for (i = 0; i < 4; i++) {
                PdfPCell i33 = new PdfPCell(new Paragraph("  ", fontTblMediumBold));
                i33.setHorizontalAlignment(Element.ALIGN_CENTER);
                if (!showborder) {
                    i33.setBorder(0);
                } else {
                    i33.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                }
                table4.addCell(i33);
            }

            PdfPCell i31 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.netpay", null,
                    RequestContextUtils.getLocale(request)) + " ", fontTblMediumBold));
            i31.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i31.setBorder(0);
            } else {
                i31.setBorder(Rectangle.LEFT + Rectangle.TOP);
            }
            i31.setPadding(5);
            table4.addCell(i31);
            double netpay = 0;
            netpay = wagetotal - taxtotal;
            netpay = Math.round(netpay);
            String amount = numberFormatter((double) netpay, currSymbol);
            //PdfPCell i33 = new PdfPCell(new Paragraph(currSymbol+String.valueOf((int)netpay+".00"), fontSmallRegular));
            PdfPCell i33 = new PdfPCell(new Paragraph(amount, fontTblMediumBold));
            //                PdfPCell i33 = new PdfPCell(new Paragraph("Rs 13,350.00", fontTblMediumBold));
            i33.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                i33.setBorder(0);
            } else {
                i31.setBorder(Rectangle.RIGHT);
            }
            i33.setPadding(5);
            table4.addCell(i33);

            PdfPCell i32 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.in.words", null,
                    RequestContextUtils.getLocale(request)), fontTblMediumBold));
            i32.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i32.setBorder(0);
            } else {
                i31.setBorder(Rectangle.LEFT);
            }
            i32.setPadding(5);
            table4.addCell(i32);
            int netpayi = (int) netpay;
            //                String netinword = EnglishNumberToWords.convert(Long.parseLong(String.valueOf(netpayi)));
            String netinword = "";//new EnglishNumberToWords(request).convert(netpay);
            PdfPCell i34 = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.only",
                    new Object[] { currname, netinword }, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold));
            i34.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i34.setBorder(0);
            } else {
                i31.setBorder(Rectangle.RIGHT);
            }
            i34.setPadding(5);
            table4.addCell(i34);

            PdfPCell mainCell5 = new PdfPCell(table4);
            if (!showborder) {
                mainCell5.setBorder(0);
            } else {
                mainCell5.setBorder(1);
            }
            mainTable.addCell(mainCell5);

            document.add(new Paragraph("\n\n"));

            PdfPTable table5 = new PdfPTable(2);
            table5.setWidthPercentage(80);
            cell = new PdfPCell(new Paragraph("___________________________"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(new Paragraph("___________________________"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.employee.signature", null,
                    RequestContextUtils.getLocale(request)), fontSmallBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(new Paragraph(messageSource.getMessage("hrms.payroll.manager.signature", null,
                    RequestContextUtils.getLocale(request)), fontSmallBold));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);

            document.add(mainTable);
            //                document.add(new Paragraph("\n\n\n\n\n\n\n\n\n\n\n\n"));
            //                document.add(table5);
            document.close();
        }

        return baos;

    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    } finally {
        writer.close();
    }

}

From source file:com.krawler.spring.exportFuctionality.ExportRecord.java

License:Open Source License

public ByteArrayOutputStream createPdf(HttpServletRequest request, String currencyid, String billid,
        DateFormat formatter, int mode, double amount, String logoPath, String customer, String accname,
        String address, boolean isExpenseInv) throws DocumentException, ServiceException, IOException {
    ByteArrayOutputStream baos = null;
    double total = 0;
    Document document = null;//  ww  w . ja v  a 2s  .co m
    PdfWriter writer = null;
    try {
        String poRefno = "";
        baos = new ByteArrayOutputStream();
        document = new Document(PageSize.A4, 15, 15, 15, 15);
        writer = PdfWriter.getInstance(document, baos);
        document.open();
        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setWidthPercentage(100);

        PdfPTable blankTable = null;
        PdfPCell blankCell = null;
        PdfPTable tab1 = null;
        PdfPTable tab2 = null;
        PdfPTable tab3 = null;
        Rectangle page = document.getPageSize();

        int bmargin = 15; //border margin
        PdfContentByte cb = writer.getDirectContent();
        cb.rectangle(bmargin, bmargin, page.getWidth() - bmargin * 2, page.getHeight() - bmargin * 2);
        cb.setColorStroke(Color.WHITE);
        cb.stroke();

        if (mode == StaticValues.AUTONUM_INVOICE || mode == StaticValues.AUTONUM_BILLINGINVOICE
                || mode == StaticValues.AUTONUM_BILLINGSALESORDER
                || mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER || mode == StaticValues.AUTONUM_SALESORDER
                || mode == StaticValues.AUTONUM_PURCHASEORDER || mode == StaticValues.AUTONUM_QUOTATION) {
            addHeaderFooter(document, writer);
            Invoice inv = null;
            BillingInvoice inv1 = null;
            BillingSalesOrder so = null;
            Company com = null;
            Account cEntry;
            String invno = "";
            Date entryDate = null;
            BillingPurchaseOrder po = null;
            SalesOrder sOrder = null;
            PurchaseOrder pOrder = null;
            Tax mainTax = null;
            Quotation quotation = null;
            if (mode == StaticValues.AUTONUM_INVOICE) {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(Invoice.class.getName(), billid);
                inv = (Invoice) cap.getEntityList().get(0);
                com = inv.getCompany();
                cEntry = inv.getCustomerEntry().getAccount();
                invno = inv.getInvoiceNumber();
                entryDate = inv.getJournalEntry().getEntryDate();
                //inv = (Invoice) session.get(Invoice.class, billid);
            } else if (mode == StaticValues.AUTONUM_BILLINGSALESORDER) {
                so = (BillingSalesOrder) kwlCommonTablesDAOObj.getClassObject(BillingSalesOrder.class.getName(),
                        billid);
                com = so.getCompany();
                cEntry = so.getCustomer().getAccount();
                invno = so.getSalesOrderNumber();
                entryDate = so.getOrderDate();
                mainTax = so.getTax();
            } else if (mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER) {
                po = (BillingPurchaseOrder) kwlCommonTablesDAOObj
                        .getClassObject(BillingPurchaseOrder.class.getName(), billid);
                com = po.getCompany();
                cEntry = po.getVendor().getAccount();
                invno = po.getPurchaseOrderNumber();
                entryDate = po.getOrderDate();
                mainTax = po.getTax();
            } else if (mode == StaticValues.AUTONUM_SALESORDER) {
                sOrder = (SalesOrder) kwlCommonTablesDAOObj.getClassObject(SalesOrder.class.getName(), billid);
                com = sOrder.getCompany();
                cEntry = sOrder.getCustomer().getAccount();
                invno = sOrder.getSalesOrderNumber();
                entryDate = sOrder.getOrderDate();
                mainTax = sOrder.getTax();

            } else if (mode == StaticValues.AUTONUM_PURCHASEORDER) {
                pOrder = (PurchaseOrder) kwlCommonTablesDAOObj.getClassObject(PurchaseOrder.class.getName(),
                        billid);
                com = pOrder.getCompany();
                cEntry = pOrder.getVendor().getAccount();
                invno = pOrder.getPurchaseOrderNumber();
                entryDate = pOrder.getOrderDate();
                mainTax = pOrder.getTax();

            } else if (mode == StaticValues.AUTONUM_QUOTATION) {
                quotation = (Quotation) kwlCommonTablesDAOObj.getClassObject(Quotation.class.getName(), billid);
                com = quotation.getCompany();
                cEntry = quotation.getCustomer().getAccount();
                invno = quotation.getquotationNumber();
                entryDate = quotation.getQuotationDate();
                mainTax = quotation.getTax();

            } else {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(BillingInvoice.class.getName(), billid);
                inv1 = (BillingInvoice) cap.getEntityList().get(0);
                com = inv1.getCompany();
                cEntry = inv1.getCustomerEntry().getAccount();
                invno = inv1.getBillingInvoiceNumber();
                entryDate = inv1.getJournalEntry().getEntryDate();
                poRefno = inv1.getPoRefNumber() == null ? "" : inv1.getPoRefNumber();
                mainTax = inv1.getTax();
                //inv1=(BillingInvoice)session.get(BillingInvoice.class,billid);
            }

            //                Company com = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getCompany() : inv1.getCompany();
            String company[] = new String[4];
            company[0] = com.getCompanyName();
            company[1] = com.getAddress();
            company[2] = com.getEmailID();
            company[3] = com.getPhoneNumber();

            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 50, 50 });

            tab1 = addCompanyLogo(logoPath, com);
            tab2 = new PdfPTable(1);
            PdfPCell invCell = null;

            CompanyAccountPreferences pref = (CompanyAccountPreferences) kwlCommonTablesDAOObj
                    .getClassObject(CompanyAccountPreferences.class.getName(), com.getCompanyID());
            Account cash = pref.getCashAccount();
            //
            //                if (mode != StaticValues.AUTONUM_BILLINGINVOICE) {
            //                    cEntry = inv.getCustomerEntry().getAccount();
            //                } else {
            //                    cEntry = inv1.getCustomerEntry().getAccount();
            //                }
            String theader = cEntry == cash
                    ? messageSource.getMessage("acc.accPref.autoCS", null,
                            RequestContextUtils.getLocale(request))
                    : messageSource.getMessage("acc.accPref.autoInvoice", null,
                            RequestContextUtils.getLocale(request));
            if (mode == StaticValues.AUTONUM_BILLINGSALESORDER || mode == StaticValues.AUTONUM_SALESORDER) {
                theader = messageSource.getMessage("acc.accPref.autoSO", null,
                        RequestContextUtils.getLocale(request));
            } else if (mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER
                    || mode == StaticValues.AUTONUM_PURCHASEORDER) {
                theader = messageSource.getMessage("acc.accPref.autoPO", null,
                        RequestContextUtils.getLocale(request));
            } else if (mode == StaticValues.AUTONUM_QUOTATION) {
                theader = messageSource.getMessage("acc.accPref.autoQN", null,
                        RequestContextUtils.getLocale(request));
            }
            invCell = createCell(theader, fontTbl, Element.ALIGN_RIGHT, 0, 5);
            tab2.addCell(invCell);

            PdfPCell cell1 = new PdfPCell(tab1);
            cell1.setBorder(0);
            table1.addCell(cell1);
            PdfPCell cel2 = new PdfPCell(tab2);
            cel2.setBorder(0);
            table1.addCell(cel2);

            PdfPCell mainCell11 = new PdfPCell(table1);
            mainCell11.setBorder(0);
            mainCell11.setPadding(10);
            mainTable.addCell(mainCell11);

            PdfPTable userTable2 = new PdfPTable(2);
            userTable2.setWidthPercentage(100);
            userTable2.setWidths(new float[] { 60, 40 });

            tab3 = getCompanyInfo(company);

            PdfPTable tab4 = new PdfPTable(2);
            tab4.setWidthPercentage(100);
            tab4.setWidths(new float[] { 50, 50 });

            PdfPCell cell2 = createCell(theader + "# :", fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
            if (mode == StaticValues.AUTONUM_QUOTATION) {
                cell2 = createCell(theader + "# :", fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
            }
            tab4.addCell(cell2);
            //                String invno = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getInvoiceNumber() : inv1.getBillingInvoiceNumber();
            cell2 = createCell(invno, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            if (mode != StaticValues.AUTONUM_QUOTATION && mode != StaticValues.AUTONUM_PURCHASEORDER
                    && mode != StaticValues.AUTONUM_SALESORDER) {
                cell2 = createCell(
                        messageSource.getMessage("acc.numb.43", null, RequestContextUtils.getLocale(request))
                                + " # :",
                        fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
                tab4.addCell(cell2);
                cell2 = createCell(poRefno, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
                tab4.addCell(cell2);
            }

            cell2 = createCell(
                    messageSource.getMessage("acc.rem.198", null, RequestContextUtils.getLocale(request))
                            + " :",
                    fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
            tab4.addCell(cell2);
            cell2 = createCell(formatter.format(entryDate), fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);

            cell1 = new PdfPCell(tab3);
            cell1.setBorder(0);
            userTable2.addCell(cell1);
            cel2 = new PdfPCell(tab4);
            cel2.setBorder(0);
            userTable2.addCell(cel2);

            PdfPCell mainCell12 = new PdfPCell(userTable2);
            mainCell12.setBorder(0);
            mainCell12.setPadding(10);
            mainTable.addCell(mainCell12);

            PdfPTable tab5 = new PdfPTable(2);
            tab5.setWidthPercentage(100);
            tab5.setWidths(new float[] { 10, 90 });
            PdfPCell cell3 = createCell(
                    messageSource.getMessage("acc.common.to", null, RequestContextUtils.getLocale(request))
                            + " , ",
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);

            HashMap<String, Object> invRequestParams = new HashMap<String, Object>();
            ArrayList filter_names = new ArrayList(), filter_params = new ArrayList(),
                    order_by = new ArrayList(), order_type = new ArrayList();
            order_by.add("srno");
            order_type.add("asc");
            invRequestParams.put("order_by", order_by);
            invRequestParams.put("order_type", order_type);
            KwlReturnObject idresult = null;

            String customerName = "";
            String shipTo = "";
            String memo = "";
            Iterator itr = null;
            if (mode == StaticValues.AUTONUM_INVOICE) {
                filter_names.add("invoice.ID");
                filter_params.add(inv.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accInvoiceDAOobj.getInvoiceDetails(invRequestParams);
                customerName = inv.getCustomer() == null ? inv.getCustomerEntry().getAccount().getName()
                        : inv.getCustomer().getName();
                shipTo = inv.getShipTo();
                itr = idresult.getEntityList().iterator();
                memo = inv.getMemo();
            } else if (mode == StaticValues.AUTONUM_BILLINGSALESORDER) {
                customerName = so.getCustomer().getName();
                shipTo = so.getCustomer().getShippingAddress();
                filter_names.add("salesOrder.ID");
                filter_params.add(so.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accSalesOrderDAOobj.getBillingSalesOrderDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = so.getMemo();
            } else if (mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER) {
                customerName = po.getVendor().getName();
                shipTo = po.getVendor().getAddress();
                filter_names.add("purchaseOrder.ID");
                filter_params.add(po.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accPurchaseOrderobj.getBillingPurchaseOrderDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = po.getMemo();
            } else if (mode == StaticValues.AUTONUM_SALESORDER) {
                customerName = sOrder.getCustomer().getName();
                shipTo = sOrder.getCustomer().getShippingAddress();
                filter_names.add("salesOrder.ID");
                filter_params.add(sOrder.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accSalesOrderDAOobj.getSalesOrderDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = sOrder.getMemo();
            } else if (mode == StaticValues.AUTONUM_PURCHASEORDER) {
                customerName = pOrder.getVendor().getName();
                shipTo = pOrder.getVendor().getAddress();
                filter_names.add("purchaseOrder.ID");
                filter_params.add(pOrder.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accPurchaseOrderobj.getPurchaseOrderDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = pOrder.getMemo();
            } else if (mode == StaticValues.AUTONUM_QUOTATION) {
                customerName = quotation.getCustomer().getName();
                shipTo = quotation.getCustomer().getShippingAddress();
                filter_names.add("quotation.ID");
                filter_params.add(quotation.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accSalesOrderDAOobj.getQuotationDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = quotation.getMemo();
            } else {
                filter_names.add("billingInvoice.ID");
                filter_params.add(inv1.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accInvoiceDAOobj.getBillingInvoiceDetails(invRequestParams);
                customerName = inv1.getCustomer() == null ? inv1.getCustomerEntry().getAccount().getName()
                        : inv1.getCustomer().getName();
                shipTo = inv1.getShipTo();
                itr = idresult.getEntityList().iterator();
                memo = inv1.getMemo();
            }
            cell3 = createCell(customerName, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell(shipTo, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);

            PdfPCell mainCell14 = new PdfPCell(tab5);
            mainCell14.setBorder(0);
            mainCell14.setPadding(10);
            mainTable.addCell(mainCell14);

            //                if(mode == StaticValues.AUTONUM_QUOTATION)
            //                   String[] header = {"S.No.","PRODUCT DESCRIPTION", "QUANTITY", "UNIT PRICE", "TAX", "AMOUNT"};

            String[] header = {
                    messageSource.getMessage("acc.setupWizard.sno", null,
                            RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.176", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.187", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.188", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.191", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.192", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.193", null, RequestContextUtils.getLocale(request)) };
            PdfPTable table = getBlankTable();
            PdfPCell invcell = null;
            for (int i = 0; i < header.length; i++) {
                invcell = new PdfPCell(new Paragraph(header[i], fontSmallBold));
                invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                invcell.setBackgroundColor(Color.LIGHT_GRAY);
                invCell.setBorder(0);
                invcell.setPadding(3);
                table.addCell(invcell);
            }

            addTableRow(mainTable, table); //Break table after adding header row
            table = getBlankTable();

            HashMap<String, Object> requestParams = AccountingManager.getGlobalParams(request);
            KwlReturnObject bAmt = null;
            InvoiceDetail row = null;
            BillingInvoiceDetail row1 = null;
            BillingSalesOrderDetail row3 = null;
            BillingPurchaseOrderDetail row4 = null;
            SalesOrderDetail row5 = null;
            PurchaseOrderDetail row6 = null;
            QuotationDetail row7 = null;
            int index = 0;
            while (itr.hasNext()) {
                String prodName = "";
                double quantity = 0, discountQuotation = 0;
                double rate = 0;
                Discount discount = null;
                String uom = "";
                double amount1 = 0;
                if (mode == StaticValues.AUTONUM_INVOICE) {
                    row = (InvoiceDetail) itr.next();
                    prodName = row.getInventory().getProduct().getName();
                    quantity = row.getInventory().getQuantity();
                    rate = row.getRate();
                    discount = row.getDiscount();
                    uom = row.getInventory().getProduct().getUnitOfMeasure() == null ? ""
                            : row.getInventory().getProduct().getUnitOfMeasure().getName();
                } else if (mode == StaticValues.AUTONUM_BILLINGSALESORDER) {
                    row3 = (BillingSalesOrderDetail) itr.next();
                    prodName = row3.getProductDetail();
                    quantity = row3.getQuantity();
                    rate = row3.getRate();
                } else if (mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER) {
                    row4 = (BillingPurchaseOrderDetail) itr.next();
                    prodName = row4.getProductDetail();
                    quantity = row4.getQuantity();
                    rate = row4.getRate();
                } else if (mode == StaticValues.AUTONUM_SALESORDER) {
                    row5 = (SalesOrderDetail) itr.next();
                    prodName = row5.getProduct().getName();
                    quantity = row5.getQuantity();
                    rate = row5.getRate();
                    uom = row5.getProduct().getUnitOfMeasure() == null ? ""
                            : row5.getProduct().getUnitOfMeasure().getName();
                } else if (mode == StaticValues.AUTONUM_PURCHASEORDER) {
                    row6 = (PurchaseOrderDetail) itr.next();
                    prodName = row6.getProduct().getName();
                    quantity = row6.getQuantity();
                    rate = row6.getRate();
                    uom = row6.getProduct().getUnitOfMeasure() == null ? ""
                            : row6.getProduct().getUnitOfMeasure().getName();
                } else if (mode == StaticValues.AUTONUM_QUOTATION) {
                    row7 = (QuotationDetail) itr.next();
                    prodName = row7.getProduct().getName();
                    quantity = row7.getQuantity();
                    rate = row7.getRate();
                    discountQuotation = rate * quantity * row7.getDiscount() / 100;
                    uom = row7.getProduct().getUnitOfMeasure() == null ? ""
                            : row7.getProduct().getUnitOfMeasure().getName();
                } else {
                    row1 = (BillingInvoiceDetail) itr.next();
                    prodName = row1.getProductDetail();
                    quantity = row1.getQuantity();
                    rate = row1.getRate();
                    discount = row1.getDiscount() != null ? row1.getDiscount() : null;
                    //                        uom = row1.getInventory().getProduct().getUnitOfMeasure()==null?"":row1.getInventory().getProduct().getUnitOfMeasure().getName();
                }
                invcell = createCell((++index) + ".", fontSmallRegular, Element.ALIGN_RIGHT,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                invcell = createCell(prodName, fontSmallRegular, Element.ALIGN_LEFT,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);

                String qtyStr = Double.toString(quantity);
                if (mode == StaticValues.AUTONUM_INVOICE || mode == StaticValues.AUTONUM_SALESORDER
                        || mode == StaticValues.AUTONUM_PURCHASEORDER
                        || mode == StaticValues.AUTONUM_QUOTATION) {
                    qtyStr = Integer.toString((int) quantity); //For with-Inventory flow, Don't show decimal point as inventory has integer value
                }
                invcell = createCell(qtyStr + " " + uom, fontSmallRegular, Element.ALIGN_CENTER,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                if (mode == StaticValues.AUTONUM_PURCHASEORDER || mode == StaticValues.AUTONUM_SALESORDER
                        || mode == StaticValues.AUTONUM_QUOTATION) {
                    bAmt = accCurrencyobj.getBaseToCurrencyAmount(requestParams, rate,
                            cEntry.getCurrency().getCurrencyID(), entryDate, 0);
                    double rateInBase = (Double) bAmt.getEntityList().get(0);
                    rate = rateInBase;
                }
                invcell = createCell(authHandlerDAOObj.getFormattedCurrency(rate, currencyid), fontSmallRegular,
                        Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                if (mode == StaticValues.AUTONUM_QUOTATION)
                    invcell = calculateDiscount(discountQuotation, currencyid);
                else
                    invcell = calculateDiscount(discount, currencyid);
                invcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                invcell.setPadding(5);
                invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                table.addCell(invcell);

                amount1 = rate * quantity;
                if (discount != null) {
                    amount1 -= mode != StaticValues.AUTONUM_BILLINGINVOICE
                            ? (row.getDiscount().getDiscountValue())
                            : (row1.getDiscount().getDiscountValue());
                }
                if (discountQuotation != 0) {
                    amount1 -= discountQuotation;
                }
                double rowTaxPercent = 0;
                if (row != null && row.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row1 != null && row1.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row1.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row3 != null && row3.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row3.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row4 != null && row4.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row4.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row5 != null && row5.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row5.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row6 != null && row6.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row6.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                } else if (row7 != null && row7.getTax() != null) {
                    requestParams.put("transactiondate", entryDate);
                    requestParams.put("taxid", row7.getTax().getID());
                    KwlReturnObject result = accTaxObj.getTax(requestParams);
                    List taxList = result.getEntityList();
                    Object[] taxObj = (Object[]) taxList.get(0);
                    rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                }
                invcell = createCell(
                        authHandlerDAOObj.getFormattedCurrency(amount1 * rowTaxPercent / 100, currencyid),
                        fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                amount1 += amount1 * rowTaxPercent / 100;
                invcell = createCell(authHandlerDAOObj.getFormattedCurrency(amount1, currencyid),
                        fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                total += amount1;

                addTableRow(mainTable, table); //Break table after adding detail's row
                table = getBlankTable();
            }
            for (int j = 0; j < 98; j++) {
                invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                table.addCell(invcell);
            }
            addTableRow(mainTable, table); //Break table after adding extra space
            table = getBlankTable();
            //                for (int i = 0; i < 5; i++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setBorder(Rectangle.TOP);
            //                    table.addCell(invcell);
            //                }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.194", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_RIGHT, Rectangle.TOP, 5);
            cell3.setColspan(6);
            table.addCell(cell3);
            //                if(mode == StaticValues.AUTONUM_INVOICE || mode==StaticValues.AUTONUM_PURCHASEORDER || mode==StaticValues.AUTONUM_SALESORDER){
            //                    bAmt = accCurrencyobj.getBaseToCurrencyAmount(requestParams, total, cEntry.getCurrency().getCurrencyID(), entryDate, 0);
            //                    double baseTotalAmount = (Double) bAmt.getEntityList().get(0);
            //                    total = baseTotalAmount;
            //                }
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(total, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);
            //                for (int i = 0; i < 5; i++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setPadding(5);
            //                    invcell.setBorder(0);
            //                    table.addCell(invcell);
            //                }
            Discount totalDiscount = null;
            double totaltax = 0, discountTotalQuotation = 0;
            double totalAmount = 0;
            double taxPercent = 0;
            if (mainTax != null) { //Get tax percent
                requestParams.put("transactiondate", entryDate);
                requestParams.put("taxid", mainTax.getID());
                KwlReturnObject result = accTaxObj.getTax(requestParams);
                List taxList = result.getEntityList();
                Object[] taxObj = (Object[]) taxList.get(0);
                taxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
            }

            if (mode == StaticValues.AUTONUM_INVOICE) {
                totalDiscount = inv.getDiscount();
                totaltax = inv.getTaxEntry() != null ? inv.getTaxEntry().getAmount() : 0;
                totalAmount = inv.getCustomerEntry().getAmount();
            } else if (mode == StaticValues.AUTONUM_BILLINGSALESORDER
                    || mode == StaticValues.AUTONUM_BILLINGPURCHASEORDER
                    || mode == StaticValues.AUTONUM_PURCHASEORDER || mode == StaticValues.AUTONUM_SALESORDER
                    || mode == StaticValues.AUTONUM_QUOTATION) {
                totalAmount = total;
                if (mode == StaticValues.AUTONUM_QUOTATION && quotation.getDiscount() != 0) {
                    if (!quotation.isPerDiscount()) {
                        discountTotalQuotation = quotation.getDiscount();
                        total = total - quotation.getDiscount();
                        totalAmount = total;
                    } else {
                        discountTotalQuotation = total * quotation.getDiscount() / 100;
                        total -= (total * quotation.getDiscount() / 100);
                        totalAmount = total;
                    }
                }
                totaltax = (taxPercent == 0 ? 0 : totalAmount * taxPercent / 100);
                totalAmount = total + totaltax;
            } else {
                totalDiscount = inv1.getDiscount();
                totaltax = inv1.getTaxEntry() != null ? inv1.getTaxEntry().getAmount() : 0;
                totalAmount = (inv1.getCustomerEntry().getAmount());
            }
            if (mode != StaticValues.AUTONUM_PURCHASEORDER || mode != StaticValues.AUTONUM_SALESORDER) {
                cell3 = createCell(
                        messageSource.getMessage("acc.rem.195", null, RequestContextUtils.getLocale(request)),
                        fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
                cell3.setColspan(6);
                table.addCell(cell3);
                if (mode == StaticValues.AUTONUM_QUOTATION)
                    invcell = calculateDiscount(discountTotalQuotation, currencyid);
                else
                    invcell = calculateDiscount(totalDiscount, currencyid);
                invcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                invcell.setPadding(5);
                table.addCell(invcell);
            }
            //                for (int i = 0; i < 5; i++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setPadding(5);
            //                    invcell.setBorder(0);
            //                    table.addCell(invcell);
            //                }
            StringBuffer taxNameStr = new StringBuffer();
            if (mainTax != null) {
                taxNameStr.append(mainTax.getName());
                taxNameStr.append(" ");
                taxNameStr.append(taxPercent);
                taxNameStr.append("% (+)");
            } else {
                taxNameStr.append(
                        messageSource.getMessage("acc.rem.196", null, RequestContextUtils.getLocale(request)));
            }
            cell3 = createCell(taxNameStr.toString(), fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
            cell3.setColspan(6);
            table.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(totaltax, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);
            //                for (int i = 0; i < 5; i++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setPadding(5);
            //                    invcell.setBorder(0);
            //                    table.addCell(invcell);
            //                }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.197", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_RIGHT, 0, 5);
            cell3.setColspan(6);
            table.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(totalAmount, currencyid),
                    fontSmallRegular, Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);

            addTableRow(mainTable, table);

            KWLCurrency currency = (KWLCurrency) kwlCommonTablesDAOObj
                    .getClassObject(KWLCurrency.class.getName(), currencyid);
            String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(totalAmount)),
                    currency);
            String currencyname = currency.getName();
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.177", null, RequestContextUtils.getLocale(request))
                            + " : " + currencyname + " " + netinword + " Only.",
                    fontSmallRegular, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5);
            PdfPTable table2 = new PdfPTable(1);
            table2.addCell(cell3);
            PdfPCell mainCell62 = new PdfPCell(table2);
            mainCell62.setBorder(0);
            mainCell62.setPadding(10);
            mainTable.addCell(mainCell62);
            PdfPTable helpTable = new PdfPTable(new float[] { 8, 92 });
            helpTable.setWidthPercentage(100);
            Phrase phrase1 = new Phrase(
                    messageSource.getMessage("acc.common.memo", null, RequestContextUtils.getLocale(request))
                            + ":  ",
                    fontSmallBold);
            Phrase phrase2 = new Phrase(memo, fontSmallRegular);
            PdfPCell pcell1 = new PdfPCell(phrase1);
            PdfPCell pcell2 = new PdfPCell(phrase2);
            pcell1.setBorder(0);
            pcell1.setPadding(10);
            pcell1.setPaddingRight(0);
            pcell2.setBorder(0);
            pcell2.setPadding(10);
            helpTable.addCell(pcell1);
            helpTable.addCell(pcell2);

            PdfPCell mainCell61 = new PdfPCell(helpTable);
            mainCell61.setBorder(0);
            mainTable.addCell(mainCell61);

        } else if (mode == StaticValues.AUTONUM_DEBITNOTE || mode == StaticValues.AUTONUM_CREDITNOTE
                || mode == StaticValues.AUTONUM_BILLINGCREDITNOTE
                || mode == StaticValues.AUTONUM_BILLINGDEBITNOTE) {
            addHeaderFooter(document, writer);

            CreditNote creNote = null;
            DebitNote dbNote = null;
            BillingCreditNote biCreNote = null;
            BillingDebitNote biDeNote = null;
            Company com = null;
            Account cEntry = null;
            String invno = "";
            Date entryDate = null;
            Customer customerObj = null;
            Vendor vendorObj = null;
            double taxMain = 0;

            if (mode == StaticValues.AUTONUM_BILLINGCREDITNOTE) {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(BillingCreditNote.class.getName(),
                        billid);
                biCreNote = (BillingCreditNote) cap.getEntityList().get(0);
                Set<JournalEntryDetail> entryset = biCreNote.getJournalEntry().getDetails();
                customerObj = new Customer();
                Iterator itr = entryset.iterator();
                while (itr.hasNext()) {
                    cEntry = ((JournalEntryDetail) itr.next()).getAccount();
                    //                    customer=(Customer)session.get(Customer.class,acc.getID());
                    customerObj = (Customer) kwlCommonTablesDAOObj.getClassObject(Customer.class.getName(),
                            cEntry.getID());
                    if (customerObj != null)
                        break;
                }
                com = biCreNote.getCompany();
                invno = biCreNote.getCreditNoteNumber();
                entryDate = biCreNote.getJournalEntry().getEntryDate();
            } else if (mode == StaticValues.AUTONUM_BILLINGDEBITNOTE) {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(BillingDebitNote.class.getName(), billid);
                biDeNote = (BillingDebitNote) cap.getEntityList().get(0);
                //                    dbNote = (BillingDebitNote) kwlCommonTablesDAOObj.getClassObject(BillingDebitNote.class.getName(), billid);
                com = biDeNote.getCompany();
                Set<JournalEntryDetail> entryset = biDeNote.getJournalEntry().getDetails();
                vendorObj = new Vendor();
                Iterator itr = entryset.iterator();
                while (itr.hasNext()) {
                    cEntry = ((JournalEntryDetail) itr.next()).getAccount();
                    //                    vendor=(Vendor)session.get(Vendor.class,acc.getID());
                    vendorObj = (Vendor) kwlCommonTablesDAOObj.getClassObject(Vendor.class.getName(),
                            cEntry.getID());
                    if (vendorObj != null)
                        break;
                }
                invno = biDeNote.getDebitNoteNumber();
                entryDate = biDeNote.getJournalEntry().getEntryDate();
            }
            if (mode == StaticValues.AUTONUM_CREDITNOTE) {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(CreditNote.class.getName(), billid);
                creNote = (CreditNote) cap.getEntityList().get(0);
                Set<JournalEntryDetail> entryset = creNote.getJournalEntry().getDetails();
                customerObj = new Customer();
                Iterator itr = entryset.iterator();
                while (itr.hasNext()) {
                    cEntry = ((JournalEntryDetail) itr.next()).getAccount();
                    //                    customer=(Customer)session.get(Customer.class,acc.getID());
                    customerObj = (Customer) kwlCommonTablesDAOObj.getClassObject(Customer.class.getName(),
                            cEntry.getID());
                    if (customerObj != null)
                        break;
                }
                com = creNote.getCompany();
                invno = creNote.getCreditNoteNumber();
                entryDate = creNote.getJournalEntry().getEntryDate();
                //inv = (Invoice) session.get(Invoice.class, billid);
            } else if (mode == StaticValues.AUTONUM_DEBITNOTE) {
                KwlReturnObject cap = kwlCommonTablesDAOObj.getObject(DebitNote.class.getName(), billid);
                dbNote = (DebitNote) cap.getEntityList().get(0);
                //                    dbNote = (BillingDebitNote) kwlCommonTablesDAOObj.getClassObject(BillingDebitNote.class.getName(), billid);
                com = dbNote.getCompany();
                Set<JournalEntryDetail> entryset = dbNote.getJournalEntry().getDetails();
                vendorObj = new Vendor();
                Iterator itr = entryset.iterator();
                while (itr.hasNext()) {
                    cEntry = ((JournalEntryDetail) itr.next()).getAccount();
                    //                    vendor=(Vendor)session.get(Vendor.class,acc.getID());
                    vendorObj = (Vendor) kwlCommonTablesDAOObj.getClassObject(Vendor.class.getName(),
                            cEntry.getID());
                    if (vendorObj != null)
                        break;
                }
                invno = dbNote.getDebitNoteNumber();
                entryDate = dbNote.getJournalEntry().getEntryDate();
            }

            //                Company com = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getCompany() : inv1.getCompany();
            String company[] = new String[4];
            company[0] = com.getCompanyName();
            company[1] = com.getAddress();
            company[2] = com.getEmailID();
            company[3] = com.getPhoneNumber();

            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 50, 50 });

            tab1 = addCompanyLogo(logoPath, com);
            tab2 = new PdfPTable(1);
            PdfPCell invCell = null;

            CompanyAccountPreferences pref = (CompanyAccountPreferences) kwlCommonTablesDAOObj
                    .getClassObject(CompanyAccountPreferences.class.getName(), com.getCompanyID());
            Account cash = pref.getCashAccount();
            //
            //                if (mode != StaticValues.AUTONUM_BILLINGINVOICE) {
            //                    cEntry = inv.getCustomerEntry().getAccount();
            //                } else {
            //                    cEntry = inv1.getCustomerEntry().getAccount();
            //                }
            String theader = "";
            if (mode == StaticValues.AUTONUM_CREDITNOTE || mode == StaticValues.AUTONUM_BILLINGCREDITNOTE) {
                theader = messageSource.getMessage("acc.accPref.autoCN", null,
                        RequestContextUtils.getLocale(request));
            } else if (mode == StaticValues.AUTONUM_DEBITNOTE
                    || mode == StaticValues.AUTONUM_BILLINGDEBITNOTE) {
                theader = messageSource.getMessage("acc.accPref.autoDN", null,
                        RequestContextUtils.getLocale(request));
            }
            invCell = createCell(theader, fontTbl, Element.ALIGN_RIGHT, 0, 5);
            tab2.addCell(invCell);

            PdfPCell cell1 = new PdfPCell(tab1);
            cell1.setBorder(0);
            table1.addCell(cell1);
            PdfPCell cel2 = new PdfPCell(tab2);
            cel2.setBorder(0);
            table1.addCell(cel2);

            PdfPCell mainCell11 = new PdfPCell(table1);
            mainCell11.setBorder(0);
            mainCell11.setPadding(10);
            mainTable.addCell(mainCell11);

            PdfPTable userTable2 = new PdfPTable(2);
            userTable2.setWidthPercentage(100);
            userTable2.setWidths(new float[] { 60, 40 });

            tab3 = getCompanyInfo(company);

            PdfPTable tab4 = new PdfPTable(2);
            tab4.setWidthPercentage(100);
            tab4.setWidths(new float[] { 30, 70 });

            PdfPCell cell2 = createCell(theader + " #", fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            //                String invno = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getInvoiceNumber() : inv1.getBillingInvoiceNumber();
            cell2 = createCell(": " + invno, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            cell2 = createCell(
                    messageSource.getMessage("acc.rem.198", null, RequestContextUtils.getLocale(request)) + " ",
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            cell2 = createCell(": " + formatter.format(entryDate), fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);

            cell1 = new PdfPCell(tab3);
            cell1.setBorder(0);
            userTable2.addCell(cell1);
            cel2 = new PdfPCell(tab4);
            cel2.setBorder(0);
            userTable2.addCell(cel2);

            PdfPCell mainCell12 = new PdfPCell(userTable2);
            mainCell12.setBorder(0);
            mainCell12.setPadding(10);
            mainTable.addCell(mainCell12);

            PdfPTable tab5 = new PdfPTable(2);
            tab5.setWidthPercentage(100);
            tab5.setWidths(new float[] { 10, 90 });
            PdfPCell cell3 = createCell(
                    messageSource.getMessage("acc.common.to", null, RequestContextUtils.getLocale(request))
                            + " , ",
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);

            String customerName = "";
            String shipTo = "";
            String memo = "";
            Iterator itr = null;

            HashMap<String, Object> invRequestParams = new HashMap<String, Object>();
            ArrayList filter_names = new ArrayList(), filter_params = new ArrayList(),
                    order_by = new ArrayList(), order_type = new ArrayList();
            order_by.add("srno");
            order_type.add("asc");
            invRequestParams.put("order_by", order_by);
            invRequestParams.put("order_type", order_type);
            KwlReturnObject idresult = null;

            if (mode == StaticValues.AUTONUM_BILLINGCREDITNOTE) {
                customerName = customerObj.getName();//inv.getCustomer()==null?inv.getCustomerEntry().getAccount().getName():inv.getCustomer().getName();
                shipTo = customerObj.getBillingAddress();//inv.getShipTo();
                filter_names.add("creditNote.ID");
                filter_params.add(biCreNote.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accCreditNoteDAOobj.getBillingCreditNoteDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = biCreNote.getMemo();
            } else if (mode == StaticValues.AUTONUM_BILLINGDEBITNOTE) {
                customerName = vendorObj.getName();//dbNote.getCustomer().getName();
                shipTo = vendorObj.getAddress();
                filter_names.add("debitNote.ID");
                filter_params.add(biDeNote.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accDebitNoteobj.getBillingDebitNoteDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = biDeNote.getMemo();
            } else if (mode == StaticValues.AUTONUM_CREDITNOTE) {
                customerName = customerObj.getName();//inv.getCustomer()==null?inv.getCustomerEntry().getAccount().getName():inv.getCustomer().getName();
                shipTo = customerObj.getBillingAddress();//inv.getShipTo();
                filter_names.add("creditNote.ID");
                filter_params.add(creNote.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accCreditNoteDAOobj.getCreditNoteDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = creNote.getMemo();
            } else if (mode == StaticValues.AUTONUM_DEBITNOTE) {
                customerName = vendorObj.getName();//dbNote.getCustomer().getName();
                shipTo = vendorObj.getAddress();
                filter_names.add("debitNote.ID");
                filter_params.add(dbNote.getID());
                invRequestParams.put("filter_names", filter_names);
                invRequestParams.put("filter_params", filter_params);
                idresult = accDebitNoteobj.getDebitNoteDetails(invRequestParams);
                itr = idresult.getEntityList().iterator();
                memo = dbNote.getMemo();
            }
            cell3 = createCell(customerName, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell(shipTo, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);

            PdfPCell mainCell14 = new PdfPCell(tab5);
            mainCell14.setBorder(0);
            mainCell14.setPadding(10);
            mainTable.addCell(mainCell14);

            String[] header = {
                    messageSource.getMessage("acc.cnList.Sno", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.190", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.187", null, RequestContextUtils.getLocale(request)),
                    messageSource.getMessage("acc.rem.193", null, RequestContextUtils.getLocale(request)) };
            PdfPTable table = new PdfPTable(4);
            table.setWidthPercentage(100);
            table.setWidths(new float[] { 7, 35, 29, 29 });
            PdfPCell invcell = null;
            for (int i = 0; i < header.length; i++) {
                invcell = new PdfPCell(new Paragraph(header[i], fontSmallBold));
                invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                invcell.setBackgroundColor(Color.LIGHT_GRAY);
                invCell.setBorder(0);
                invcell.setPadding(3);
                table.addCell(invcell);
            }

            //                Iterator itr = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getRows().iterator() : inv1.getRows().iterator();
            CreditNoteDetail row = null;
            DebitNoteDetail row1 = null;
            BillingCreditNoteDetail row2 = null;
            BillingDebitNoteDetail row3 = null;
            int index = 0;
            while (itr.hasNext()) {
                String prodName = "";
                double quantity = 0;
                Discount discount = null;
                String uom = "";
                double amount1 = 0;
                if (mode == StaticValues.AUTONUM_CREDITNOTE) {
                    row = (CreditNoteDetail) itr.next();
                    prodName = row.getInvoiceRow().getInventory().getProduct().getName();
                    quantity = row.getQuantity();
                    discount = row.getDiscount();
                    taxMain = taxMain + row.getTaxAmount();
                    total = total + row.getTaxAmount();
                    try {
                        uom = row.getInvoiceRow().getInventory().getProduct().getUnitOfMeasure() == null ? ""
                                : row.getInvoiceRow().getInventory().getProduct().getUnitOfMeasure().getName();
                    } catch (Exception ex) {//In case of exception use uom="";
                    }
                } else if (mode == StaticValues.AUTONUM_DEBITNOTE) {
                    row1 = (DebitNoteDetail) itr.next();
                    prodName = row1.getGoodsReceiptRow().getInventory().getProduct().getName();
                    quantity = row1.getQuantity();
                    discount = row1.getDiscount();
                    taxMain = taxMain + row1.getTaxAmount();
                    total = total + row1.getTaxAmount();
                    try {
                        uom = row1.getGoodsReceiptRow().getInventory().getProduct().getUnitOfMeasure() == null
                                ? ""
                                : row1.getGoodsReceiptRow().getInventory().getProduct().getUnitOfMeasure()
                                        .getName();
                    } catch (Exception ex) {//In case of exception use uom="";
                    }
                } else if (mode == StaticValues.AUTONUM_BILLINGCREDITNOTE) {
                    row2 = (BillingCreditNoteDetail) itr.next();
                    prodName = row2.getInvoiceRow().getProductDetail();
                    quantity = row2.getQuantity();
                    discount = row2.getDiscount();
                    taxMain = taxMain + row2.getTaxAmount();
                    total = total + row2.getTaxAmount();
                } else if (mode == StaticValues.AUTONUM_BILLINGDEBITNOTE) {
                    row3 = (BillingDebitNoteDetail) itr.next();
                    prodName = row3.getGoodsReceiptRow().getProductDetail();
                    quantity = row3.getQuantity();
                    discount = row3.getDiscount();
                    taxMain = taxMain + row3.getTaxAmount();
                    total = total + row3.getTaxAmount();
                }

                invcell = createCell((++index) + ".", fontSmallRegular, Element.ALIGN_RIGHT,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                invcell = createCell(prodName, fontSmallRegular, Element.ALIGN_LEFT,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                invcell = createCell((int) quantity + " " + uom, fontSmallRegular, Element.ALIGN_CENTER,
                        Rectangle.LEFT + Rectangle.RIGHT, 5);
                table.addCell(invcell);
                invcell = calculateDiscount(discount, currencyid);
                invcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                invcell.setPadding(5);
                invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                table.addCell(invcell);

                total += discount.getDiscountValue();
                //                    invcell = createCell(authHandlerDAOObj.getFormattedCurrency(amount1, currencyid), fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                //                    table.addCell(invcell);

            }
            //                for (int j = 0; j < 70; j++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
            //                    table.addCell(invcell);
            //                }
            //                for (int i = 0; i < 3; i++) {
            //                    invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
            //                    invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            //                    invcell.setBorder(Rectangle.TOP);
            //                    table.addCell(invcell);
            //                }

            for (int i = 0; i < 2; i++) {
                invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                invcell.setBorder(Rectangle.TOP);
                table.addCell(invcell);
            }

            cell3 = createCell(
                    messageSource.getMessage("acc.rem.192", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_CENTER, Rectangle.TOP, 5);
            table.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(taxMain, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);

            for (int i = 0; i < 2; i++) {
                invcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                invcell.setBorder(0);
                table.addCell(invcell);
            }

            cell3 = createCell(
                    messageSource.getMessage("acc.rem.197", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_CENTER, 0, 5);
            table.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(total, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);

            PdfPCell mainCell5 = new PdfPCell(table);
            mainCell5.setBorder(0);
            mainCell5.setPadding(10);
            mainTable.addCell(mainCell5);

            PdfPTable helpTable = new PdfPTable(new float[] { 8, 92 });
            helpTable.setWidthPercentage(100);
            Phrase phrase1 = new Phrase(
                    messageSource.getMessage("acc.common.memo", null, RequestContextUtils.getLocale(request))
                            + " : ",
                    fontSmallBold);
            Phrase phrase2 = new Phrase(memo, fontSmallRegular);
            PdfPCell pcell1 = new PdfPCell(phrase1);
            PdfPCell pcell2 = new PdfPCell(phrase2);
            pcell1.setBorder(0);
            pcell1.setPadding(10);
            pcell1.setPaddingRight(0);
            pcell2.setBorder(0);
            pcell2.setPadding(10);
            helpTable.addCell(pcell1);
            helpTable.addCell(pcell2);

            PdfPCell mainCell61 = new PdfPCell(helpTable);
            mainCell61.setBorder(0);
            mainTable.addCell(mainCell61);

        } else if (mode == StaticValues.AUTONUM_GOODSRECEIPT
                || mode == StaticValues.AUTONUM_BILLINGGOODSRECEIPT) {
            addHeaderFooter(document, writer);
            GoodsReceipt gr = null;
            BillingGoodsReceipt gr1 = null;
            if (mode == StaticValues.AUTONUM_GOODSRECEIPT) {
                gr = (GoodsReceipt) kwlCommonTablesDAOObj.getClassObject(GoodsReceipt.class.getName(), billid);
            } else {
                gr1 = (BillingGoodsReceipt) kwlCommonTablesDAOObj
                        .getClassObject(BillingGoodsReceipt.class.getName(), billid);
            }

            Company com = mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getCompany() : gr1.getCompany();
            String company[] = new String[4];
            company[0] = com.getCompanyName();
            company[1] = com.getAddress();
            company[2] = com.getEmailID();
            company[3] = com.getPhoneNumber();

            KWLCurrency rowCurrency = (mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getCurrency()
                    : gr1.getCurrency());
            String rowCurrenctID = rowCurrency == null ? currencyid : rowCurrency.getCurrencyID();

            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 50, 50 });

            tab1 = addCompanyLogo(logoPath, com);
            tab2 = new PdfPTable(1);
            PdfPCell invCell = null;

            CompanyAccountPreferences pref = (CompanyAccountPreferences) kwlCommonTablesDAOObj
                    .getClassObject(CompanyAccountPreferences.class.getName(), com.getCompanyID());
            Account cash = pref.getCashAccount();
            Account vEntry;
            if (mode == StaticValues.AUTONUM_GOODSRECEIPT) {
                vEntry = gr.getVendorEntry().getAccount();
            } else {
                vEntry = gr1.getVendorEntry().getAccount();
            }
            String theader = vEntry == cash
                    ? messageSource.getMessage("acc.accPref.autoCP", null,
                            RequestContextUtils.getLocale(request))
                    : messageSource.getMessage("acc.accPref.autoVI", null,
                            RequestContextUtils.getLocale(request));
            invCell = createCell(theader, fontTbl, Element.ALIGN_RIGHT, 0, 5);
            tab2.addCell(invCell);

            PdfPCell cell1 = new PdfPCell(tab1);
            cell1.setBorder(0);
            table1.addCell(cell1);
            PdfPCell cel2 = new PdfPCell(tab2);
            cel2.setBorder(0);
            table1.addCell(cel2);

            PdfPCell mainCell11 = new PdfPCell(table1);
            mainCell11.setBorder(0);
            mainTable.addCell(mainCell11);

            blankTable = addBlankLine(3);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            PdfPTable userTable2 = new PdfPTable(2);
            userTable2.setWidthPercentage(100);
            userTable2.setWidths(new float[] { 60, 40 });

            tab3 = getCompanyInfo(company);

            PdfPTable tab4 = new PdfPTable(2);
            tab4.setWidthPercentage(100);
            tab4.setWidths(new float[] { 30, 70 });

            PdfPCell cell2 = createCell(theader + " #", fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            String grno = mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getGoodsReceiptNumber()
                    : gr1.getBillingGoodsReceiptNumber();
            cell2 = createCell(": " + grno, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            cell2 = createCell(
                    messageSource.getMessage("acc.rem.198", null, RequestContextUtils.getLocale(request))
                            + "  ",
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);
            cell2 = createCell(
                    ": " + formatter.format(
                            mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getJournalEntry().getEntryDate()
                                    : gr1.getJournalEntry().getEntryDate()),
                    fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab4.addCell(cell2);

            cell1 = new PdfPCell(tab3);
            cell1.setBorder(0);
            userTable2.addCell(cell1);
            cel2 = new PdfPCell(tab4);
            cel2.setBorder(0);
            userTable2.addCell(cel2);

            PdfPCell mainCell12 = new PdfPCell(userTable2);
            mainCell12.setBorder(0);
            mainTable.addCell(mainCell12);

            blankTable = addBlankLine(3);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            PdfPTable tab5 = new PdfPTable(2);
            tab5.setWidthPercentage(100);
            tab5.setWidths(new float[] { 10, 90 });
            PdfPCell cell3 = createCell(
                    messageSource.getMessage("acc.common.from", null, RequestContextUtils.getLocale(request))
                            + " , ",
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);

            String vendorName = "";
            if (mode == StaticValues.AUTONUM_GOODSRECEIPT) {
                vendorName = gr.getVendor() == null ? gr.getVendorEntry().getAccount().getName()
                        : gr.getVendor().getName();
            } else {
                vendorName = gr1.getVendor() == null ? gr1.getVendorEntry().getAccount().getName()
                        : gr1.getVendor().getName();
            }
            cell3 = createCell(vendorName, fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab5.addCell(cell3);
            cell3 = createCell(mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getBillFrom() : gr1.getBillFrom(),
                    fontSmallRegular, Element.ALIGN_LEFT, 0, 5);
            tab5.addCell(cell3);

            PdfPCell mainCell14 = new PdfPCell(tab5);
            mainCell14.setBorder(0);
            mainTable.addCell(mainCell14);

            blankTable = addBlankLine(3);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);
            PdfPTable table;
            PdfPCell grcell = null;
            if (isExpenseInv) {
                String[] header = { "S.No.", "Account", "PRICE", "DISCOUNT", "TAX", "LINE TOTAL" };
                table = new PdfPTable(6);
                table.setWidthPercentage(100);
                table.setWidths(new float[] { 7, 23, 18, 18, 18, 16 });
                for (int i = 0; i < header.length; i++) {
                    grcell = new PdfPCell(new Paragraph(header[i], fontSmallBold));
                    grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    grcell.setBackgroundColor(Color.LIGHT_GRAY);
                    grcell.setBorder(0);
                    grcell.setPadding(3);
                    table.addCell(grcell);
                }
            } else {

                String[] header = {
                        messageSource.getMessage("acc.cnList.Sno", null,
                                RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.190", null, RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.187", null, RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.188", null, RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.191", null, RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.192", null, RequestContextUtils.getLocale(request)),
                        messageSource.getMessage("acc.rem.212", null, RequestContextUtils.getLocale(request)) };
                table = new PdfPTable(7);
                table.setWidthPercentage(100);
                table.setWidths(new float[] { 5, 20, 15, 15, 15, 13, 17 });
                for (int i = 0; i < header.length; i++) {
                    grcell = new PdfPCell(new Paragraph(header[i], fontSmallBold));
                    grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    grcell.setBackgroundColor(Color.LIGHT_GRAY);
                    grcell.setBorder(0);
                    grcell.setPadding(3);
                    table.addCell(grcell);
                }
            }
            //                Iterator itr =mode==StaticValues.AUTONUM_GOODSRECEIPT?gr.getRows().iterator():gr1.getRows().iterator();
            HashMap<String, Object> grRequestParams = new HashMap<String, Object>();
            ArrayList filter_names = new ArrayList(), filter_params = new ArrayList(),
                    order_by = new ArrayList(), order_type = new ArrayList();
            order_by.add("srno");
            order_type.add("asc");
            grRequestParams.put("order_by", order_by);
            grRequestParams.put("order_type", order_type);

            KwlReturnObject idresult = null;
            if (mode != StaticValues.AUTONUM_BILLINGINVOICE
                    || mode != StaticValues.AUTONUM_BILLINGGOODSRECEIPT) {
                if (mode == StaticValues.AUTONUM_BILLINGGOODSRECEIPT) {
                    filter_names.add("billingGoodsReceipt.ID");
                    filter_params.add(gr1.getID());
                    grRequestParams.put("filter_names", filter_names);
                    grRequestParams.put("filter_params", filter_params);
                    idresult = accGoodsReceiptobj.getBillingGoodsReceiptDetails(grRequestParams);
                } else {
                    filter_names.add("goodsReceipt.ID");
                    filter_params.add(gr.getID());
                    grRequestParams.put("filter_names", filter_names);
                    grRequestParams.put("filter_params", filter_params);
                    if (isExpenseInv) {
                        idresult = accGoodsReceiptobj.getExpenseGRDetails(grRequestParams);
                    } else
                        idresult = accGoodsReceiptobj.getGoodsReceiptDetails(grRequestParams);
                }
            } else {
                filter_names.add("billingGoodsReceipt.ID");
                filter_params.add(gr.getID());
                grRequestParams.put("filter_names", filter_names);
                grRequestParams.put("filter_params", filter_params);
                idresult = accGoodsReceiptobj.getBillingGoodsReceiptDetails(grRequestParams);
            }
            Iterator itr = idresult.getEntityList().iterator();

            GoodsReceiptDetail row = null;
            BillingGoodsReceiptDetail row1 = null;
            ExpenseGRDetail exprow = null;
            int index = 0;
            while (itr.hasNext()) {
                if (mode == StaticValues.AUTONUM_GOODSRECEIPT) {
                    if (isExpenseInv)
                        exprow = (ExpenseGRDetail) itr.next();
                    else
                        row = (GoodsReceiptDetail) itr.next();
                } else {
                    row1 = (BillingGoodsReceiptDetail) itr.next();
                }
                if (isExpenseInv) {
                    grcell = createCell((++index) + ".", fontSmallRegular, Element.ALIGN_RIGHT,
                            Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = createCell(exprow.getAccount().getName(), fontSmallRegular, Element.ALIGN_LEFT,
                            Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = createCell(authHandlerDAOObj.getFormattedCurrency(exprow.getRate(), rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = calculateDiscount(exprow.getDiscount(), rowCurrenctID);
                    grcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    grcell.setPadding(5);
                    grcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                    table.addCell(grcell);
                    double amount1 = exprow.getRate();
                    Discount disc = exprow.getDiscount();
                    if (disc != null) {
                        amount1 -= exprow.getDiscount().getDiscountValue();
                    }

                    double rowTaxPercent = 0;
                    HashMap<String, Object> requestParams = AccountingManager.getGlobalParams(request);
                    if (exprow != null && exprow.getTax() != null) {
                        requestParams.put("transactiondate",
                                exprow.getGoodsReceipt().getJournalEntry().getEntryDate());
                        requestParams.put("taxid", exprow.getTax().getID());
                        KwlReturnObject result = accTaxObj.getTax(requestParams);
                        List taxList = result.getEntityList();
                        Object[] taxObj = (Object[]) taxList.get(0);
                        rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                    }
                    grcell = createCell(
                            authHandlerDAOObj.getFormattedCurrency(amount1 * rowTaxPercent / 100,
                                    rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    amount1 += amount1 * rowTaxPercent / 100;
                    grcell = createCell(authHandlerDAOObj.getFormattedCurrency(amount1, rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    total += amount1;
                    for (int j = 0; j < 84; j++) {
                        grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                        grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        grcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                        table.addCell(grcell);
                    }

                } else {
                    grcell = createCell((++index) + ".", fontSmallRegular, Element.ALIGN_RIGHT,
                            Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = createCell(
                            mode == StaticValues.AUTONUM_GOODSRECEIPT
                                    ? row.getInventory().getProduct().getName()
                                    : row1.getProductDetail(),
                            fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = createCell(
                            Double.toString(mode == StaticValues.AUTONUM_GOODSRECEIPT
                                    ? row.getInventory().getQuantity()
                                    : row1.getQuantity())
                                    + " "
                                    + (mode != StaticValues.AUTONUM_BILLINGGOODSRECEIPT
                                            ? (row.getInventory().getProduct().getUnitOfMeasure() == null ? ""
                                                    : row.getInventory().getProduct().getUnitOfMeasure()
                                                            .getName())
                                            : ""),
                            fontSmallRegular, Element.ALIGN_CENTER, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = createCell(
                            authHandlerDAOObj.getFormattedCurrency(
                                    mode == StaticValues.AUTONUM_GOODSRECEIPT ? row.getRate() : row1.getRate(),
                                    rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    grcell = calculateDiscount(
                            mode == StaticValues.AUTONUM_GOODSRECEIPT ? row.getDiscount() : row1.getDiscount(),
                            rowCurrenctID);
                    grcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    grcell.setPadding(5);
                    grcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                    table.addCell(grcell);
                    double amount1 = mode == StaticValues.AUTONUM_GOODSRECEIPT
                            ? row.getRate() * row.getInventory().getQuantity()
                            : row1.getRate() * row1.getQuantity();
                    Discount disc = mode == StaticValues.AUTONUM_GOODSRECEIPT ? row.getDiscount()
                            : row1.getDiscount();
                    if (disc != null) {
                        amount1 -= mode == StaticValues.AUTONUM_GOODSRECEIPT
                                ? row.getDiscount().getDiscountValue()
                                : row1.getDiscount().getDiscountValue();
                    }

                    double rowTaxPercent = 0;
                    HashMap<String, Object> requestParams = AccountingManager.getGlobalParams(request);
                    if (row != null && row.getTax() != null) {
                        requestParams.put("transactiondate",
                                row.getGoodsReceipt().getJournalEntry().getEntryDate());
                        requestParams.put("taxid", row.getTax().getID());
                        KwlReturnObject result = accTaxObj.getTax(requestParams);
                        List taxList = result.getEntityList();
                        Object[] taxObj = (Object[]) taxList.get(0);
                        rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                    } else if (row1 != null && row1.getTax() != null) {
                        requestParams.put("transactiondate",
                                row1.getBillingGoodsReceipt().getJournalEntry().getEntryDate());
                        requestParams.put("taxid", row1.getTax().getID());
                        KwlReturnObject result = accTaxObj.getTax(requestParams);
                        List taxList = result.getEntityList();
                        Object[] taxObj = (Object[]) taxList.get(0);
                        rowTaxPercent = taxObj[1] == null ? 0 : (Double) taxObj[1];
                    }
                    grcell = createCell(
                            authHandlerDAOObj.getFormattedCurrency(amount1 * rowTaxPercent / 100,
                                    rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    amount1 += amount1 * rowTaxPercent / 100;
                    grcell = createCell(authHandlerDAOObj.getFormattedCurrency(amount1, rowCurrenctID),
                            fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
                    table.addCell(grcell);
                    total += amount1;
                    for (int j = 0; j < 98; j++) {
                        grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                        grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        grcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                        table.addCell(grcell);
                    }

                }
            }
            int length = isExpenseInv ? 4 : 5;
            for (int i = 0; i < length; i++) {
                grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                grcell.setBorder(Rectangle.TOP);
                table.addCell(grcell);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.194", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_LEFT, Rectangle.TOP, 5);
            table.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(total, rowCurrenctID), fontSmallRegular,
                    Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);
            for (int i = 0; i < length; i++) {
                grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                grcell.setPadding(5);
                grcell.setBorder(0);
                table.addCell(grcell);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.195", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            table.addCell(cell3);
            grcell = calculateDiscount(
                    mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getDiscount() : gr1.getDiscount(),
                    rowCurrenctID);
            grcell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            grcell.setPadding(5);
            table.addCell(grcell);
            for (int i = 0; i < length; i++) {
                grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                grcell.setPadding(5);
                grcell.setBorder(0);
                table.addCell(grcell);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.196", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            table.addCell(cell3);
            cell3 = createCell(
                    authHandlerDAOObj.getFormattedCurrency(
                            mode == StaticValues.AUTONUM_GOODSRECEIPT
                                    ? (gr.getTaxEntry() != null ? gr.getTaxEntry().getAmount() : 0)
                                    : (gr1.getTaxEntry() != null ? gr1.getTaxEntry().getAmount() : 0),
                            rowCurrenctID),
                    fontSmallRegular, Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);
            for (int i = 0; i < length; i++) {
                grcell = new PdfPCell(new Paragraph("", fontSmallRegular));
                grcell.setHorizontalAlignment(Element.ALIGN_CENTER);
                grcell.setPadding(5);
                grcell.setBorder(0);
                table.addCell(grcell);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.197", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold, Element.ALIGN_LEFT, 0, 5);
            table.addCell(cell3);
            cell3 = createCell(
                    authHandlerDAOObj.getFormattedCurrency(
                            mode == StaticValues.AUTONUM_GOODSRECEIPT ? (gr.getVendorEntry().getAmount())
                                    : (gr1.getVendorEntry().getAmount()),
                            rowCurrenctID),
                    fontSmallRegular, Element.ALIGN_RIGHT, 15, 5);
            table.addCell(cell3);

            PdfPCell mainCell5 = new PdfPCell(table);
            mainCell5.setBorder(0);
            mainTable.addCell(mainCell5);
            KWLCurrency currency = (KWLCurrency) kwlCommonTablesDAOObj
                    .getClassObject(KWLCurrency.class.getName(), currencyid);
            double totalamount = 0;
            if (gr != null)
                totalamount = gr.getVendorEntry().getAmount();
            else if (gr1 != null)
                totalamount = gr1.getVendorEntry().getAmount();
            String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(totalamount)),
                    currency);
            String currencyname = currency.getName();
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.177", null, RequestContextUtils.getLocale(request))
                            + " : " + currencyname + " " + netinword + " Only.",
                    fontSmallRegular, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5);
            PdfPTable table2 = new PdfPTable(1);
            table2.addCell(cell3);
            PdfPCell mainCell62 = new PdfPCell(table2);
            mainCell62.setBorder(0);
            mainTable.addCell(mainCell62);
            PdfPTable helpTable = new PdfPTable(new float[] { 8, 92 });
            helpTable.setWidthPercentage(100);
            Phrase phrase1 = new Phrase(
                    messageSource.getMessage("acc.common.memo", null, RequestContextUtils.getLocale(request))
                            + ":  ",
                    fontSmallBold);
            Phrase phrase2 = new Phrase(
                    mode == StaticValues.AUTONUM_GOODSRECEIPT ? gr.getMemo() : gr1.getMemo(), fontSmallRegular);
            PdfPCell pcell1 = new PdfPCell(phrase1);
            PdfPCell pcell2 = new PdfPCell(phrase2);
            pcell1.setBorder(0);
            pcell1.setPadding(10);
            pcell1.setPaddingRight(0);
            pcell2.setBorder(0);
            pcell2.setPadding(10);
            helpTable.addCell(pcell1);
            helpTable.addCell(pcell2);

            PdfPCell mainCell61 = new PdfPCell(helpTable);
            mainCell61.setBorder(0);
            mainTable.addCell(mainCell61);

        } else if (mode == StaticValues.AUTONUM_RECEIPT || mode == StaticValues.AUTONUM_BILLINGRECEIPT) {

            Receipt rc = null;
            BillingReceipt rc1 = null;
            if (mode != StaticValues.AUTONUM_BILLINGRECEIPT) {
                rc = (Receipt) kwlCommonTablesDAOObj.getClassObject(Receipt.class.getName(), billid);
            } else {
                rc1 = (BillingReceipt) kwlCommonTablesDAOObj.getClassObject(BillingReceipt.class.getName(),
                        billid);
            }

            KWLCurrency currency = (KWLCurrency) kwlCommonTablesDAOObj
                    .getClassObject(KWLCurrency.class.getName(), currencyid);
            Company com = mode != StaticValues.AUTONUM_BILLINGRECEIPT ? rc.getCompany() : rc1.getCompany();
            String company[] = new String[3];
            company[0] = com.getCompanyName();
            company[1] = com.getAddress();
            company[2] = com.getEmailID();

            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 25, 75 });

            tab1 = addCompanyLogo(logoPath, com);

            tab3 = new PdfPTable(1);
            tab3.setWidthPercentage(100);
            PdfPCell mainCell1 = null;
            mainCell1 = createCell(com.getCompanyName(), fontMediumBold, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(125);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getAddress(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getEmailID(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getPhoneNumber(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = new PdfPCell(tab1);
            mainCell1.setBorder(0);
            table1.addCell(mainCell1);
            mainCell1 = new PdfPCell(tab3);
            mainCell1.setBorder(0);
            table1.addCell(mainCell1);

            mainCell1 = new PdfPCell(table1);
            mainCell1.setBorder(0);
            mainTable.addCell(mainCell1);

            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            PdfPCell mainCell2 = createCell(
                    messageSource.getMessage("acc.numb.37", null, RequestContextUtils.getLocale(request)),
                    fontMediumBold, Element.ALIGN_CENTER, 0, 0);
            mainTable.addCell(mainCell2);

            blankTable = addBlankLine(2);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab3 = new PdfPTable(2);
            tab3.setWidthPercentage(100);
            tab3.setWidths(new float[] { 60, 40 });

            tab1 = new PdfPTable(2);
            tab1.setWidthPercentage(100);
            tab1.setWidths(new float[] { 10, 90 });

            PdfPCell cell3 = createCell(
                    messageSource.getMessage("acc.msgbox.no", null, RequestContextUtils.getLocale(request))
                            + " : ",
                    fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            new PdfPCell(new Paragraph());
            tab1.addCell(cell3);
            cell3 = createCell(mode != StaticValues.AUTONUM_BILLINGRECEIPT ? rc.getReceiptNumber()
                    : rc1.getBillingReceiptNumber(), fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab1.addCell(cell3);
            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 30, 70 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.38", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_RIGHT, 0, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    formatter.format(
                            mode != StaticValues.AUTONUM_BILLINGRECEIPT ? rc.getJournalEntry().getEntryDate()
                                    : rc1.getJournalEntry().getEntryDate()),
                    fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab2.addCell(cell3);

            PdfPCell mainCell3 = new PdfPCell(tab1);
            mainCell3.setBorder(0);
            tab3.addCell(mainCell3);
            mainCell3 = new PdfPCell(tab2);
            mainCell3.setBorder(0);
            tab3.addCell(mainCell3);

            PdfPCell mainCell4 = new PdfPCell(tab3);
            mainCell4.setBorder(0);
            mainTable.addCell(mainCell4);

            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);
            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 75, 25 });
            cell3 = new PdfPCell(new Paragraph(
                    messageSource.getMessage("acc.report.2", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold));
            cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell3.setBackgroundColor(Color.lightGray);
            cell3.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT);
            tab2.addCell(cell3);
            cell3 = new PdfPCell(new Paragraph(
                    messageSource.getMessage("acc.rem.193", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold));
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setBackgroundColor(Color.lightGray);
            cell3.setBorder(Rectangle.RIGHT + Rectangle.BOTTOM);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.je.acc", null, RequestContextUtils.getLocale(request))
                            + " : ",
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(accname, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT,
                    0);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(amount, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, Rectangle.RIGHT, 15);
            tab2.addCell(cell3);
            cell3 = createCell(address, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT,
                    0);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);

            for (int i = 0; i < 30; i++) {
                cell3 = new PdfPCell(new Paragraph("", fontSmallRegular));
                cell3.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                tab2.addCell(cell3);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.42", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    mode != StaticValues.AUTONUM_BILLINGRECEIPT
                            ? (rc.getPayDetail() == null ? "Cash"
                                    : rc.getPayDetail().getPaymentMethod().getMethodName())
                            : (rc1.getPayDetail() == null ? "Cash"
                                    : rc1.getPayDetail().getPaymentMethod().getMethodName()),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    mode != StaticValues.AUTONUM_BILLINGRECEIPT
                            ? (rc.getPayDetail() != null
                                    ? (rc.getPayDetail().getPaymentMethod().getMethodName().equals("Cheque")
                                            ? "Cheque No : " + rc.getPayDetail().getCheque().getChequeNo()
                                                    + " and Bank Name : "
                                                    + rc.getPayDetail().getCheque().getBankName()
                                            : "")
                                    : "")
                            : (rc1.getPayDetail() != null
                                    ? (rc1.getPayDetail().getPaymentMethod().getMethodName().equals("Cheque")
                                            ? "Cheque No : " + rc1.getPayDetail().getCheque().getChequeNo()
                                                    + " and Bank Name : "
                                                    + rc1.getPayDetail().getCheque().getBankName()
                                            : "")
                                    : ""),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            String str = "";
            if (mode != StaticValues.AUTONUM_BILLINGRECEIPT) {
                if (rc.getPayDetail() != null)
                    if (rc.getPayDetail().getPaymentMethod().getDetailType() == 2
                            || rc.getPayDetail().getPaymentMethod().getDetailType() == 1)
                        if (rc.getPayDetail().getCard() != null)
                            str = "Card No : " + (rc.getPayDetail().getCard().getCardNo())
                                    + " and Card Holder : " + rc.getPayDetail().getCard().getCardHolder();
                        else if (rc.getPayDetail().getCheque() != null)
                            str = "Bank Name : " + (rc.getPayDetail().getCheque().getBankName())
                                    + "and Ref. No : " + (rc.getPayDetail().getCheque().getChequeNo());
            } else if (rc1.getPayDetail() != null)
                if (rc1.getPayDetail().getPaymentMethod().getDetailType() == 2
                        || rc1.getPayDetail().getPaymentMethod().getDetailType() == 1)
                    if (rc1.getPayDetail().getCard() != null)
                        str = "Card No : " + (rc1.getPayDetail().getCard().getCardNo()) + " and Card Holder : "
                                + rc1.getPayDetail().getCard().getCardHolder();
                    else if (rc1.getPayDetail().getCheque() != null)
                        str = "Bank Name : " + (rc1.getPayDetail().getCheque().getBankName()) + "and Ref. No : "
                                + (rc1.getPayDetail().getCheque().getChequeNo());

            //                mode!=StaticValues.AUTONUM_BILLINGRECEIPT?(rc.getPayDetail()!=null?(rc.getPayDetail().getPaymentMethod().getMethodName().equals("Credit Card")||customer.equals("Debit Card")?
            //                        rc.getPayDetail().getCard()!=null?"Card No : "+(rc.getPayDetail().getCard().getCardNo()+" and Card Holder : "+rc.getPayDetail().getCard().getCardHolder()):"":""):""):
            //                        (rc1.getPayDetail()!=null?(rc1.getPayDetail().getPaymentMethod().getMethodName().equals("Credit Card")||customer.equals("Debit Card")?
            //                        rc1.getPayDetail().getCard()!=null?"Card No : "+(rc1.getPayDetail().getCard().getCardNo()+" and Card Holder : "+rc1.getPayDetail().getCard().getCardHolder()):"":""):"")

            cell3 = createCell(str, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.41", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell(mode != StaticValues.AUTONUM_BILLINGRECEIPT ? rc.getMemo() : rc1.getMemo(),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(amount)),
                    currency);
            String currencyname = currency.getName();
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.177", null, RequestContextUtils.getLocale(request))
                            + " : " + currencyname + " " + netinword + " Only.",
                    fontSmallRegular, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5);
            tab2.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(amount, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP,
                    5);
            tab2.addCell(cell3);
            PdfPCell mainCell5 = new PdfPCell(tab2);
            mainCell5.setBorder(1);
            mainTable.addCell(mainCell5);

            blankTable = addBlankLine(25);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab1 = new PdfPTable(2);
            tab1.setWidthPercentage(100);
            tab1.setWidths(new float[] { 50, 50 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.35", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab1.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.36", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab1.addCell(cell3);
            PdfPCell mainCell6 = new PdfPCell(tab1);
            mainCell6.setPadding(5);
            mainCell6.setBorder(0);
            mainTable.addCell(mainCell6);

            blankTable = addBlankLine(15);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 50, 50 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.39", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.40", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab2.addCell(cell3);
            PdfPCell mainCell7 = new PdfPCell(tab2);
            mainCell7.setPadding(5);
            mainCell7.setBorder(0);
            mainTable.addCell(mainCell7);
            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

        } else if (mode == StaticValues.AUTONUM_PAYMENT || mode == StaticValues.AUTONUM_BILLINGPAYMENT) {
            Payment pc = null;
            BillingPayment pc1 = null;
            if (mode == StaticValues.AUTONUM_PAYMENT) {
                pc = (Payment) kwlCommonTablesDAOObj.getClassObject(Payment.class.getName(), billid);
            } else {
                pc1 = (BillingPayment) kwlCommonTablesDAOObj.getClassObject(BillingPayment.class.getName(),
                        billid);
            }
            KWLCurrency currency = (KWLCurrency) kwlCommonTablesDAOObj
                    .getClassObject(KWLCurrency.class.getName(), currencyid);
            Company com = mode == StaticValues.AUTONUM_PAYMENT ? pc.getCompany() : pc1.getCompany();
            String company[] = new String[3];
            company[0] = com.getCompanyName();
            company[1] = com.getAddress();
            company[2] = com.getEmailID();

            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 25, 75 });

            tab1 = addCompanyLogo(logoPath, com);

            tab3 = new PdfPTable(1);
            tab3.setWidthPercentage(100);
            PdfPCell mainCell1 = null;
            mainCell1 = createCell(com.getCompanyName(), fontMediumBold, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(125);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getAddress(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getEmailID(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = createCell(com.getPhoneNumber(), fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            mainCell1.setPaddingLeft(75);
            tab3.addCell(mainCell1);
            mainCell1 = new PdfPCell(tab1);
            mainCell1.setBorder(0);
            table1.addCell(mainCell1);
            mainCell1 = new PdfPCell(tab3);
            mainCell1.setBorder(0);
            table1.addCell(mainCell1);

            mainCell1 = new PdfPCell(table1);
            mainCell1.setBorder(0);
            mainTable.addCell(mainCell1);

            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            PdfPCell mainCell2 = createCell(
                    messageSource.getMessage("acc.numb.37", null, RequestContextUtils.getLocale(request)),
                    fontMediumBold, Element.ALIGN_CENTER, 0, 0);
            mainTable.addCell(mainCell2);

            blankTable = addBlankLine(2);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab3 = new PdfPTable(2);
            tab3.setWidthPercentage(100);
            tab3.setWidths(new float[] { 60, 40 });

            tab1 = new PdfPTable(2);
            tab1.setWidthPercentage(100);
            tab1.setWidths(new float[] { 10, 90 });

            PdfPCell cell3 = createCell(
                    messageSource.getMessage("acc.msgbox.no", null, RequestContextUtils.getLocale(request))
                            + " : ",
                    fontSmallRegular, Element.ALIGN_LEFT, 0, 0);
            new PdfPCell(new Paragraph());
            tab1.addCell(cell3);
            cell3 = createCell(mode == StaticValues.AUTONUM_PAYMENT ? pc.getPaymentNumber()
                    : pc1.getBillingPaymentNumber(), fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab1.addCell(cell3);
            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 30, 70 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.38", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_RIGHT, 0, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    formatter.format(mode == StaticValues.AUTONUM_PAYMENT ? pc.getJournalEntry().getEntryDate()
                            : pc1.getJournalEntry().getEntryDate()),
                    fontSmallBold, Element.ALIGN_LEFT, 0, 0);
            tab2.addCell(cell3);

            PdfPCell mainCell3 = new PdfPCell(tab1);
            mainCell3.setBorder(0);
            tab3.addCell(mainCell3);
            mainCell3 = new PdfPCell(tab2);
            mainCell3.setBorder(0);
            tab3.addCell(mainCell3);

            PdfPCell mainCell4 = new PdfPCell(tab3);
            mainCell4.setBorder(0);
            mainTable.addCell(mainCell4);

            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);
            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 75, 25 });
            cell3 = new PdfPCell(new Paragraph(
                    messageSource.getMessage("acc.report.2", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold));
            cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell3.setBackgroundColor(Color.lightGray);
            cell3.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT);
            tab2.addCell(cell3);
            cell3 = new PdfPCell(new Paragraph(
                    messageSource.getMessage("acc.rem.193", null, RequestContextUtils.getLocale(request)),
                    fontSmallBold));
            cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell3.setBackgroundColor(Color.lightGray);
            cell3.setBorder(Rectangle.RIGHT + Rectangle.BOTTOM);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.193", null, RequestContextUtils.getLocale(request))
                            + " : ",
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallBold, Element.ALIGN_LEFT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(accname, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT,
                    0);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(amount, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell(address, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT,
                    0);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);

            for (int i = 0; i < 30; i++) {
                cell3 = new PdfPCell(new Paragraph("", fontSmallRegular));
                cell3.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                tab2.addCell(cell3);
            }
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.42", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    mode == StaticValues.AUTONUM_PAYMENT
                            ? (pc.getPayDetail() == null ? "Cash"
                                    : pc.getPayDetail().getPaymentMethod().getMethodName())
                            : (pc1.getPayDetail() == null ? "Cash"
                                    : pc1.getPayDetail().getPaymentMethod().getMethodName()),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    mode == StaticValues.AUTONUM_PAYMENT
                            ? (pc.getPayDetail() != null
                                    ? (pc.getPayDetail().getPaymentMethod().getMethodName().equals("Cheque")
                                            ? "Cheque No : " + pc.getPayDetail().getCheque().getChequeNo()
                                                    + " and Bank Name : "
                                                    + pc.getPayDetail().getCheque().getBankName()
                                            : "")
                                    : "")
                            : (pc1.getPayDetail() != null
                                    ? (pc1.getPayDetail().getPaymentMethod().getMethodName().equals("Cheque")
                                            ? "Cheque No : " + pc1.getPayDetail().getCheque().getChequeNo()
                                                    + " and Bank Name : "
                                                    + pc1.getPayDetail().getCheque().getBankName()
                                            : "")
                                    : ""),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            String str = "";

            if (mode == StaticValues.AUTONUM_PAYMENT) {
                if (pc.getPayDetail() != null)
                    if (pc.getPayDetail().getPaymentMethod().getDetailType() == 2
                            || pc.getPayDetail().getPaymentMethod().getDetailType() == 1)
                        if (pc.getPayDetail().getCard() != null)
                            str = "Card No : " + (pc.getPayDetail().getCard().getCardNo())
                                    + " and Card Holder : " + pc.getPayDetail().getCard().getCardHolder();
                        else if (pc.getPayDetail().getCheque() != null)
                            str = "Bank Name : " + (pc.getPayDetail().getCheque().getBankName())
                                    + "and Ref. No : " + (pc.getPayDetail().getCheque().getChequeNo());
            } else if (pc1.getPayDetail() != null)
                if (pc1.getPayDetail().getPaymentMethod().getDetailType() == 2
                        || pc1.getPayDetail().getPaymentMethod().getDetailType() == 1)
                    if (pc1.getPayDetail().getCard() != null)
                        str = "Card No : " + (pc1.getPayDetail().getCard().getCardNo()) + " and Card Holder : "
                                + pc1.getPayDetail().getCard().getCardHolder();
                    else if (pc1.getPayDetail().getCheque() != null)
                        str = "Bank Name : " + (pc1.getPayDetail().getCheque().getBankName()) + "and Ref. No : "
                                + (pc1.getPayDetail().getCheque().getChequeNo());
            cell3 = createCell(str, fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.41", null, RequestContextUtils.getLocale(request)),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_RIGHT, Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            cell3 = createCell(mode == StaticValues.AUTONUM_PAYMENT ? pc.getMemo() : pc1.getMemo(),
                    fontSmallRegular, Element.ALIGN_LEFT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            cell3.setPaddingLeft(50);
            tab2.addCell(cell3);
            cell3 = createCell("", fontSmallRegular, Element.ALIGN_CENTER, Rectangle.RIGHT, 5);
            tab2.addCell(cell3);
            String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(amount)),
                    currency);
            String currencyname = currency.getName();
            cell3 = createCell(
                    messageSource.getMessage("acc.rem.177", null, RequestContextUtils.getLocale(request)) + " "
                            + currencyname + " " + netinword + " Only.",
                    fontSmallRegular, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5);
            tab2.addCell(cell3);
            cell3 = createCell(authHandlerDAOObj.getFormattedCurrency(amount, currencyid), fontSmallRegular,
                    Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP,
                    5);
            tab2.addCell(cell3);
            PdfPCell mainCell5 = new PdfPCell(tab2);
            mainCell5.setBorder(1);
            mainTable.addCell(mainCell5);

            blankTable = addBlankLine(25);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab1 = new PdfPTable(2);
            tab1.setWidthPercentage(100);
            tab1.setWidths(new float[] { 50, 50 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.35", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab1.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.36", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab1.addCell(cell3);
            PdfPCell mainCell6 = new PdfPCell(tab1);
            mainCell6.setPadding(5);
            mainCell6.setBorder(0);
            mainTable.addCell(mainCell6);

            blankTable = addBlankLine(15);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

            tab2 = new PdfPTable(2);
            tab2.setWidthPercentage(100);
            tab2.setWidths(new float[] { 50, 50 });
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.39", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab2.addCell(cell3);
            cell3 = createCell(
                    messageSource.getMessage("acc.numb.40", null, RequestContextUtils.getLocale(request)),
                    fontTblMediumBold, Element.ALIGN_CENTER, 0, 0);
            tab2.addCell(cell3);
            PdfPCell mainCell7 = new PdfPCell(tab2);
            mainCell7.setPadding(5);
            mainCell7.setBorder(0);
            mainTable.addCell(mainCell7);
            blankTable = addBlankLine(5);
            blankCell = new PdfPCell(blankTable);
            blankCell.setBorder(0);
            mainTable.addCell(blankCell);

        }

        document.add(mainTable);
        return baos;
    } catch (Exception ex) {
        throw ServiceException.FAILURE("Export:" + ex.getMessage(), ex);
    } finally {
        if (document != null) {
            document.close();
        }
        if (writer != null) {
            writer.close();
        }
        if (baos != null) {
            baos.close();
        }
    }

}

From source file:com.krawler.spring.exportFunctionality.exportDAOImpl.java

License:Open Source License

public void createInvoicePdf(Document document, int mode, Map<String, Object> DataInfo, Company com,
        DateFormat formatter, String currencyid, JSONArray productDetails, String preText, String postText,
        String baseUrl) throws DocumentException, JSONException {
    // mode 1 = quotation
    try {/*from w w w.  j a va2  s.  c o  m*/
        KWLCurrency currencyObj = (KWLCurrency) hibernateTemplate.load(KWLCurrency.class, currencyid);
        config = new com.krawler.utils.json.base.JSONObject(DataInfo.get("config").toString());
        PdfPTable tab2 = null;
        PdfPTable tab3 = null;
        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setWidthPercentage(100);
        String invno = "";
        String theader = "";
        double quotationDisc = 0;
        double quotationtaxamount = 0;
        String quotationtaxname = "";
        double totalAmount = 0;
        double quotationtaxpercent = 0;
        Date entryDate = null;
        String customerName = "";
        String shipTo = "";
        String memo = "";
        //                itr = idresult.getEntityList().iterator();

        if (mode == 1) {
            theader = "Quotation";
            invno = DataInfo.containsKey("invno") ? DataInfo.get("invno").toString() : "";
            entryDate = DataInfo.containsKey("entrydate") ? (Date) DataInfo.get("entrydate") : new Date();
            customerName = DataInfo.containsKey("customername") ? DataInfo.get("customername").toString() : "";
            shipTo = DataInfo.containsKey("address") ? DataInfo.get("address").toString() : "";
            memo = DataInfo.containsKey("memo") ? DataInfo.get("memo").toString() : "";
            quotationDisc = DataInfo.containsKey("quotationdisc")
                    ? Double.parseDouble(DataInfo.get("quotationdisc").toString())
                    : 0;
            quotationtaxamount = DataInfo.containsKey("quotationtax")
                    ? Double.parseDouble(DataInfo.get("quotationtax").toString())
                    : 0;
            quotationtaxname = DataInfo.containsKey("quotationtaxname")
                    ? DataInfo.get("quotationtaxname").toString()
                    : "";
            quotationtaxpercent = DataInfo.containsKey("quotationtaxpercent")
                    ? Double.parseDouble(DataInfo.get("quotationtaxpercent").toString())
                    : 0;
            totalAmount = DataInfo.containsKey("totalamount")
                    ? Double.parseDouble(DataInfo.get("totalamount").toString())
                    : 0;
        }
        String company[] = new String[4];
        company[0] = com.getCompanyName();
        company[1] = com.getAddress();
        company[2] = com.getEmailID();
        company[3] = com.getPhoneNumber();

        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(100);
        table1.setWidths(new float[] { 50, 50 });

        tab2 = new PdfPTable(1);
        PdfPCell invCell = null;
        invCell = createCell(theader, FontContext.TABLE_HEADER, Element.ALIGN_RIGHT, 0, 5);
        tab2.addCell(invCell);
        PdfPCell cel2 = new PdfPCell(tab2);
        cel2.setBorder(0);
        table1.addCell(cel2);

        PdfPCell mainCell11 = new PdfPCell(table1);
        mainCell11.setBorder(0);
        mainCell11.setPadding(10);
        mainTable.addCell(mainCell11);

        PdfPTable userTable2 = new PdfPTable(2);
        userTable2.setWidthPercentage(100);
        userTable2.setWidths(new float[] { 60, 40 });

        tab3 = getCompanyInfo(company);

        PdfPTable tab4 = new PdfPTable(2);
        tab4.setWidthPercentage(100);
        tab4.setWidths(new float[] { 30, 70 });

        PdfPCell cell2 = createCell(theader + " No.", FontContext.TABLE_HEADER, Element.ALIGN_LEFT, 0, 5);
        tab4.addCell(cell2);
        //                String invno = mode != StaticValues.AUTONUM_BILLINGINVOICE ? inv.getInvoiceNumber() : inv1.getBillingInvoiceNumber();
        cell2 = createCell(": " + invno, FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, 5);
        tab4.addCell(cell2);

        cell2 = createCell("DATE  ", FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0, 5);
        tab4.addCell(cell2);
        cell2 = createCell(": " + formatter.format(entryDate), FontContext.SMALL_TEXT, Element.ALIGN_LEFT, 0,
                5);
        tab4.addCell(cell2);

        PdfPCell cell1 = new PdfPCell(tab3);
        cell1.setBorder(0);
        userTable2.addCell(cell1);
        cel2 = new PdfPCell(tab4);
        cel2.setBorder(0);
        userTable2.addCell(cel2);

        PdfPCell mainCell12 = new PdfPCell(userTable2);
        mainCell12.setBorder(0);
        mainCell12.setPadding(10);
        mainTable.addCell(mainCell12);

        PdfPTable tab5 = new PdfPTable(2);
        tab5.setWidthPercentage(100);
        tab5.setWidths(new float[] { 50, 50 });
        PdfPCell cell3 = createCell("To, ", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5);
        tab5.addCell(cell3);
        cell3 = createCell("", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 0);
        tab5.addCell(cell3);
        //                cell3 = createCell("", fontRegularNormal, Element.ALIGN_LEFT, 0, 0);
        //                tab5.addCell(cell3);

        cell3 = createCell(customerName, FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5);
        tab5.addCell(cell3);
        cell3 = createCell("", FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 0);
        tab5.addCell(cell3);
        cell3 = createCell(shipTo, FontContext.TABLE_DATA, Element.ALIGN_LEFT, 0, 5);
        tab5.addCell(cell3);

        PdfPCell mainCell14 = new PdfPCell(tab5);
        mainCell14.setBorder(0);
        //mainCell14.setPadding(10);
        mainTable.addCell(mainCell14);
        getHtmlCell(preText.trim(), mainTable, baseUrl);
        getHtmlCell("<br>", mainTable, baseUrl);
        getHtmlCell("<br>", mainTable, baseUrl);
        String[] header = { "S.No.", "PRODUCT", "DESCRIPTION", "QUANTITY", "UNIT PRICE", "DISCOUNT", "TAX",
                "LINE TOTAL" };
        PdfPTable table = getBlankTable();
        PdfPCell invcell = null;

        for (int i = 0; i < header.length; i++) {
            invcell = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(header[i], FontContext.TABLE_HEADER)));
            invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            invcell.setBackgroundColor(Color.LIGHT_GRAY);
            invCell.setBorder(0);
            invcell.setPadding(3);
            table.addCell(invcell);
        }
        addTableRow(mainTable, table); //Break table after adding header row
        table = getBlankTable();

        String prodName = "";
        String subtotal = "";
        String quantity = "";
        String rate = "";
        String description = "";
        String discount = "";
        String prodtax = "";
        int index = 0;
        double total = 0;
        for (int cnt = 0; cnt < productDetails.length(); cnt++) {
            JSONObject productInfo = productDetails.getJSONObject(cnt);
            prodName = productInfo.getString("productname");
            description = productInfo.getString("description");
            quantity = productInfo.getString("quantity");
            rate = productInfo.getString("orderrate");
            subtotal = productInfo.getString("amount");
            discount = productInfo.getString("prdiscountamount");
            prodtax = productInfo.getString("taxamount");

            invcell = createCell((++index) + ".", FontContext.TABLE_DATA, Element.ALIGN_RIGHT,
                    Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(prodName, FontContext.TABLE_DATA, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(description, FontContext.TABLE_DATA, Element.ALIGN_LEFT,
                    Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(quantity, FontContext.TABLE_DATA, Element.ALIGN_CENTER,
                    Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(currencyRender(rate, currencyObj), FontContext.TABLE_DATA, Element.ALIGN_RIGHT,
                    Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(currencyRender(subtotal, currencyObj), FontContext.TABLE_DATA,
                    Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(currencyRender(prodtax, currencyObj), FontContext.TABLE_DATA,
                    Element.ALIGN_CENTER, Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);
            invcell = createCell(currencyRender(subtotal, currencyObj), FontContext.TABLE_DATA,
                    Element.ALIGN_RIGHT, Rectangle.LEFT + Rectangle.RIGHT, 5);
            table.addCell(invcell);

            total += Double.valueOf(subtotal);

            addTableRow(mainTable, table); //Break table after adding detail's row
            table = getBlankTable();
        }

        for (int j = 0; j < 98; j++) {
            invcell = new PdfPCell(new Paragraph(fontFamilySelector.process("", FontContext.TABLE_DATA)));//fontRegularBold));
            invcell.setHorizontalAlignment(Element.ALIGN_CENTER);
            invcell.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
            table.addCell(invcell);
        }
        addTableRow(mainTable, table); //Break table after adding extra space
        table = getBlankTable();

        cell3 = createCell("SUB TOTAL", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, Rectangle.TOP, 5);
        cell3.setColspan(7);
        table.addCell(cell3);

        cell3 = createCell(currencyRender(String.valueOf(total), currencyObj), FontContext.TABLE_DATA,
                Element.ALIGN_RIGHT, 15, 5);
        table.addCell(cell3);

        cell3 = createCell("DISCOUNT(-)", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5);
        cell3.setColspan(7);
        table.addCell(cell3);
        cell3 = calculateDiscount(quotationDisc, currencyObj);
        table.addCell(cell3);

        StringBuffer taxNameStr = new StringBuffer();
        if (!StringUtil.isNullOrEmpty(quotationtaxname)) {
            taxNameStr.append(quotationtaxname);
            taxNameStr.append(" ");
            taxNameStr.append(quotationtaxpercent);
            taxNameStr.append("% (+)");
        } else {
            taxNameStr.append("TAX (+)");
        }
        cell3 = createCell(taxNameStr.toString(), FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5);
        cell3.setColspan(7);
        table.addCell(cell3);
        cell3 = createCell(currencyRender(String.valueOf(quotationtaxamount), currencyObj),
                FontContext.TABLE_DATA, Element.ALIGN_RIGHT, 15, 5);
        table.addCell(cell3);

        cell3 = createCell("TOTAL", FontContext.NOTE_TEXT, Element.ALIGN_RIGHT, 0, 5);
        cell3.setColspan(7);
        table.addCell(cell3);
        cell3 = createCell(currencyRender(String.valueOf(totalAmount), currencyObj), FontContext.TABLE_DATA,
                Element.ALIGN_RIGHT, 15, 5);
        table.addCell(cell3);

        addTableRow(mainTable, table);

        String netinword = EnglishNumberToWordsOjb.convert(Double.parseDouble(String.valueOf(totalAmount)),
                currencyObj);
        String currencyname = currencyObj.getName();

        cell3 = createCell("Amount (in words) : " + currencyname + " " + netinword + " Only.",
                FontContext.HEADER_NOTE, Element.ALIGN_LEFT,
                Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM + Rectangle.TOP, 5);

        PdfPTable table2 = new PdfPTable(1);
        table2.addCell(cell3);
        PdfPCell mainCell62 = new PdfPCell(table2);
        mainCell62.setBorder(0);
        mainCell62.setPadding(10);
        mainTable.addCell(mainCell62);

        PdfPTable helpTable = new PdfPTable(new float[] { 8, 92 });
        helpTable.setWidthPercentage(100);
        Phrase phrase1 = fontFamilySelector.process("Memo:  ", FontContext.NOTE_TEXT);
        Phrase phrase2 = fontFamilySelector.process(memo, FontContext.TABLE_DATA);//fontRegularBold);
        PdfPCell pcell1 = new PdfPCell(phrase1);
        PdfPCell pcell2 = new PdfPCell(phrase2);
        pcell1.setBorder(0);
        pcell1.setPadding(10);
        pcell1.setPaddingRight(0);
        pcell2.setBorder(0);
        pcell2.setPadding(10);
        helpTable.addCell(pcell1);
        helpTable.addCell(pcell2);

        PdfPCell mainCell61 = new PdfPCell(helpTable);
        mainCell61.setBorder(0);
        mainTable.addCell(mainCell61);
        getHtmlCell("<br>", mainTable, baseUrl);
        getHtmlCell("<br>", mainTable, baseUrl);
        getHtmlCell(postText.trim(), mainTable, baseUrl);
        document.add(mainTable);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.krawler.spring.hrms.payroll.payslip.ExportPayslipController.java

License:Open Source License

public ModelAndView exportPDF(HttpServletRequest request, HttpServletResponse response) {
    JSONObject jsonResp = new JSONObject();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = null;/*from   w  w w  .  j ava2 s .c  om*/
    try {

        Company company = (Company) kwlCommonTablesDAOObj.getObject("com.krawler.common.admin.Company",
                sessionHandlerImplObj.getCompanyid(request));
        int i = 0;
        DecimalFormat decfm = new DecimalFormat("#,##0.00");
        Date d2 = null;
        Date d3 = null;
        int days = 0;
        boolean showborder = true;
        if (!StringUtil.isNullOrEmpty(request.getParameter("showborder"))) {
            showborder = Boolean.parseBoolean(request.getParameter("showborder"));
        }
        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy");
        String stDate = request.getParameter("stdate").replace("/", "-");
        String endDate = request.getParameter("enddate").replace("/", "-");
        d2 = sdf.parse(stDate);
        d3 = sdf.parse(endDate);

        days = getWorkingDays(request.getParameter("stdate").replace("/", "-"),
                request.getParameter("enddate").replace("/", "-"), company.getCompanyID());

        String historyid = "";

        List<Payhistory> lst = exportPayslipDAO.getPayhistory(request.getParameter("empid"), d2, d3);
        ;
        if (lst != null && lst.size() == 0) {
            throw new Exception("Exception occured");
        } else if (lst != null && lst.size() > 0) {
            String currSymbol = getCurrencySymbol(request, false);
            masterDB.Payhistory payhistory = (masterDB.Payhistory) lst.get(0);
            historyid = payhistory.getHistoryid();
            double unpaidleaves = payhistory.getUnpaidleaves();

            Document document = new Document(PageSize.A4, 15, 15, 15, 15);
            writer = PdfWriter.getInstance(document, baos);
            writer.setPageEvent(new EndPage(request));
            document.open();

            String userid = request.getParameter("empid");

            User userinfo = payhistory.getUserID();
            Useraccount ua = (Useraccount) kwlCommonTablesDAOObj
                    .getObject("com.krawler.common.admin.Useraccount", userinfo.getUserID());
            String uname = userinfo.getLastName() != null ? userinfo.getLastName() : "";
            String empid = getUserCode(ua, company.getCompanyID());

            String department = payhistory.getDepartment();
            String designation = getUserDesignation(ua);
            String bankacc = ua.getAccno() != null ? ua.getAccno() : "";
            Empprofile empprof = null;
            String epf = "";
            String dateofjoin = "";
            try {
                empprof = (Empprofile) kwlCommonTablesDAOObj.getObject("com.krawler.hrms.ess.Empprofile",
                        userid);
                epf = StringUtil.isNullOrEmpty(empprof.getPfno()) ? "" : empprof.getPfno();
                dateofjoin = empprof.getJoindate() != null ? empprof.getJoindate().toString() : "";
            } catch (Exception ex) {
                epf = "";
            }
            PdfPTable mainTable = new PdfPTable(1);
            mainTable.setWidthPercentage(100);
            PdfPTable table1 = new PdfPTable(3);
            table1.setWidthPercentage(100);
            table1.setWidths(new float[] { 40, 40, 20 });
            PdfPTable userTable1 = new PdfPTable(1);
            String cmpid = AuthHandler.getCompanyid(request);
            userTable1.setHorizontalAlignment(Element.ALIGN_MIDDLE);
            userTable1.setWidthPercentage(10);
            PdfPCell cell11 = null;

            PdfPCell cell1x = new PdfPCell(
                    new Paragraph(fontFamilySelector.process("  ", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN)));
            cell1x.setBorder(0);
            userTable1.addCell(cell1x);
            try {
                String imgPath = StorageHandler.GetProfileImgStorePath() + cmpid + ".png";

                if (StringUtil.isStandAlone()) {
                    imgPath = URLUtil.getPageURL(request, "").concat(ProfileImageServlet.defaultCompanyImgPath);
                }

                Image img = Image.getInstance(imgPath);
                cell11 = new PdfPCell(img);
                cell11.setPaddingLeft(5);
            } catch (Exception e) {
                cell11 = new PdfPCell(new Paragraph(fontFamilySelector
                        .process(AuthHandler.getCompanyName(request), FontContext.TABLE_BOLD_TIMES_NEW_ROMAN)));
                cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
            }
            if (cell11 != null) {
                cell11.setBorder(0);
                userTable1.addCell(cell11);
            }

            PdfPCell cell1 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process("", FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN)));
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell1.setBorder(0);
            userTable1.addCell(cell1);

            PdfPTable userTable2 = new PdfPTable(1);
            userTable2.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getCompanyName(),
                    FontContext.REGULAR_BOLD_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            cell.setPaddingTop(15);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(company.getCity(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getAddress(),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(company.getState(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(new Paragraph(fontFamilySelector.process(company.getZipCode(),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);
            cell = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.payslip.period.params",
                                    new Object[] { request.getParameter("stdate"),
                                            request.getParameter("enddate") },
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell.setBorder(0);
            userTable2.addCell(cell);

            PdfPTable userTable3 = new PdfPTable(1);
            userTable3.setWidthPercentage(100);
            PdfPCell cell2 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process("", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            cell2.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2.setBorder(0);
            userTable1.addCell(cell2);

            PdfPCell mainCell11 = new PdfPCell(userTable1);
            if (!showborder) {
                mainCell11.setBorder(0);
            } else {
                mainCell11.setBorder(Rectangle.LEFT);
            }

            table1.addCell(mainCell11);
            PdfPCell mainCell13 = new PdfPCell(userTable2);
            mainCell13.setBorder(0);
            table1.addCell(mainCell13);
            PdfPCell mainCell15 = new PdfPCell(userTable3);
            if (!showborder) {
                mainCell15.setBorder(0);
            } else {
                mainCell15.setBorder(Rectangle.RIGHT);
            }
            table1.addCell(mainCell15);

            PdfPCell mainCell12 = new PdfPCell(new Paragraph(""));
            if (!showborder) {
                mainCell12.setBorder(0);
            } else {
                mainCell12.setBorder(Rectangle.LEFT);
            }
            table1.addCell(mainCell12);
            PdfPCell mainCell14 = new PdfPCell(new Paragraph(""));
            mainCell14.setBorder(0);
            table1.addCell(mainCell14);
            PdfPCell mainCell16 = new PdfPCell(new Paragraph(""));
            if (!showborder) {
                mainCell16.setBorder(0);
            } else {
                mainCell16.setBorder(Rectangle.RIGHT);
            }
            table1.addCell(mainCell16);

            PdfPCell mainCell1 = new PdfPCell(table1);
            if (!showborder) {
                mainCell1.setBorder(0);
            } else {
                mainCell1.setBorder(1);
            }
            mainTable.addCell(mainCell1);
            // __________________________________________________________________________
            PdfPTable table2 = new PdfPTable(4);
            table2.setWidthPercentage(100);
            table2.setWidths(new float[] { 20, 30, 20, 30 });

            PdfPCell h11 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.employee.code", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h11.setHorizontalAlignment(Element.ALIGN_LEFT);
            h11.setPadding(5);
            if (!showborder) {
                h11.setBorder(0);
            }
            table2.addCell(h11);
            PdfPCell h12 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process("" + empid, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h12.setHorizontalAlignment(Element.ALIGN_LEFT);
            h12.setPadding(5);
            if (!showborder) {
                h12.setBorder(0);
            }
            table2.addCell(h12);
            PdfPCell h13 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.employee.name", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h13.setHorizontalAlignment(Element.ALIGN_LEFT);
            h13.setPadding(5);
            if (!showborder) {
                h13.setBorder(0);
            }
            table2.addCell(h13);
            PdfPCell h14 = new PdfPCell(new Paragraph(fontFamilySelector
                    .process(userinfo.getFirstName() + " " + uname, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h14.setHorizontalAlignment(Element.ALIGN_LEFT);
            h14.setPadding(5);
            if (!showborder) {
                h14.setBorder(0);
            }
            table2.addCell(h14);

            PdfPCell h21 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.department", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h21.setHorizontalAlignment(Element.ALIGN_LEFT);
            h21.setPadding(5);
            if (!showborder) {
                h21.setBorder(0);
            }
            table2.addCell(h21);
            PdfPCell h22 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(department, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h22.setHorizontalAlignment(Element.ALIGN_LEFT);
            h22.setPadding(5);
            if (!showborder) {
                h22.setBorder(0);
            }
            table2.addCell(h22);
            PdfPCell h33 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.designation", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h33.setHorizontalAlignment(Element.ALIGN_LEFT);
            h33.setPadding(5);
            if (!showborder) {
                h33.setBorder(0);
            }
            table2.addCell(h33);
            PdfPCell h34 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(designation, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h34.setHorizontalAlignment(Element.ALIGN_LEFT);
            h34.setPadding(5);
            if (!showborder) {
                h34.setBorder(0);
            }
            table2.addCell(h34);
            PdfPCell h43 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.bank.ac.no", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h43.setHorizontalAlignment(Element.ALIGN_LEFT);
            h43.setPadding(5);
            if (!showborder) {
                h43.setBorder(0);
            }
            table2.addCell(h43);
            PdfPCell h44 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(bankacc, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h44.setHorizontalAlignment(Element.ALIGN_LEFT);
            h44.setPadding(5);
            if (!showborder) {
                h44.setBorder(0);
            }
            table2.addCell(h44);
            PdfPCell h61 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.working.days", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h61.setHorizontalAlignment(Element.ALIGN_LEFT);
            h61.setPadding(5);
            if (!showborder) {
                h61.setBorder(0);
            }
            table2.addCell(h61);
            PdfPCell h62 = new PdfPCell(new Paragraph(fontFamilySelector.process(String.valueOf(days),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h62.setHorizontalAlignment(Element.ALIGN_LEFT);
            h62.setPadding(5);
            if (!showborder) {
                h62.setBorder(0);
            }
            table2.addCell(h62);
            PdfPCell h63 = new PdfPCell(new Paragraph(fontFamilySelector.process(
                    messageSource.getMessage("hrms.common.e.p.f", null, RequestContextUtils.getLocale(request)),
                    FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h63.setHorizontalAlignment(Element.ALIGN_LEFT);
            h63.setPadding(5);
            if (!showborder) {
                h63.setBorder(0);
            }
            table2.addCell(h63);
            PdfPCell h64 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(epf, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h64.setHorizontalAlignment(Element.ALIGN_LEFT);
            h64.setPadding(5);
            if (!showborder) {
                h64.setBorder(0);
            }
            table2.addCell(h64);
            PdfPCell h65 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.common.DateofJoining", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            h65.setHorizontalAlignment(Element.ALIGN_LEFT);
            h65.setPadding(5);
            if (!showborder) {
                h65.setBorder(0);
            }
            table2.addCell(h65);
            PdfPCell h66 = new PdfPCell(new Paragraph(
                    fontFamilySelector.process(dateofjoin, FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            h66.setHorizontalAlignment(Element.ALIGN_LEFT);
            h66.setPadding(5);
            if (!showborder) {
                h66.setBorder(0);
            }
            table2.addCell(h66);

            for (int y = 0; y < 2; y++) {
                PdfPCell h71 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    h71.setBorder(0);
                } else {
                    h71.setBorder(Rectangle.LEFT);
                }
                table2.addCell(h71);
                for (i = 0; i < 2; i++) {
                    h71 = new PdfPCell(new Paragraph(
                            fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                    h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                    h71.setBorder(0);
                    table2.addCell(h71);
                }
                h71 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                h71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    h71.setBorder(0);
                } else {
                    h71.setBorder(Rectangle.RIGHT);
                }
                table2.addCell(h71);
            }
            PdfPCell mainCell2 = new PdfPCell(table2);
            if (!showborder) {
                mainCell2.setBorder(0);
            } else {
                mainCell2.setBorder(1);
            }
            mainTable.addCell(mainCell2);

            PdfPTable table3main = new PdfPTable(1);
            table3main.setWidthPercentage(100);
            PdfPTable table7main = new PdfPTable(1);
            table7main.setWidthPercentage(100);

            PdfPTable table31 = new PdfPTable(4);
            table31.setWidthPercentage(100);
            table31.setWidths(new float[] { 30, 20, 30, 20 });
            PdfPTable table41 = new PdfPTable(2);
            table41.setWidthPercentage(100);
            table41.setWidths(new float[] { 50, 50 });

            //***************************************************************************************************************
            PdfPCell s11 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.Earnings", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s11.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s11.setBorder(0);
            } else {
                s11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            s11.setPadding(5);
            table31.addCell(s11);
            PdfPCell s12 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol },
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s12.setHorizontalAlignment(Element.ALIGN_RIGHT);
            s12.setPadding(5);
            if (!showborder) {
                s12.setBorder(0);
            } else {
                s12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            table31.addCell(s12);
            PdfPCell s14 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.Deduction", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s14.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s14.setBorder(0);
            } else {
                s14.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            s14.setPadding(5);
            table31.addCell(s14);
            PdfPCell s15 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol },
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s15.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s15.setBorder(0);
            } else {
                s15.setBorder(Rectangle.LEFT + Rectangle.RIGHT + Rectangle.BOTTOM);
            }
            s15.setPadding(5);
            table31.addCell(s15);
            int Wcount = 0;
            float taxtotal = 0;

            List<Historydetail> lst1 = exportPayslipDAO.getHistorydetail(historyid, "Wages", "Basic");
            List<Historydetail> list = exportPayslipDAO.getHistorydetailNotType(historyid, "Wages", "Basic");
            if (list != null) {
                lst1.addAll(list);
            }

            List<Historydetail> lst2 = exportPayslipDAO.getHistorydetail(historyid, "Taxes");

            CompanyPreferences cp = hrmsCommonDAOObj.getCompanyPreferences(company.getCompanyID());
            int financialMonth = cp.getFinancialmonth();
            Calendar c1 = Calendar.getInstance();
            c1.setTime(d3);
            c1.set(Calendar.MONTH, financialMonth);
            c1.set(Calendar.DATE, 1);
            Date d = c1.getTime();
            Date DOJ = new java.util.Date(empprof.getJoindate().getTime());
            if (d3.before(d)) {
                int currentYear = c1.get(Calendar.YEAR) - 1;
                c1.set(Calendar.YEAR, currentYear);
                d = c1.getTime();
            }
            if (DOJ.after(d)) {
                c1.setTime(DOJ);
                c1.set(Calendar.DATE, 1);
                d = c1.getTime();
            }
            List<Historydetail> lst3 = exportPayslipDAO.getHistorydetail(historyid, "Deduction");
            int size = lst1.size() > (lst2.size() + lst3.size()) ? lst1.size() : lst2.size() + lst3.size();
            float wagetotal = 0;
            double totalYTDEarning = 0, totalYTDDeduction = 0;
            for (i = 0; i < size; i++) {
                masterDB.Historydetail hd = null;
                if (i < lst1.size()) {
                    hd = (masterDB.Historydetail) lst1.get(i);
                    PdfPCell s21 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(),
                            FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                    s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                    if (!showborder) {
                        s21.setBorder(0);
                    } else {
                        s21.setBorder(Rectangle.LEFT);
                    }
                    s21.setPadding(5);
                    table31.addCell(s21);

                    BigDecimal bd = new BigDecimal(hd.getAmount());
                    bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                    double newamount = bd.doubleValue();

                    PdfPCell s22 = new PdfPCell(
                            new Paragraph(fontFamilySelector.process(String.valueOf(decfm.format(newamount)),
                                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                    s22.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    if (!showborder) {
                        s22.setBorder(0);
                    } else {
                        s22.setBorder(Rectangle.LEFT);
                    }
                    s22.setPadding(5);
                    table31.addCell(s22);

                    List<Historydetail> lstw = exportPayslipDAO.getHistorydetail(request.getParameter("empid"),
                            d, d3, hd.getType());
                    double wageAmt = 0;
                    masterDB.Historydetail hd1 = null;
                    for (int y = 0; y < lstw.size(); y++) {
                        hd1 = (masterDB.Historydetail) lstw.get(y);
                        wageAmt += Double.parseDouble(hd1.getAmount());
                    }
                    wagetotal = wagetotal + Float.parseFloat(hd.getAmount());
                    totalYTDEarning = totalYTDEarning + wageAmt;
                    Wcount++;
                } else {
                    for (int j = 0; j < 2; j++) {
                        PdfPCell s21 = new PdfPCell(new Paragraph(
                                fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                        s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                        if (!showborder) {
                            s21.setBorder(0);
                        } else {
                            s21.setBorder(Rectangle.LEFT);
                        }
                        s21.setPadding(5);
                        table31.addCell(s21);
                    }
                }
                if (i < lst2.size()) {
                    hd = (masterDB.Historydetail) lst2.get(i);
                    PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(),
                            FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                    s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                    if (!showborder) {
                        s24.setBorder(0);
                    } else {
                        s24.setBorder(Rectangle.LEFT);
                    }
                    s24.setPadding(5);
                    table31.addCell(s24);

                    BigDecimal bd = new BigDecimal(hd.getAmount());
                    bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                    double newamount = bd.doubleValue();

                    PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector
                            .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                    s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                    if (!showborder) {
                        s25.setBorder(0);
                    } else {
                        s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                    }
                    s25.setPadding(5);
                    table31.addCell(s25);

                    List<Historydetail> lstw1 = exportPayslipDAO.getHistorydetail(request.getParameter("empid"),
                            d, d3, hd.getType());
                    double taxAmt = 0;
                    masterDB.Historydetail hd2 = null;
                    for (int y = 0; y < lstw1.size(); y++) {
                        hd2 = (masterDB.Historydetail) lstw1.get(y);
                        taxAmt += Double.parseDouble(hd2.getAmount());
                    }
                    taxtotal = taxtotal + Float.parseFloat(hd.getAmount());
                    totalYTDDeduction = totalYTDDeduction + taxAmt;
                } else {
                    if (i - lst2.size() < lst3.size()) {
                        hd = (masterDB.Historydetail) lst3.get(i - lst2.size());
                        PdfPCell s24 = new PdfPCell(new Paragraph(fontFamilySelector.process(hd.getType(),
                                FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                        if (hd.getType().equals("Unpaid_leaves")) {
                            s24 = new PdfPCell(new Paragraph(
                                    fontFamilySelector.process(hd.getType() + "(" + unpaidleaves + ")",
                                            FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                        }
                        s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                        if (!showborder) {
                            s24.setBorder(0);
                        } else {
                            s24.setBorder(Rectangle.LEFT);
                        }
                        s24.setPadding(5);
                        table31.addCell(s24);

                        BigDecimal bd = new BigDecimal(hd.getAmount());
                        bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                        double newamount = bd.doubleValue();

                        PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector
                                .process(decfm.format(newamount), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                        s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                        if (!showborder) {
                            s25.setBorder(0);
                        } else {
                            s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                            ;
                        }
                        s25.setPadding(5);
                        table31.addCell(s25);

                        List<Historydetail> lstw2 = exportPayslipDAO
                                .getHistorydetail(request.getParameter("empid"), d, d3, hd.getType());
                        masterDB.Historydetail hd3 = null;
                        double deductAmt = 0;
                        for (int y = 0; y < lstw2.size(); y++) {
                            hd3 = (masterDB.Historydetail) lstw2.get(y);
                            deductAmt += Double.parseDouble(hd3.getAmount());
                        }

                        taxtotal = taxtotal + Float.parseFloat(hd.getAmount());
                        totalYTDDeduction = totalYTDDeduction + deductAmt;
                    } else {
                        for (int j = 0; j < 2; j++) {
                            PdfPCell s21 = new PdfPCell(new Paragraph(
                                    fontFamilySelector.process("", FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                            s21.setHorizontalAlignment(Element.ALIGN_LEFT);
                            if (!showborder) {
                                s21.setBorder(0);
                            } else {
                                s21.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                            }
                            s21.setPadding(5);
                            table31.addCell(s21);
                        }
                    }
                }
            }
            PdfPCell s91 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.total.earnings", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s91.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s91.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s91.setBorder(0);
            } else {
                s91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s91.setPadding(5);
            table31.addCell(s91);
            BigDecimal bd = new BigDecimal(String.valueOf(wagetotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            double newamount = bd.doubleValue();
            PdfPCell s92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            s92.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s92.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s92.setBorder(0);
            } else {
                s92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s92.setPadding(5);
            table31.addCell(s92);
            PdfPCell s94 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.total.deductions", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            s94.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s94.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                s94.setBorder(0);
            } else {
                s94.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s94.setPadding(5);
            table31.addCell(s94);
            bd = new BigDecimal(String.valueOf(taxtotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            newamount = bd.doubleValue();
            PdfPCell s95 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            s95.setHorizontalAlignment(Element.ALIGN_BASELINE);
            s95.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                s95.setBorder(0);
            } else {
                s95.setBorder(Rectangle.RIGHT + Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            s95.setPadding(5);
            table31.addCell(s95);
            for (int y = 0; y < 2; y++) {
                PdfPCell he71 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    he71.setBorder(0);
                } else {
                    he71.setBorder(Rectangle.LEFT);
                }
                table31.addCell(he71);
                for (i = 0; i < 2; i++) {
                    he71 = new PdfPCell(new Paragraph(
                            fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                    he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                    he71.setBorder(0);
                    table31.addCell(he71);
                }
                he71 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                he71.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    he71.setBorder(0);
                } else {
                    he71.setBorder(Rectangle.RIGHT);
                }
                table31.addCell(he71);
            }

            List<Historydetail> lst4 = exportPayslipDAO.getHistorydetail(historyid, "Employer Contribution");
            double ectotal = 0;
            PdfPCell ec11 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.EmployerContribution", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            ec11.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                ec11.setBorder(0);
            } else {
                ec11.setBorder(Rectangle.LEFT + Rectangle.BOTTOM);
            }
            ec11.setPadding(5);
            table41.addCell(ec11);
            PdfPCell ec12 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.amount.params", new Object[] { currSymbol },
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            ec12.setHorizontalAlignment(Element.ALIGN_RIGHT);
            ec12.setPadding(5);
            if (!showborder) {
                ec12.setBorder(0);
            } else {
                ec12.setBorder(Rectangle.LEFT + Rectangle.BOTTOM + Rectangle.RIGHT);
            }
            table41.addCell(ec12);
            masterDB.Historydetail hd1 = null;
            for (i = 0; i < lst4.size(); i++) {
                hd1 = (masterDB.Historydetail) lst4.get(i);
                PdfPCell s24 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process(hd1.getType(), FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                s24.setHorizontalAlignment(Element.ALIGN_LEFT);
                if (!showborder) {
                    s24.setBorder(0);
                } else {
                    s24.setBorder(Rectangle.LEFT);
                }
                s24.setPadding(5);
                table41.addCell(s24);
                bd = new BigDecimal(hd1.getAmount());
                bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
                newamount = bd.doubleValue();
                ectotal = ectotal + newamount;

                PdfPCell s25 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount),
                        FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
                s25.setHorizontalAlignment(Element.ALIGN_RIGHT);
                if (!showborder) {
                    s25.setBorder(0);
                } else {
                    s25.setBorder(Rectangle.RIGHT + Rectangle.LEFT);
                }
                s25.setPadding(5);
                table41.addCell(s25);
            }

            PdfPCell se91 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.total.contribution", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            se91.setHorizontalAlignment(Element.ALIGN_BASELINE);
            se91.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                se91.setBorder(0);
            } else {
                se91.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM);
            }
            se91.setPadding(5);
            table41.addCell(se91);
            bd = new BigDecimal(String.valueOf(ectotal));
            bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
            newamount = bd.doubleValue();
            PdfPCell se92 = new PdfPCell(new Paragraph(fontFamilySelector.process(decfm.format(newamount),
                    FontContext.SMALL_NORMAL_TIMES_NEW_ROMAN)));
            se92.setHorizontalAlignment(Element.ALIGN_BASELINE);
            se92.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                se92.setBorder(0);
            } else {
                se92.setBorder(Rectangle.LEFT + Rectangle.TOP + Rectangle.BOTTOM + Rectangle.RIGHT);
            }
            se92.setPadding(5);
            table41.addCell(se92);

            PdfPCell Cell31 = new PdfPCell(table31);
            if (!showborder) {
                Cell31.setBorder(0);
            } else {
                Cell31.setBorder(1);
            }
            table3main.addCell(Cell31);

            PdfPCell mainCell4 = new PdfPCell(table3main);
            if (!showborder) {
                mainCell4.setBorder(0);
            } else {
                mainCell4.setBorder(1);
            }
            mainTable.addCell(mainCell4);

            PdfPCell Cell41 = new PdfPCell(table41);
            if (!showborder) {
                Cell41.setBorder(0);
            } else {
                Cell41.setBorder(1);
            }
            table7main.addCell(Cell41);

            PdfPCell mainCell44 = new PdfPCell(table7main);
            if (!showborder) {
                mainCell44.setBorder(0);
            } else {
                mainCell44.setBorder(1);
            }
            mainTable.addCell(mainCell44);

            //***************************************************************************************************************

            PdfPTable table4 = new PdfPTable(2);
            table4.setWidthPercentage(100);
            for (i = 0; i < 4; i++) {
                PdfPCell i33 = new PdfPCell(new Paragraph(
                        fontFamilySelector.process("  ", FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
                i33.setHorizontalAlignment(Element.ALIGN_CENTER);
                if (!showborder) {
                    i33.setBorder(0);
                } else {
                    i33.setBorder(Rectangle.LEFT + Rectangle.RIGHT);
                }
                table4.addCell(i33);
            }

            PdfPCell i31 = new PdfPCell(new Paragraph(fontFamilySelector.process(
                    messageSource.getMessage("hrms.payroll.netpay", null,
                            RequestContextUtils.getLocale(request)) + " ",
                    FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            i31.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i31.setBorder(0);
            } else {
                i31.setBorder(Rectangle.LEFT + Rectangle.TOP);
            }
            i31.setPadding(5);
            table4.addCell(i31);
            double netpay = 0;
            netpay = wagetotal - taxtotal;
            netpay = Math.round(netpay);
            String amount = numberFormatter((double) netpay, currSymbol);
            PdfPCell i33 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(amount, FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            i33.setHorizontalAlignment(Element.ALIGN_RIGHT);
            if (!showborder) {
                i33.setBorder(0);
            } else {
                i31.setBorder(Rectangle.RIGHT);
            }
            i33.setPadding(5);
            table4.addCell(i33);

            PdfPCell i32 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.in.words", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            i32.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i32.setBorder(0);
            } else {
                i31.setBorder(Rectangle.LEFT);
            }
            i32.setPadding(5);
            table4.addCell(i32);
            EnglishNumberToWords enw = new EnglishNumberToWords(request, messageSource);
            String netinword = enw.convert(netpay);
            PdfPCell i34 = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.only",
                                    new Object[] { getCurrencyName(request), netinword },
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            i34.setHorizontalAlignment(Element.ALIGN_LEFT);
            if (!showborder) {
                i34.setBorder(0);
            } else {
                i31.setBorder(Rectangle.RIGHT);
            }
            i34.setPadding(5);
            table4.addCell(i34);

            PdfPCell mainCell5 = new PdfPCell(table4);
            if (!showborder) {
                mainCell5.setBorder(0);
            } else {
                mainCell5.setBorder(1);
            }
            mainTable.addCell(mainCell5);

            document.add(new Paragraph("\n\n"));

            PdfPTable table5 = new PdfPTable(2);
            table5.setWidthPercentage(80);
            cell = new PdfPCell(new Paragraph("___________________________"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(new Paragraph("___________________________"));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.employee.signature", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);
            cell = new PdfPCell(
                    new Paragraph(fontFamilySelector.process(
                            messageSource.getMessage("hrms.payroll.manager.signature", null,
                                    RequestContextUtils.getLocale(request)),
                            FontContext.SMALL_BOLD_TIMES_NEW_ROMAN)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBorder(0);
            table5.addCell(cell);

            document.add(mainTable);
            document.close();
        }

        String filename = "Employee_Payslip.pdf";
        if (!StringUtil.isNullOrEmpty(request.getParameter("reportname"))) {
            String temp = request.getParameter("reportname");
            filename = temp.lastIndexOf(".pdf") >= 0 ? temp : temp + ".pdf";
        }
        response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
        response.setContentType("application/octet-stream");
        response.setContentLength(baos.size());
        response.getOutputStream().write(baos.toByteArray());

        jsonResp.put("valid", true);
        jsonResp.put("data", "");
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (response.getOutputStream() != null) {
                response.getOutputStream().flush();
                response.getOutputStream().close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        writer.close();
    }
    return new ModelAndView("jsonView", "model", jsonResp.toString());
}

From source file:com.logiware.accounting.reports.ArDisputeReportCreator.java

private void writeContent() throws Exception {
    List<ReportBean> disputeList = new ArReportsDAO().getDisputeList(arReportsForm);
    contentTable = new PdfPTable(9);
    contentTable.setWidthPercentage(100);
    contentTable.setWidths(new float[] { 10, 22, 8, 12, 10, 10, 8, 10, 10 });
    contentTable/*from  ww  w  . j av a 2  s . c o  m*/
            .addCell(createHeaderCell("Customer Number", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable
            .addCell(createHeaderCell("Customer Name", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable
            .addCell(createHeaderCell("Invoice Date", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable.addCell(createHeaderCell("Invoice/BL", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable
            .addCell(createHeaderCell("Invoice Amount", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable
            .addCell(createHeaderCell("Invoice Balance", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable
            .addCell(createHeaderCell("Disputed Date", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable.addCell(createHeaderCell("Disputed By", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    contentTable.addCell(createHeaderCell("Disputed To", blackBoldFont8, Element.ALIGN_LEFT, Rectangle.BOTTOM));
    for (ReportBean dispute : disputeList) {
        contentTable.addCell(createTextCell(dispute.getCustomerNumber(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getCustomerName(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getInvoiceDate(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getInvoiceOrBl(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getInvoiceAmount(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getBalance(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getDisputedDate(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getDisputedUser(), blackNormalFont7, Rectangle.BOTTOM));
        contentTable.addCell(createTextCell(dispute.getDisputeSentUser(), blackNormalFont7, Rectangle.BOTTOM));
    }
    document.add(contentTable);
}

From source file:com.sinkluge.reports.contracts.GenSubcontract.java

public void create(Info in, Image toplogo) throws Exception {

    //for the unchecked box
    Image checkbox = Image.getInstance(in.path + "/WEB-INF/images/unchecked.jpg");
    Chunk ch2 = new Chunk(checkbox, -7, -7);
    Phrase checkboxPhrase = new Phrase();
    checkboxPhrase.add(ch2);//from   w  ww. j av  a  2s .c  om

    Font tnr8 = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);

    Image iBox = Image.getInstance(in.path + "/WEB-INF/images/initialsBox.jpg");//(in.path + "/jsp/dev/images/epcologo3.jpg");
    Chunk ch3 = new Chunk(iBox, -3, -3);
    Phrase initialsBoxPhrase = new Phrase();
    initialsBoxPhrase.add(ch3);

    Phrase footerPhrase = new Phrase(
            attr.get("full_name") + ", " + attr.get("address") + ", " + attr.get("city") + ", "
                    + attr.get("state") + " " + attr.get("zip") + "\nPhone: " + attr.get("phone") + "   Fax: "
                    + attr.get("fax") + "   " + attr.get("url") + "   Page: ",
            new Font(Font.TIMES_ROMAN, 7, Font.BOLD | Font.ITALIC));

    HeaderFooter footer = new HeaderFooter(footerPhrase, true);
    footer.setBorder(0);
    footer.setAlignment(Element.ALIGN_CENTER);
    init(40, 40, 40, 40, footer);

    Phrase underLinePhrase = new Phrase(
            "  ___________________________________________________________________________________________  ",
            new Font(Font.TIMES_ROMAN, 10, Font.BOLD));
    int[] twoC = { 30, 70 };
    int[] twoD = { 5, 95 };
    int[] twoF = { 10, 90 };
    int[] twoE = { 25, 75 };
    int[] twoG = { 40, 60 };
    int[] threeD = { 4, 11, 85 };
    int[] threeB = { 70, 15, 15 };
    //int[] threeC = { 47, 5, 48 };
    int[] five = { 18, 25, 14, 18, 25 };

    //blank spacer for keeping tables apart
    Table spacer = new Table(1, 1);
    spacer.setBorderWidth(0);
    //spacer.setDefaultCellBorderWidth(0);
    spacer.setWidth(100);
    spacer.setPadding(0);
    spacer.setSpacing(0);
    Cell blank = new Cell();
    blank.add(new Chunk("", new Font(Font.TIMES_ROMAN, 8, Font.BOLD, new Color(255, 255, 255))));
    blank.setBorderWidth(0);
    //blank.setLeading(0);
    spacer.addCell(blank);

    //start of document
    //document.setFooter(footer);

    //document.setFooter(footer);

    //add image
    Phrase p1 = new Phrase();
    Table table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(2);
    table1.setSpacing(2);
    toplogo.scalePercent(20);
    //Chunk ch1=new Chunk(toplogo, -36, -55);
    //p1.add(ch1);
    Cell cell = new Cell(toplogo);
    cell.setBorderWidth(0);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    table1.addCell(cell);

    document.add(table1);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);
    document.add(spacer);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setLeading(19);
    cell.add(
            new Phrase(title.toUpperCase() + " AGREEMENT BETWEEN CONTRACTOR AND " + cTitle.toUpperCase() + "\n",
                    new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setUseDescender(true);
    cell.setBackgroundColor(Color.lightGray);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setSpacing(0);
    cell = new Cell();
    cell.add(underLinePhrase);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("\nDOCUMENTS CONTAINED HEREIN:\n", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(3, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setWidths(threeD);
    table1.setPadding(0);
    table1.setSpacing(0);
    table1.addCell(blank);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Page 1", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Agreement Declaration", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.add(new Phrase("    Initial boxes below to indicate complete review of this agreement.",
            new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Page 2", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Articles of " + title + " Agreement and Standard Provisions", tnr8));
    cell.add(new Phrase("    Sign the concluding page.", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Exhibit \"A\"", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("List of Contract Documents, Plans, Specifications, Etc.", tnr8));
    cell.setBorder(0);
    //cell.add(new Phrase("    Read and initial each page.", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
    table1.addCell(cell);

    table1.addCell(blank);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Exhibit \"B\"", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(cTitle + "'s Scope of Work", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase("Exhibit \"C\"", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase(cTitle + "'s Special Provisions and Procedure Requirements", tnr8));
    cell.add(new Phrase("    Read and complete \"Release Authorization\" information.",
            new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);
    table1.addCell(blank);
    if (insure) {
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase("Exhibit \"D\"", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);

        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(cTitle + " Cost Breakdown", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.add(new Phrase("    Complete and return with signed contract",
                new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
        cell.setBorder(0);
        table1.addCell(cell);

        table1.addCell(blank);
    }
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.setColspan(2);
    cell.add(new Phrase("NOTE OTHERS HERE:", new Font(Font.TIMES_ROMAN, 8, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);

    document.add(table1);

    table1 = new Table(3);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setWidths(threeB);
    table1.addCell(blank);
    cell = new Cell();
    cell.setColspan(2);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("(Initial) Entire agreement thoroughly reviewed:\n",
            new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);

    cell = new Cell();

    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Contractor: ________", new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(cTitle + ": ________", new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setColspan(3);
    cell.add(underLinePhrase);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("AGREEMENT", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" made as of " + agreementDate, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("BETWEEN", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the Contractor: \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + attr.get("full_name") + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + attr.get("address") + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + attr.get("city") + ", " + attr.get("state") + " " + attr.get("zip"),
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("                (hereinafter known as \"Contractor\")\n",
            new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("AND", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the " + cTitle + ": \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + subName + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + subAddress + "\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + subCityStateZip, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("                (hereinafter known as \"" + cTitle + "\")\n",
            new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("FOR", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the the fixed sum of  " + DocHelper.numberAndText(amount) + " \n",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    //cell.add(new Phrase("     " + amountString + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("FOR", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the Project known as:\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + projectName + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + projectAddress + "\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + projectCityStateZip, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("                (hereinafter known as \"Project\")\n",
            new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("BY", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the Architect:\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + architectName + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + architectAddress + "\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + architectCityStateZip, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("                (hereinafter known as \"Architect\")\n",
            new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    cell.add(new Phrase("FOR", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the Project owner:\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + ownerName + " \n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + ownerAddress + "\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("     " + ownerCityStateZip, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.add(new Phrase("                (hereinafter known as \"Owner\")\n",
            new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("WHEREFORE", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.add(new Phrase(" the Contractor and " + cTitle + " agree as follows:\n\n\n",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);

    document.add(table1);
    /*
          table1 = new Table(1);
          table1.setBorderWidth(0); table1.setWidth(100);
          //table1.setDefaultCellBorder(0);
          table1.setPadding(0);
               
          cell = new Cell();
          cell.setHorizontalAlignment("center");
          cell.setVerticalAlignment("middle");
          //cell.add(new Phrase("\n", new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
          cell.setBorder(Rectangle.BOTTOM | Rectangle.TOP);
          cell.setBorderWidth(1.1f);
          cell.add(footerPhrase);
          cell.add(new Phrase(" 1\n ",
    new Font(Font.TIMES_ROMAN, 6, Font.NORMAL)));
          //cell.add(footerPhrase2);
                  
          cell.setBorder(0); table1.addCell(cell);
            
          document.add(table1);
    */
    document.newPage();

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(title.toUpperCase() + " AGREEMENT\n", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setBackgroundColor(Color.lightGray);
    cell.setLeading(19);
    cell.setUseDescender(true);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    Paragraph para = new Paragraph(8, "\n\n" + text.toString(), tnr8);

    document.add(para);

    Phrase p;

    document.add(spacer);
    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setWidths(twoC);
    table1.setPadding(0);
    p = new Phrase("Date:\n\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);
    p = new Phrase("Signed:\n\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);

    p = new Phrase("_______________________", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);
    p = new Phrase("_________________________________________________________________",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("            General Contractor                                               Title\n",
            tnr8));
    cell.setBorder(0);
    table1.addCell(cell);

    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setColspan(2);
    cell.add(new Phrase("\nThis " + title
            + " Agreement supercedes all other proposals, documents, and negotiations whether written or verbal\n\n",
            new Font(Font.TIMES_ROMAN, 8, Font.BOLDITALIC)));
    cell.setBorder(0);
    table1.addCell(cell);

    p = new Phrase("Date:\n\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);
    p = new Phrase("Signed:\n\n", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);

    p = new Phrase("_______________________", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);
    p = new Phrase("_________________________________________________________________",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(p);
    cell.setBorder(0);
    table1.addCell(cell);

    table1.addCell(blank);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(
            "            " + cTitle + "                                                       Title\n", tnr8));
    cell.setBorder(0);
    table1.addCell(cell);
    table1.setCellsFitPage(true);
    table1.setTableFitsPage(true);
    document.add(table1);

    document.newPage();

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(cTitle.toUpperCase() + " INFORMATION\n", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setBackgroundColor(Color.lightGray);
    cell.setLeading(19);
    cell.setUseDescender(true);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    document.add(new Phrase("\n"));

    table1 = new Table(5, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(1);
    table1.setWidths(five);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase("Federal I.D. : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(federal_id, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase("(Both Required)", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)));

    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("License Number : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(license_number, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase("Contact : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.setUseDescender(true);
    cell.add(new Phrase(contactName, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Company : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(subName, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Telephone : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.setUseDescender(true);
    cell.add(new Phrase(telephone, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("Fax : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(fax, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");

    cell.add(new Phrase("Mobile phone : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(mobile, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("", new Font(Font.TIMES_ROMAN, 8, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("E-mail : ", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.setBorder(15);
    cell.add(new Phrase(email, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    table1.addCell(cell);
    document.add(table1);

    //document.add(spacer);

    table1 = new Table(1, 1);
    //table1.setBorderWidth(4);
    //table1.setBorderColor(Color.lightGray);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setBorder(0);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    if (insure)
        cell.add(new Phrase("Please attach a COPY of your current state license to this page:",
                new Font(Font.TIMES_ROMAN, 12, Font.NORMAL)));
    else
        cell.add(new Phrase("", new Font(Font.TIMES_ROMAN, 12, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);
    document.add(spacer);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    if (insure)
        cell.add(new Phrase("\n\nAttach\nCopy of\nContractor's\nLicense\nHere\n(If Applicable)",
                new Font(Font.TIMES_ROMAN, 24, Font.NORMAL, Color.lightGray)));
    else
        cell.add(new Phrase("", new Font(Font.TIMES_ROMAN, 24, Font.NORMAL, Color.lightGray)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    //document.setMargins(72, 72, 36, 36);
    document.newPage();

    table1 = new Table(1, 1);
    table1.setOffset(0);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setWidth(100);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(title.toUpperCase() + " EXHIBIT \"A\"\n", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setLeading(6);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell(new Phrase("\n", new Font(Font.TIMES_ROMAN, 8)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("CONTRACT DOCUMENTS, PLANS,\nSPECIFICATIONS, ADDENDUMS, ETC.\n",
            new Font(Font.TIMES_ROMAN, 16, Font.BOLD)));
    cell.setUseDescender(true);
    cell.setLeading(17);
    cell.setBackgroundColor(Color.lightGray);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("\n" + subName
            + " is responsible to verify versions, dates, and completeness of documents that were used in the preparation of the "
            + cTitle + "'s bid proposal before signing this " + title + " Agreement\n", tnr8));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("This " + title + " Agreement includes, but is not limited to the following items:",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setUseDescender(true);
    cell.setBorder(Rectangle.BOTTOM);
    cell.setBorderWidth(0.5f);
    table1.addCell(cell);
    document.add(table1);

    Paragraph prgh = new Paragraph("\n" + bidDocuments + "\n", tnr8);
    prgh.setLeading(10);
    document.add(prgh);

    document.add(spacer);
    /*
     p = new Phrase("\n"+bidDocuments, new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
     p.setLeading(10);
     cell= new Cell(p);
     cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
     cell.setBorderWidth(0.5f);
     //cell.setBorderColor(Color.lightGray);
     cell.setHorizontalAlignment("left");
     cell.setVerticalAlignment("middle");
     //cell.setLeading(10);
     cell.setUseDescender(true);
     table1.addCell(cell);
     */

    table1 = new Table(1, 1);
    table1.setOffset(0);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setWidth(100);
    table1.setTableFitsPage(true);
    p = new Phrase("\nPlease note below all verbal conditions or instructions, if any, that the " + cTitle
            + " has received during the bid process which might affect the scope of work as required by the contract documents",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
    p.setLeading(10);
    cell = new Cell(p);
    cell.setBorder(Rectangle.TOP);
    cell.setBorderWidth(0.5f);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    table1.addCell(cell);

    document.add(table1);

    document.newPage();

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setOffset(0);
    table1.setWidth(100);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(title.toUpperCase() + " EXHIBIT \"B\"\n", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setLeading(6);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell(new Phrase("\n", new Font(Font.TIMES_ROMAN, 8)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase("SCOPE OF WORK\n", new Font(Font.TIMES_ROMAN, 16, Font.BOLD)));
    cell.setBackgroundColor(Color.lightGray);
    cell.setUseDescender(true);
    cell.setLeading(17);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(
            "\nThis " + title + " Agreement includes, but is not limited to the following items:\n\n",
            new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
    cell.setBorder(Rectangle.BOTTOM);
    cell.setBorderWidth(0.5f);
    table1.addCell(cell);

    document.add(table1);

    prgh = new Paragraph("\n" + contractDescription + "\n", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL));
    prgh.setLeading(10);
    document.add(prgh);
    //cell= new Cell(prgh);
    //cell.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
    //cell.setBorderWidth(0.5f);
    //cell.setBorderColor(Color.lightGray);
    //cell.setHorizontalAlignment("left");
    //cell.setVerticalAlignment("middle");
    //cell.setLeading(10);
    //cell.setUseDescender(true);
    //table1.addCell(cell);

    document.add(spacer);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setOffset(0);
    table1.setWidth(100);
    table1.setTableFitsPage(true);

    p = new Phrase("\nAll " + cTitle
            + " bid proposal conditions that are outside of, in addition to or are limiting of conditions contained in the Contract Documents are of no effect and are invalid to the "
            + title + " Agreement unless expressly included in the description above.", tnr8);
    p.setLeading(10);
    cell = new Cell(p);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.setBorder(Rectangle.TOP);
    cell.setBorderWidth(0.5f);
    table1.addCell(cell);

    document.add(table1);

    //document.setMargins(10, 10, 30, 30);

    document.newPage();

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setOffset(0);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(title.toUpperCase() + " EXHIBIT \"C\"\n", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
    cell.setLeading(6);
    cell.setBorder(0);
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell(new Phrase("\n", new Font(Font.TIMES_ROMAN, 8)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("center");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(cTitle.toUpperCase() + " SPECIAL PROVISIONS AND REQUIREMENTS\n",
            new Font(Font.TIMES_ROMAN, 16, Font.BOLD)));
    cell.setBackgroundColor(Color.lightGray);
    cell.setUseDescender(true);
    cell.setLeading(17);
    cell.setBorder(0);
    table1.addCell(cell);

    document.add(table1);

    int count = 1;

    if (insure) {

        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setOffset(4);
        cell = new Cell();
        cell.add(new Phrase("1.     Insurance Provisions (If Applicable)",
                new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
        //cell.setLeading(6);
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
        count++;
        table1 = new Table(2, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setWidths(twoD);
        table1.setOffset(0);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.setLeading(6);
        cell.add(new Phrase(
                "a.  The " + cTitle + " is required to name the following as additional Primary-Insured:",
                tnr8));
        table1.addCell(blank);
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);

        table1 = new Table(2, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setWidths(twoE);
        table1.setOffset(0);
        cell = new Cell();
        cell.setHorizontalAlignment("right");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase("Contractor:  ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(attr.get("full_name"), new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("right");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase("Owner:  ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(ownerName, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("right");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase("Other:  ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase("_______________________________________", tnr8));
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);

        table1 = new Table(2, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setWidths(twoD);
        table1.setOffset(4);
        p = new Phrase("b.  The " + cTitle
                + " must provide verification of current Worker's Compensation coverage with reference to "
                + jobName + " on the policy.", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL));
        p.setLeading(8);
        cell = new Cell(p);
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.setLeading(8);
        table1.addCell(blank);
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
    }

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setOffset(4);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(count + ".     Release Authorizations", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    count++;
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);
    table1 = new Table(2, 1);
    table1.setOffset(4);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setWidths(twoD);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    p = new Phrase(
            "List any Owners, Partners, and/or Corporate Officers who are legally authorized to sign for "
                    + subName
                    + " and who will be signing the MONTHLY REQUEST FOR PAYMENT, FINAL REQUEST FOR PAYMENT, and LIEN WAIVER documents:\n\n",
            tnr8);
    p.setLeading(8);
    p1 = new Phrase(
            "       ______________________________________________________________________          ______________________________________________________________________\n",
            new Font(Font.TIMES_ROMAN, 6, Font.ITALIC));
    //p1.setLeading(0);
    Phrase p2 = new Phrase(
            "       Printed name and title                                                                                                                   Signature\n\n",
            new Font(Font.TIMES_ROMAN, 6, Font.ITALIC));
    //cell.setLeading(8);
    cell.add(p);
    cell.add(p1);
    cell.add(p2);
    cell.add(p1);
    cell.add(p2);
    cell.add(p1);
    cell.add(p2);
    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(3);
    table1.setOffset(0);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(count + ".     Shop Drawings - Samples - Submittals",
            new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);
    count++;

    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setWidths(twoD);
    table1.setOffset(2);
    p = new Phrase(
            "All shop drawings, materials samples, and submittals shall be submitted to the Contractor within 30 days of the issuance of this "
                    + title
                    + " Agreement unless specifically noted below.  All submitted items shall be in number and type as per the contract documents including, but not limited to, the following:",
            tnr8);
    p.setLeading(8);
    cell = new Cell(p);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setWidths(twoF);
    table1.setOffset(4);

    p = new Phrase("--The number of copies of each submittal for " + jobName + " is " + submittal_copies
            + ".\n--All submittals, of any type, are due on or before " + dueDate
            + " unless specifically noted otherwise.\n", tnr8);
    p.setLeading(8);
    cell = new Cell(p);
    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    String submittals = "";
    if (!submittalVector.isEmpty()) {
        p = new Phrase("            Due Date:\n", new Font(Font.TIMES_ROMAN, 8, Font.BOLD));
        p.setLeading(8);
        cell = new Cell(p);
        cell.setColspan(2);
        cell.setBorder(0);
        table1.addCell(cell);
        for (int i = 0; i < submittalVector.size(); i++) {
            submittals += (String) submittalVector.elementAt(i) + "\n";
        }
        p = new Phrase(submittals, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL));
        p.setLeading(8);
        cell = new Cell(p);
        table1.addCell(blank);
        cell.setBorder(0);
        table1.addCell(cell);
    } else {
        p = new Phrase("\nSubmittals required per contract documents and specifications.\n",
                new Font(Font.TIMES_ROMAN, 8, Font.BOLD));
        p.setLeading(8);
        cell = new Cell(p);
        table1.addCell(blank);
        cell.setBorder(0);
        table1.addCell(cell);
    }
    p = new Phrase("\n(" + subName
            + " is responsible for all submittals required in the Contract Documents as pertaining to labor and materials included in the scope of this "
            + title + " Agreement regardless of items listed, not listed, or incorrectly listed above.)",
            new Font(Font.TIMES_ROMAN, 6, Font.ITALIC));
    p.setLeading(8);
    cell = new Cell(p);

    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(1);
    table1.setWidths(twoD);
    table1.setOffset(2);
    p = new Phrase(cTitle.toUpperCase()
            + " acknowledges that review and approval of any type of submittal which deviates from the Project Plans and Specifications does NOT relieve the "
            + cTitle
            + " from costs, penalties and all other remedies required to meet the published specifications where the "
            + cTitle
            + " failed to notify the Owner/Architect/Contractor in writing of the variations from the specifications and failed to obtain written approval for EACH variation from the published specifications.",
            tnr8);
    p.setLeading(8);
    cell = new Cell(p);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(8);
    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(1, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setOffset(2);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    cell.add(new Phrase(count + ".     Project Close-out", new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);
    count++;
    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setOffset(4);
    table1.setWidths(twoD);
    p = new Phrase(
            "All project close-out documents, materials, and Owner-training required by the Contract Documents shall be submitted to the Contractor PRIOR to payment of the "
                    + cTitle
                    + "'s 90% completion payment request.  The requirements shall include, but not be limited to, the following:",
            tnr8);
    p.setLeading(8);
    cell = new Cell(p);
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("middle");
    //cell.setLeading(8);
    table1.addCell(blank);
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    table1 = new Table(2, 1);
    table1.setBorderWidth(0);
    table1.setWidth(100);
    //table1.setDefaultCellBorder(0);
    table1.setPadding(0);
    table1.setOffset(0);
    table1.setWidths(twoG);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("\"O & M\" Submittals: ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(omSubmittals, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("Full Warranty: ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(fullWarranty, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("Up-to-date Lien Release(s): ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(lienReleases, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("Signed Training Form: ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(signedTraining, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("Materials-Equip-Specialty Items: ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(specialtyItems, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("right");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase("Other Items: ", new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    cell = new Cell();
    cell.setHorizontalAlignment("left");
    cell.setVerticalAlignment("top");
    cell.add(new Phrase(otherItems, new Font(Font.TIMES_ROMAN, 8, Font.NORMAL)));
    cell.setBorder(0);
    table1.addCell(cell);
    document.add(table1);

    if (insure) {
        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(3);
        table1.setOffset(2);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(count + ".     " + cTitle + " Safety Program (If Applicable)",
                new Font(Font.TIMES_ROMAN, 10, Font.BOLD)));
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
        table1 = new Table(2, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setOffset(2);
        table1.setWidths(twoD);
        p = new Phrase(
                cTitle + " will submit one copy of the " + cTitle + "'s job-specific safety program to "
                        + attr.get("full_name")
                        + " before any equipment, manpower, or materials are brought onto the Project site.  ",
                tnr8);
        p.setLeading(8);
        cell = new Cell(p);
        p = new Phrase(cTitle + " will require it's " + cTitle.toLowerCase()
                + "s to have in place a job-specific safety program before they enter the Project site.", tnr8);
        p.setLeading(8);
        cell.add(p);
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        //cell.setLeading(8);

        table1.addCell(blank);
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
    }

    if (insure) {
        document.newPage();

        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(3);
        table1.setOffset(0);
        cell = new Cell();
        cell.setHorizontalAlignment("center");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(title.toUpperCase() + " EXHIBIT \"D\"", new Font(Font.TIMES_ROMAN, 20, Font.BOLD)));
        cell.setLeading(6);
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell(new Phrase("\n", new Font(Font.TIMES_ROMAN, 8)));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("center");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(cTitle.toUpperCase() + "'S COST BREAKDOWN\n",
                new Font(Font.TIMES_ROMAN, 16, Font.BOLD)));
        cell.setBackgroundColor(Color.lightGray);
        cell.setUseDescender(true);
        cell.setLeading(17);
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setPadding(0);
        table1.setOffset(2);
        p = new Phrase("The following information is to be supplied by " + subName + " for " + jobName
                + ". List all SUPPLIERS and SUBCONTRACTORS for approval and payment confirmation (attach additional pages if needed):",
                new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
        p.setLeading(12);
        cell = new Cell(p);
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(
                "     Name                                        City                                  Phone                                                                            Estimated Dollar Amount",
                tnr8));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        p = new Phrase(
                "________________________________________________________________________  $___________________\n",
                new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        for (int i = 0; i < 10; i++) {
            cell.add(p);
        }
        cell.setBorder(0);
        table1.addCell(cell);

        p = new Phrase(
                "Supplier accepts full responsibility for acts and omissions of his subcontractors and suppliers.  No suppliers or subcontractors are to be added or deleted without prior notification to "
                        + attr.get("full_name") + ".",
                new Font(Font.TIMES_ROMAN, 8, Font.ITALIC));
        p.setLeading(10);
        cell = new Cell(p);
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.setLeading(15);
        cell.setBorder(0);
        table1.addCell(cell);
        p = new Phrase(
                "List the primary phases of your contracted scope of work and the associated costs.  This information may be released to the Owner if disputes arise over future billings and progress payments.",
                new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
        p.setLeading(12);
        cell = new Cell(p);
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.setLeading(15);
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        cell.add(new Phrase(
                "Description/Phase of Work                     Labor                      Material                    Equipment/Tools       Sub-subcontractor     Total",
                tnr8));
        cell.setBorder(0);
        table1.addCell(cell);
        cell = new Cell();
        p = new Phrase(
                "________________________  $____________ $____________ $____________ $____________ $____________ \n",
                new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
        cell.setHorizontalAlignment("left");
        cell.setVerticalAlignment("middle");
        for (int i = 0; i < 13; i++) {
            cell.add(p);
        }
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);

        document.add(spacer);

        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setOffset(2);
        table1.setPadding(1);
        cell = new Cell();
        cell.setHorizontalAlignment("center");
        cell.setVerticalAlignment("middle");
        //cell.setLeading(10);
        cell.add(new Phrase(subName, new Font(Font.TIMES_ROMAN, 10, Font.UNDERLINE)));
        cell.add(new Phrase("\n" + cTitle, new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
        document.add(spacer);
        document.add(spacer);

        table1 = new Table(1, 1);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        table1.setOffset(0);
        cell = new Cell();
        cell.setHorizontalAlignment("center");
        cell.setVerticalAlignment("middle");
        //cell.setLeading(10);
        cell.add(new Phrase("By:____________________________", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
        cell.add(new Phrase("\nPrint Name of Authorized Company Officer",
                new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);
        document.add(spacer);
        document.add(spacer);
        table1 = new Table(1, 1);
        table1.setOffset(0);
        table1.setBorderWidth(0);
        table1.setWidth(100);
        //table1.setDefaultCellBorder(0);
        cell = new Cell();
        cell.setHorizontalAlignment("center");
        cell.setVerticalAlignment("middle");
        //cell.setLeading(10);
        cell.add(new Phrase("By:____________________________", new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)));
        cell.add(new Phrase("\nAuthorized Signature", new Font(Font.TIMES_ROMAN, 6, Font.ITALIC)));
        cell.setBorder(0);
        table1.addCell(cell);
        document.add(table1);

    }

}

From source file:corner.orm.tapestry.pdf.PdfTemplateSourceDelegate.java

License:Apache License

private void createTemplateByBlock(PdfBlock block, StringBuffer sb) {
    sb.append("<span jwcid=\"");
    sb.append(block.getName());//  w  ww. ja va  2s  . co  m
    sb.append("\" ");

    // rectangle
    sb.append("rectangle=\"literal:");
    Rectangle r = block.getRectangle();
    sb.append(r.left()).append(",").append(r.bottom()).append(",").append(r.right()).append(",")
            .append(r.top());
    sb.append("\" ");

    // other parameter
    if (block.getValue() != null)
        sb.append(block.getValue());

    sb.append("/>\n");
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner//w  ww . j ava2s.  co  m
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}