/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ServiceLayer;

import DataEntryBean.MicroFileAccountDetBean;
//import com.lowagie.text.*;
// import com.lowagie.text.pdf.PdfPCell;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Properties;


/**
 *
 * @author 1004242
 */
public class CashWithdrawlDDSService {

   private static final String FILE_NAME = "transactionReciept";
   private static final String FILE_NAME_ALL_TRAN = "AllTransactionReciept";
   private static final String FILE_NAME_DETAIL_TRAN = "DetailTransactionReciept";
   private static DecimalFormat df2 = new DecimalFormat(".##");

//   public PdfPCell getCell(String text, int alignment , Font f) {
//    PdfPCell cell = new PdfPCell(new Phrase(text,f));
//    cell.setPadding(0);
//    cell.setHorizontalAlignment(alignment);
//    cell.setBorder(PdfPCell.NO_BORDER);
//    return cell;
//}
   
//   public File createReceipt(MicroFileAccountDetBean accountDet , String agntCode , String agntName) {
//
//        Document document = new Document();//new Rectangle(216,432)
//        SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy");
//        SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
//        double avlBl=0;
//        File pdfReceipt =null;
//
//        try {
//
//            pdfReceipt = new File(FILE_NAME+System.currentTimeMillis()+".pdf");
//            PdfWriter.getInstance(document, new FileOutputStream(pdfReceipt));
//            Rectangle one = new Rectangle(155,180);
//            document.setPageSize(one);
//            document.setMargins(4, 4, 4, 2);
//
//            Font f = new Font();
//            f.setStyle(Font.BOLD);
//            f.setSize(15);
//
//            Font f1 = new Font();
//            f1.setStyle(Font.BOLD);
//            f.setSize(9);
//
//            Font f2 = new Font();
//            f2.setSize(6);
//
//            document.open();
//
//            String dateLine = "Date: "+  sdf.format(new Date()).toString();
//            String timeLine = "Time: "+ sdfTime.format(new Date()).toString();
//            PdfPTable table = new PdfPTable(2);
//            table.setWidthPercentage(100);
//            table.addCell(getCell(dateLine, PdfPCell.ALIGN_LEFT,f2));
//            table.addCell(getCell(timeLine, PdfPCell.ALIGN_RIGHT,f2));
//            document.add(table);
//
//
//            String header = "CASH " + (accountDet.getTxnType().equalsIgnoreCase("CR") ? "DEPOSIT" : "WITHDRAWL");
//            Paragraph p2 = new Paragraph(header, f);
//            p2.setAlignment(Element.ALIGN_CENTER);
//
//            document.add(p2);
//            document.add( new Chunk("------------------------------------") );
//
//
//            PdfPTable tableDetails = new PdfPTable(2);
//            tableDetails    .setWidthPercentage(100);
//
//            tableDetails.addCell(getCell("Agent Code/Id", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(agntCode == null ? ": N/A":": "+agntCode, PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell("Agent Name", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(agntName == null ? ": N/A":": "+agntName, PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Transaction No", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getTxnRefNo()== null ? ": N/A":": "+accountDet.getTxnRefNo(), PdfPCell.ALIGN_LEFT,f2));
//
//
//            tableDetails.addCell(getCell("Account No", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAccountCode()== null ? ": N/A":": "+accountDet.getAccountCode(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Account Holder Name", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAccountName()== null ? ": N/A":": "+accountDet.getAccountName(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Product Type", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getProdType()== null ? ": N/A":": "+accountDet.getProdType(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Address1", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAdd1()== null ? ": N/A":": "+accountDet.getAdd1(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Address2", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAdd2()== null ? ": N/A" :": "+accountDet.getAdd2(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Address3", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAdd3()== null ? ": N/A":": "+accountDet.getAdd3(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Pincode", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+"N/A", PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("ACC Open Date", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAccntOpenDate()== null ? ": N/A":": "+accountDet.getAccntOpenDate(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Maturity/Due Date", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(accountDet.getAccntMatDate()== null ? ": N/A":": "+accountDet.getAccntMatDate(), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Previous Balance", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+String.valueOf(accountDet.getAvailBal()== 0 ? ": N/A":accountDet.getAvailBal()), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Amount", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+String.valueOf(accountDet.getCrTotal()== null ? ": N/A":accountDet.getCrTotal()), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Available Balance", PdfPCell.ALIGN_LEFT,f2));
//            if(accountDet.getTxnType().equalsIgnoreCase("CR"))
//            {
//                avlBl = accountDet.getCrTotal()+accountDet.getAvailBal();
//            }
//            else if(accountDet.getTxnType().equalsIgnoreCase("DR"))
//            {
//                avlBl =accountDet.getAvailBal()-accountDet.getCrTotal();
//            }
//            tableDetails.addCell(getCell(": "+String.valueOf(avlBl== 0 ? ": N/A": avlBl), PdfPCell.ALIGN_LEFT,f2));
//
//            document.add(tableDetails);
//            document.add( Chunk.NEWLINE );
//            String footer = "Thank you for banking with us";
//            Paragraph p3 = new Paragraph(footer, f2);
//            p3.setAlignment(Element.ALIGN_CENTER);
//            document.add(p3);
//
//            document.close();
//
//            //Desktop.getDesktop().open( pdfReceipt);
//            System.out.println("Done");
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//            pdfReceipt = null;
//
//        }
//         return pdfReceipt;
//
//    }

    public File createReceipt(MicroFileAccountDetBean accountDet , String agntCode , String agntName) {

       // Document document = new Document();//new Rectangle(216,432)
        SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy");
        SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
        double avlBl=0;
        File pdfReceipt =null;
         File file = null;
          BufferedWriter writer = null;
          
        try {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            InputStream input = classLoader.getResourceAsStream("Dao/BulkMarkSTB.properties");
            Properties properties = new Properties();
            properties.load(input);
            
            String APPLICATION_FOLDER_PATH = properties.getProperty("APPLICATION_FOLDER_PATH");

            file = new File (APPLICATION_FOLDER_PATH+FILE_NAME+System.currentTimeMillis()+".txt");
            writer = new BufferedWriter(new FileWriter(file));
            writer.write("Date: "+  sdf.format(new Date()).toString()+" ");
            writer.write( "Time: "+ sdfTime.format(new Date()).toString());
            writer.newLine();
            String header = "     CASH " + (accountDet.getTxnType().equalsIgnoreCase("CR") ? "DEPOSIT" : "WITHDRAWL");
            writer.write(header);
            writer.newLine();
            writer.write("------------------------------------");
            writer.newLine();
            writer.write("Agent Code/Id"+(agntCode == null ? ": N/A":": "+agntCode));
            writer.newLine();
            writer.write("Agent Name"+(agntName == null ? ": N/A":": "+agntName));
            writer.newLine();
            writer.write("Transaction No"+(accountDet.getTxnRefNo()== null ? ": N/A":": "+accountDet.getTxnRefNo()));
            writer.newLine();
            writer.write("Account No"+(accountDet.getAccountCode()== null ? ": N/A":": "+accountDet.getAccountCode()));
            writer.newLine();
            writer.write("Account Holder Name"+(accountDet.getAccountName()== null ? ": N/A":": "+accountDet.getAccountName()));
            writer.newLine();
            writer.write("Product Type"+(accountDet.getProdType()== null ? ": N/A":": "+accountDet.getProdType()));
            writer.newLine();
            writer.write("Txn Amount"+String.valueOf(accountDet.getCrTotal()== null ? ": N/A":": "+accountDet.getCrTotal()));
            writer.newLine();
//            writer.write("Address1"+(accountDet.getAdd1()== null ? ": N/A":": "+accountDet.getAdd1()));
//            writer.newLine();
//            writer.write("Address2"+(accountDet.getAdd2()== null ? ": N/A" :": "+accountDet.getAdd2()));
//            writer.newLine();
//            writer.write("Address3"+(accountDet.getAdd3()== null ? ": N/A":": "+accountDet.getAdd3()));
//            writer.newLine();
//            writer.write("Pincode"+": "+"N/A");
//            writer.newLine();
//            writer.write("ACC Open Date"+(accountDet.getAccntOpenDate()== null ? ": N/A":": "+accountDet.getAccntOpenDate()));
//            writer.newLine();
//            writer.write("Maturity/Due Date"+(accountDet.getAccntMatDate()== null ? ": N/A":": "+accountDet.getAccntMatDate()));
//            writer.newLine();
            writer.write("Previous Balance"+": "+String.valueOf(accountDet.getAvailBal()== 0 ? ": N/A":accountDet.getAvailBal()));
            writer.newLine();
            if(accountDet.getTxnType().equalsIgnoreCase("CR"))
            {
                avlBl = accountDet.getCrTotal()+accountDet.getAvailBal();
            }
            else if(accountDet.getTxnType().equalsIgnoreCase("DR"))
            {
                avlBl =accountDet.getAvailBal()-accountDet.getCrTotal();
            }
            writer.write("Available Balance"+": "+String.valueOf(avlBl== 0 ? ": N/A": avlBl));
            writer.newLine();
            writer.write("Thank you for banking with us");
            writer.newLine();
            writer.newLine();
            writer.newLine();
            writer.newLine();
            writer.flush();
            writer.close();

            
            //Desktop.getDesktop().open( file);
            System.out.println("Done");

        } catch (Exception e) {

           // e.printStackTrace();
           System.out.println("Error occurred during processing.");
            file = null;

        } finally {
            System.out.println("Processing done.");
        }
         return file;

    }


//     public File createAllTransactionReceipt(MicroFileAccountDetBean accountDet , String agntCode , String agntName , String pacsId) {
//
//        Document document = new Document();//new Rectangle(216,432)
//        SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy");
//        File pdfReceipt =null;
//
//        try {
//
//            pdfReceipt = new File(FILE_NAME_ALL_TRAN+System.currentTimeMillis()+".pdf");
//            PdfWriter.getInstance(document, new FileOutputStream(pdfReceipt));
//            Rectangle one = new Rectangle(155,110);
//            document.setPageSize(one);
//            document.setMargins(4, 4, 4, 2);
//
//            Font f = new Font();
//            f.setStyle(Font.BOLD);
//            f.setSize(15);
//
//            Font f1 = new Font();
//            f1.setStyle(Font.BOLD);
//            f.setSize(9);
//
//            Font f2 = new Font();
//            f2.setSize(6);
//
//            document.open();
//
//            String header = "TOTAL TRANSACTION";
//            Paragraph p2 = new Paragraph(header, f);
//            p2.setAlignment(Element.ALIGN_CENTER);
//
//            document.add(p2);
//            document.add( new Chunk("------------------------------------") );
//
//            String dateLine = accountDet.getAccntMaturityDate();
//
//            PdfPTable tableDetails = new PdfPTable(2);
//            tableDetails.setWidthPercentage(100);
//
//
//            tableDetails.addCell(getCell("Transaction Date", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(dateLine == null ? ": N/A":": "+dateLine, PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell("Id", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(agntCode == null ? ": N/A":": "+agntCode, PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell("Name", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(agntName == null ? ": N/A":": "+agntName, PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Total Deposit", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+String.valueOf(accountDet.getDrTotal()== 0 ? ": N/A":accountDet.getDrTotal()), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Total Withdrawl", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+String.valueOf(accountDet.getCrTotal()== 0 ? ": N/A":accountDet.getCrTotal()), PdfPCell.ALIGN_LEFT,f2));
//
//            tableDetails.addCell(getCell("Total Transaction", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails.addCell(getCell(": "+String.valueOf(accountDet.getCrTotal()+ accountDet.getDrTotal()== 0 ? ": N/A":accountDet.getCrTotal()+accountDet.getDrTotal()), PdfPCell.ALIGN_LEFT,f2));
//
//            document.add(tableDetails);
//            document.add( Chunk.NEWLINE );
//
//            document.close();
//            //Desktop.getDesktop().open( pdfReceipt);
//
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//            pdfReceipt = null;
//
//        }
//         return pdfReceipt;
//
//    }

      public File createAllTransactionReceipt(MicroFileAccountDetBean accountDet , String agntCode , String agntName , String pacsId) {

        // Document document = new Document();//new Rectangle(216,432)
         SimpleDateFormat sdf =  new SimpleDateFormat("dd/MM/yyyy");
         File file = null;
         BufferedWriter writer = null;

        try { 
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            InputStream input = classLoader.getResourceAsStream("Dao/BulkMarkSTB.properties");
            Properties properties = new Properties();
            properties.load(input);
            
            String APPLICATION_FOLDER_PATH = properties.getProperty("APPLICATION_FOLDER_PATH");
            
            file = new File (APPLICATION_FOLDER_PATH+FILE_NAME_ALL_TRAN+System.currentTimeMillis()+".txt");
            writer = new BufferedWriter(new FileWriter(file));
            
            String header = "       TOTAL TRANSACTION";
            writer.write(header);
            writer.newLine();
            writer.write("------------------------------------");
            writer.newLine();
            String dateLine = accountDet.getAccntMaturityDate();
            writer.write("Transaction Date"+(dateLine == null ? ": N/A":": "+dateLine));
            writer.newLine();
            writer.write("Id"+(agntCode == null ? ": N/A":": "+agntCode));
            writer.newLine();
            writer.write("Name"+(agntName== null ? ": N/A":": "+agntName));
            writer.newLine();
            writer.write("Total Deposit"+String.valueOf(accountDet.getCrTotal()== 0 ? ": N/A":": "+accountDet.getCrTotal()));
            writer.newLine();
            writer.write("Total Withdrawl"+String.valueOf(accountDet.getDrTotal()== 0 ? ": N/A":": "+accountDet.getDrTotal()));
            writer.newLine();
            writer.write("Total Transaction"+String.valueOf(accountDet.getCrTotal()+ accountDet.getDrTotal()== 0 ? ": N/A":": "+    accountDet.getCrTotal()+accountDet.getDrTotal()));
            writer.newLine();
            writer.newLine();
            writer.newLine();
            writer.newLine();
            writer.flush();
            writer.close();
            System.out.println("Done");

        } catch (Exception e) {

           // e.printStackTrace();
           System.out.println("Error occurred during processing.");
            file = null;

        } finally {
            System.out.println("Processing done.");
        }
         return file;


    }

//   public File createTransactionReceiptDetailed( ArrayList<MicroFileAccountDetBean> accountDetlist){
//
//        Document document = new Document();//new Rectangle(216,432)
//        File pdfReceipt =null;
//
//        try {
//
//            String file = FILE_NAME_DETAIL_TRAN+System.currentTimeMillis()+".pdf";
//            pdfReceipt = new File(file);
//            PdfWriter.getInstance(document, new FileOutputStream(pdfReceipt));
//            Rectangle one = new Rectangle(155,accountDetlist.size() *13 + 60 );
//            document.setPageSize(one);
//            document.setMargins(4, 4, 4, 2);
//
//            Font f = new Font();
//            f.setStyle(Font.BOLD);
//            f.setSize(15);
//
//            Font f1 = new Font();
//            f1.setStyle(Font.BOLD);
//            f.setSize(9);
//
//            Font f2 = new Font();
//            f2.setSize(6);
//
//            document.open();
//
//            String header = "TRANSACTION REPORT";
//            Paragraph p2 = new Paragraph(header, f);
//            p2.setAlignment(Element.ALIGN_CENTER);
//
//            document.add(p2);
//            document.add( new Chunk("------------------------------------") );
//
//
//
//            PdfPTable tableDetails1 = new PdfPTable(4);
//            tableDetails1.setWidthPercentage(100);
//
//            tableDetails1.addCell(getCell("SL NO", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails1.addCell(getCell("ACC NO", PdfPCell.ALIGN_LEFT,f2));
//            tableDetails1.addCell(getCell("AMOUNT", PdfPCell.ALIGN_RIGHT,f2));
//            tableDetails1.addCell(getCell("TXN TYPE", PdfPCell.ALIGN_RIGHT,f2));
//            document.add(tableDetails1);
//
//
//
//            PdfPTable tableDetails = new PdfPTable(4);
//            tableDetails.setWidthPercentage(100);
//            tableDetails.setTotalWidth(new float[]{ 20, 70 ,35,30 });
//
//            for (MicroFileAccountDetBean accDt : accountDetlist) {
//
//                tableDetails.addCell(getCell(String.valueOf(accDt.getSlNo() == null ? ": " : accDt.getSlNo()+"."), PdfPCell.ALIGN_LEFT, f2));
//                tableDetails.addCell(getCell(String.valueOf(accDt.getAccountCode() == null ? ": N/A" : accDt.getAccountCode()), PdfPCell.ALIGN_LEFT, f2));
//                tableDetails.addCell(getCell(String.valueOf(accDt.getAvailBal() == 0 ? ": N/A" : accDt.getAvailBal()), PdfPCell.ALIGN_LEFT, f2));
//                tableDetails.addCell(getCell(String.valueOf(accDt.getProdType() == null ? ": N/A" : accDt.getProdType()), PdfPCell.ALIGN_LEFT, f2));
//
//            }
//            tableDetails.deleteLastRow();
//            document.add(tableDetails);
//            document.add( new Chunk("------------------------------------") );
//
//
//            PdfPTable tableDetails3 = new PdfPTable(4);
//            tableDetails.setWidthPercentage(100);
//            MicroFileAccountDetBean accDt = accountDetlist.get(accountDetlist.size()-1);
//            tableDetails3.addCell(getCell(String.valueOf(accDt.getSlNo() == null ? ": N/A" : accDt.getSlNo()), PdfPCell.ALIGN_CENTER, f2));
//            tableDetails3.addCell(getCell(String.valueOf(accDt.getAccountCode() == null ? "Total:" : accDt.getAccountCode()+":"), PdfPCell.ALIGN_LEFT, f2));
//            tableDetails3.addCell(getCell(String.valueOf(accDt.getAvailBal() == 0 ? ": N/A" : accDt.getAvailBal()), PdfPCell.ALIGN_CENTER, f2));
//            tableDetails3.addCell(getCell(String.valueOf(accDt.getProdType() == null ? ": N/A" : accDt.getProdType()), PdfPCell.ALIGN_CENTER, f2));
//            document.add(tableDetails3);
//
//
//            document.add( Chunk.NEWLINE );
//
//            document.close();
//
//            //Desktop.getDesktop().open( pdfReceipt);
//
//
//        } catch (Exception e) {
//
//            e.printStackTrace();
//            pdfReceipt = null;
//
//        }
//         return pdfReceipt;
//
//    }


    public File createTransactionReceiptDetailed(ArrayList<MicroFileAccountDetBean> accountDetlist) {

        File file = null;
        int counter =1;
        BufferedWriter writer = null;
        double totalAmnt = 0;

        try {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            InputStream input = classLoader.getResourceAsStream("Dao/BulkMarkSTB.properties");
            Properties properties = new Properties();
            properties.load(input);
            
            String APPLICATION_FOLDER_PATH = properties.getProperty("APPLICATION_FOLDER_PATH");

            file = new File(APPLICATION_FOLDER_PATH+FILE_NAME_DETAIL_TRAN + System.currentTimeMillis() + ".txt");
            writer = new BufferedWriter(new FileWriter(file));

            String header = "       TRANSACTION REPORT";
            writer.write(header);
            writer.newLine();
            writer.write("------------------------------------");
            writer.newLine();
            writer.write("SL NO" + "    ACC NO" + "       AMOUNT" + " TXN TYP");
            writer.newLine();
            for (MicroFileAccountDetBean accDt : accountDetlist) {

                writer.write(String.valueOf(accDt.getSlNo() == null ? " " : accDt.getSlNo() + ".") + (counter>9?(counter>99?"":" "):"  ")
                        + String.valueOf(accDt.getAccountCode() == null ? " N/A" : accDt.getAccountCode())+ "  "
                        + String.valueOf(accDt.getAvailBal() == 0 ? " N/A" : (accDt.getAvailBal())) +(accDt.getAvailBal()>99? " ":"  ")
                        + String.valueOf(accDt.getProdType() == null ? " N/A" : accDt.getProdType()));
                 writer.newLine();
                 counter++;
                 totalAmnt = totalAmnt+accDt.getAvailBal();
            }

            writer.write("------------------------------------");
            writer.newLine();
            writer.write("       TOTAL :   "+totalAmnt);
            writer.newLine();
            writer.newLine();
            writer.newLine();
            writer.flush();
            writer.close();
            System.out.println("Done");

        } catch (Exception e) {

           // e.printStackTrace();
           System.out.println("Error occurred during processing.");
            file = null;

        } finally {
            System.out.println("Processing done.");
        }
        return file;


    }
}
