package com.reallinkbilling.download;

import static java.awt.Color.WHITE;
import static org.apache.pdfbox.pdmodel.font.PDType1Font.HELVETICA;
import static org.vandeseer.easytable.settings.HorizontalAlignment.CENTER;
import static org.vandeseer.easytable.settings.HorizontalAlignment.LEFT;
import static org.vandeseer.easytable.settings.HorizontalAlignment.RIGHT;

import java.awt.Color;
import java.io.FileInputStream;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;
import org.vandeseer.easytable.TableDrawer;
import org.vandeseer.easytable.structure.Row;
import org.vandeseer.easytable.structure.Table;
import org.vandeseer.easytable.structure.Table.TableBuilder;
import org.vandeseer.easytable.structure.cell.TextCell;

import com.opensymphony.xwork2.ActionSupport;
import com.reallinkbilling.DAO.CustomerCreditColectionReportDAO;
import com.reallinkbilling.DAO.CustomerCreditReportDAO;
import com.reallinkbilling.DAO.CustomerInfoDAO;
import com.reallinkbilling.cipher.EncryptionDecryption;
import com.reallinkbilling.db.GetDBConnection;
import javax.servlet.ServletOutputStream;


public class DownloadCreditCollectionReport extends ActionSupport implements SessionAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public HttpServletRequest request;
	public HttpServletResponse response;
	private SessionMap<String,Object> sessionMap;
	private final static Color BLUE_DARK = new Color(76, 129, 190);
    private final static Color BLUE_LIGHT_1 = new Color(186, 206, 230);
    private final static Color BLUE_LIGHT_2 = new Color(218, 230, 242);

    private final static Color GRAY_LIGHT_1 = new Color(245, 245, 245);
    private final static Color GRAY_LIGHT_2 = new Color(240, 240, 240);
    private final static Color GRAY_LIGHT_3 = new Color(216, 216, 216);
    private static final float PADDING5 = 5f;
    private static final float PADDING10 = 10f;
    private static final float PADDING20 = 20f;
    private static final float PADDING30 = 30f;
    private static final float PADDING40 = 40f;
    private static final float PADDING50 = 50f;
    
    
    private String fromDate;
   	private String toDate;
   	private HttpSession session;
   
   	private String customerNameCode;
   	private String addSideBarJs;
   	private List<String> downloadTypeList = new ArrayList<String>();
   	private String downloadType;
   	private Float totalAmount;
   	

	private List<CustomerCreditColectionReportDAO> creditCollectionList = new ArrayList<CustomerCreditColectionReportDAO>();
	
	public void download()
	{
		session=ServletActionContext.getRequest().getSession(false); 
		 
        if(session==null || session.getAttribute("login")==null){ 
        	addActionMessage("Please Login First !!!");
        	
        }  
        else{
        	
        	response = ServletActionContext.getResponse();
        	request = ServletActionContext.getRequest();

        	Map<String, String> map = new HashMap<String, String>();

        	Enumeration<String> headerNames = request.getHeaderNames();

        	while (headerNames.hasMoreElements()) {
        	    String key = headerNames.nextElement();
        	    String value = request.getHeader(key);
        	    map.put(key, value);
        	}
			
			downloadTypeList.add("pdf");
	    	downloadTypeList.add("xl");
	    	
	    	
	    	
	    	String shopId = (String) this.getSessionMap().get("shopId");
    		String shopCode = (String) this.getSessionMap().get("shopCode");
    		
    		
    		Connection connection = null;
			PreparedStatement preparedStatement= null;
			ResultSet resultSet = null;
			
			

    		String sql = "";
    		String db = (String) session.getAttribute("db");
    		
    		try
    		{
    			

    			connection = GetDBConnection.getDBConnection(db);
				
    			if(this.getCustomerNameCode() == null || this.getCustomerNameCode().trim().equals(""))
				{
				
					sql = "SELECT "
							+ "customer_id,"
							+ "customer_name,"
							+ "DATE_FORMAT(entry_date,'%d-%m-%Y'),"
							+ "entry_time,"
							+ "payment_amount,"
							+ "payment_details, "
							+ "payment_received_by,"
							+ "entry_id "
							+ "FROM "
							+ "shop_customer_payment_master "
							+ "WHERE "
							+ "shop_id = ? "
							+ "AND "
							+ "shop_code = ? "
							+ "AND "
							+ "(entry_date "
							+ "BETWEEN "
							+ "STR_TO_DATE(?,'%d-%m-%Y') "
							+ "AND "
							+ "STR_TO_DATE(?,'%d-%m-%Y'))";
					
					
					
					preparedStatement = connection.prepareStatement(sql);
					preparedStatement.setString(1, shopId);
					preparedStatement.setString(2, shopCode);
					preparedStatement.setString(3, this.getFromDate());
					preparedStatement.setString(4, this.getToDate());
				}
    			else
				{
				    String customerSearch = resolveCustomerSearchTerm(this.getCustomerNameCode());

				    sql = "SELECT "
				            + "customer_id,"
				            + "customer_name,"
				            + "DATE_FORMAT(entry_date,'%d-%m-%Y'),"
				            + "entry_time,"
				            + "payment_amount,"
				            + "payment_details, "
				            + "payment_received_by,"
				            + "entry_id "
				            + "FROM "
				            + "shop_customer_payment_master "
				            + "WHERE "
				            + "shop_id = ? "
				            + "AND "
				            + "shop_code = ? "
				            + "AND "
				            + "customer_id = ? "
				            + "AND "
				            + "entry_date BETWEEN "
				            + "STR_TO_DATE(?,'%d-%m-%Y') "
				            + "AND "
				            + "STR_TO_DATE(?,'%d-%m-%Y')";

				    preparedStatement = connection.prepareStatement(sql);

				    preparedStatement.setString(1, shopId);
				    preparedStatement.setString(2, shopCode);
				    preparedStatement.setString(3, customerSearch);
			    preparedStatement.setString(4, this.getFromDate());					   
			    preparedStatement.setString(5, this.getToDate());
				
				}
				resultSet = preparedStatement.executeQuery();
				int rowCount = 0;
				resultSet.last();
				rowCount = resultSet.getRow();
				resultSet.beforeFirst();
				if(rowCount > 0)
				{
					while(resultSet.next())
					{
						CustomerCreditColectionReportDAO reportDAO = new CustomerCreditColectionReportDAO();
						
						reportDAO.setCustomerId(resultSet.getString(1));
						reportDAO.setCustomerName(resultSet.getString(2));
						reportDAO.setEntryDate(resultSet.getString(3));
						reportDAO.setEntryTime(resultSet.getString(4));
						reportDAO.setAmount(resultSet.getString(5));
						reportDAO.setComments(resultSet.getString(6));
						reportDAO.setEntryBy(resultSet.getString(7));
						reportDAO.setPaymentId(resultSet.getString(8));
						reportDAO.setKey(
								URLEncoder.encode(EncryptionDecryption.encrypt(
										
												resultSet.getString(1)+"#"
												+resultSet.getString(2)+"#"
												+resultSet.getString(3)+"#"
												+resultSet.getString(4)+"#"
												+resultSet.getString(5)+"#"
												+resultSet.getString(7)),"UTF-8"));
						
						//customerId#Customername#entryDate#time#Amount#EntryBy
						
						this.getCreditCollectionList().add(reportDAO);
						
					}
					
					float totalAmountFloat = 0.0F;

					for (CustomerCreditColectionReportDAO dao : this.getCreditCollectionList()) {
					    if (dao.getAmount() != null && !dao.getAmount().trim().equals("")) {
					        totalAmountFloat += Float.parseFloat(dao.getAmount());
					    }
					}

					this.setTotalAmount(totalAmountFloat);
					
						
					
				}
				else
				{
					
						
					
					addActionError(this.getText("message.error.datanotfoundforspecifiedinfo"));
				}
				
			
   			
   			
   			
   			
   			@SuppressWarnings("unchecked")
   			String name = (String) this.getSessionMap().get("shopnameenglish");
			String address = (String) this.getSessionMap().get("shopaddresseng");
			String path= this.getRequest().getSession().getServletContext().getRealPath("/images/");
		    
			if(this.getDownloadType().equals("pdf"))
			{
				
				DecimalFormat df = new DecimalFormat("#.#");
				
			
			
			PDDocument document = new PDDocument(); 
			PDPage page = null;
			
			
				 page = new PDPage(PDRectangle.A4);
			
			
		        document.addPage(page);
		         PDPageContentStream contentStream = new PDPageContentStream(document, page);
		         int pageCount = 1;
	    			 Table header;
	    			 Table creditDetails;
	    			 
	    			
	    			  TableBuilder tableHeaderBuilder = Table.builder()
				                .addColumnsOfWidth(585)				                
				                .font(HELVETICA)
				                .borderColor(Color.BLACK)
				                .horizontalAlignment(CENTER);
			         
			          Row headerName = Row.builder()
				                .add(TextCell.builder().text(name).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(10F).build())				               
				                .backgroundColor(WHITE)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA_BOLD).fontSize(18)				              
				                .horizontalAlignment(CENTER)
				                .build();
			          
			          Row addressRow = Row.builder()
				                .add(TextCell.builder().text(address).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(10F).build())				               
				                .backgroundColor(WHITE)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA_BOLD).fontSize(9)				              
				                .horizontalAlignment(CENTER)
				                .build();
			          
			          
			          Row info1 = Row.builder()
				                .add(TextCell.builder().text("Credit Collection Report  "
				                			+"       Page No . : "+pageCount).borderWidthBottom(0.0F).horizontalAlignment(CENTER).build())				               
				                .backgroundColor(WHITE)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA_BOLD).fontSize(10)
				                .horizontalAlignment(CENTER)
				                .build();
			          
			          Row info2 = Row.builder()
				                .add(TextCell.builder().text("From Date : "
				                		+ ""+this.getFromDate()
				                		+ " and To Date :"+this.getToDate() +" Customer Id/Name : " + this.getCustomerNameCode() ).borderWidthBottom(0.0F).horizontalAlignment(CENTER).build())				               
				                .backgroundColor(WHITE)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)
				                .horizontalAlignment(CENTER)
				                .build();
			         
			          
			          tableHeaderBuilder.addRow(headerName);
			          tableHeaderBuilder.addRow(addressRow);
			          tableHeaderBuilder.addRow(info1);
			          tableHeaderBuilder.addRow(info2);
			          header = tableHeaderBuilder.build();
			          
			          
			          TableBuilder tableDebtDetailsBuilder = Table.builder()
			        		  .addColumnsOfWidth(35,40, 50, 180, 60, 220)		                
				                .font(HELVETICA)
				                .borderWidth(0.5F)
				                .borderColor(Color.BLACK)
				                .horizontalAlignment(CENTER);
			          
			          Row tableHeader = Row.builder()
			        		  	.add(TextCell.builder().text("Sr. No").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                

			        		  	.add(TextCell.builder().text("ID").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
				                .add(TextCell.builder().text("Date").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())
				                .add(TextCell.builder().text("Customer Name").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
				                .add(TextCell.builder().text("Amount").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
				                .add(TextCell.builder().text("Details").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
				                .backgroundColor(Color.LIGHT_GRAY)
				                .textColor(Color.BLACK)
				                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)				              
				                .horizontalAlignment(CENTER)
				                .build();
			          tableDebtDetailsBuilder.addRow(tableHeader);
			       
			        
			     
			        	  int size = this.getCreditCollectionList().size();
			        	  
			        	  
				          float startY = page.getMediaBox().getHeight() - PADDING20;
				          float currentY = startY;
				          TableDrawer.builder()
			                .contentStream(contentStream)
			                .table(header)
			                .startX(PADDING30)
			                .startY(startY)
			                .build()
			                .draw();
				          
				          
				          
				    	  for(int s=0;s<size;s++)
			        	  {
			        		  
			        		  if(currentY < 130)
			        		  {
			        			  pageCount++;
			        			  creditDetails = tableDebtDetailsBuilder.build();
			        			  TableDrawer.builder()
					                .contentStream(contentStream)
					                .table(creditDetails)
					                .startX(PADDING5)
					                .startY(startY-70)
					                .build()
					                .draw();
			        			  
			        			  contentStream.close();
			        			  
			        			  header = null;
			        			  
			        			 
					    			 
					    			
					    			  tableHeaderBuilder = Table.builder()
								                .addColumnsOfWidth(585)				                
								                .font(HELVETICA)
								                .borderColor(Color.BLACK)
								                .horizontalAlignment(CENTER);
							         
							           headerName = Row.builder()
								                .add(TextCell.builder().text(name).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(10F).build())				               
								                .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA_BOLD).fontSize(18)				              
								                .horizontalAlignment(CENTER)
								                .build();
							          
							           
							           
							        addressRow = Row.builder()
								                .add(TextCell.builder().text(address).horizontalAlignment(CENTER).borderWidth(0).lineSpacing(10F).build())				               
								                .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA_BOLD).fontSize(9)				              
								                .horizontalAlignment(CENTER)
								                .build();
							          
							           info1 = Row.builder()
								                .add(TextCell.builder().text("Customer Payment Report  "
							                			+"       Page No . : "+pageCount).borderWidthBottom(0.0F).horizontalAlignment(CENTER).build())				               
								                .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA_BOLD).fontSize(10)
								                .horizontalAlignment(CENTER)
								                .build();
							           
							           
							           String custName = "";
							           
							           if(this.getCustomerNameCode() == null || this.getCustomerNameCode().equals(""))
							           {
							        	   custName = "ALL";
							           }
							           else
							           {
							        	   String[] customerParts = this.getCustomerNameCode().split("-");
							        	   custName = customerParts.length >= 2 ? customerParts[1] : this.getCustomerNameCode();
							           }
							        	   
							          
							           info2 = Row.builder()
								                .add(TextCell.builder().text("From Date : "
								                		+ ""+this.getFromDate()
								                		+ " and To Date :"+this.getToDate() +" Customer Name : " +custName).borderWidthBottom(0.0F).horizontalAlignment(CENTER).build())				               
								                .backgroundColor(WHITE)
								                .textColor(Color.BLACK)
								                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)
								                .horizontalAlignment(CENTER)
								                .build();
							         
							          
							          tableHeaderBuilder.addRow(headerName);
							          tableHeaderBuilder.addRow(addressRow);
							          tableHeaderBuilder.addRow(info1);
							          tableHeaderBuilder.addRow(info2);
							          header = tableHeaderBuilder.build();
			        			  
			        			  creditDetails = null;
			        			   tableDebtDetailsBuilder = Table.builder()
			        					   .addColumnsOfWidth(35,40, 50, 180, 60, 220)
							                .font(HELVETICA)
							                .borderWidth(0.5F)
							                .borderColor(Color.BLACK)
							                .horizontalAlignment(CENTER);
						          
						           tableHeader = Row.builder()
						        		  	.add(TextCell.builder().text("Sr. No").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                

						        		   .add(TextCell.builder().text("Id").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
							                .add(TextCell.builder().text("Date").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())
							                .add(TextCell.builder().text("Customer Name").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
							                .add(TextCell.builder().text("Amount").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
							                .add(TextCell.builder().text("Details").horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())									                
							                .backgroundColor(Color.LIGHT_GRAY)
							                .textColor(Color.BLACK)
							                .font(PDType1Font.HELVETICA_BOLD).fontSize(8)				              
							                .horizontalAlignment(CENTER)
							                .build();
						          tableDebtDetailsBuilder.addRow(tableHeader);
						          
			        			  
			        				PDPage newPage = new PDPage(PDRectangle.A4);
						        	 contentStream = new PDPageContentStream(document,newPage);
						        	startY = newPage.getMediaBox().getHeight() - PADDING20;
						        	currentY = startY;
						             document.addPage( newPage );
						             
						             TableDrawer.builder()
						                .contentStream(contentStream)
						                .table(header)
						                .startX(PADDING30)
						                .startY(currentY)
						                .build()
						                .draw();
			        		  }
			        		  
			        		  CustomerCreditColectionReportDAO dao2 = this.getCreditCollectionList().get(s);
			        		  String detailsText = dao2.getComments() == null ? "" : dao2.getComments();
			        		  
			        		  
			        			Row supplierInfo = Row.builder()
			        					.add(TextCell.builder().text(""+(s+1)).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                

			        					.add(TextCell.builder().text(dao2.getPaymentId()).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
				        			  	.add(TextCell.builder().text(dao2.getEntryDate()).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
				        			  	.add(TextCell.builder().text(dao2.getCustomerName()).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
				        			  	.add(TextCell.builder().text(df.format(Double.parseDouble(dao2.getAmount()))).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(1F).build())				                
				        			  	.add(TextCell.builder().text(detailsText).horizontalAlignment(LEFT).borderWidth(0.5F).lineSpacing(1F).build())				                
				        			  	.backgroundColor(Color.WHITE)
						                .textColor(Color.BLACK)
						                .font(PDType1Font.HELVETICA)
						                .fontSize(8)				              
						                .horizontalAlignment(CENTER)                
						                .build();
				        	  
				        	  tableDebtDetailsBuilder.addRow(supplierInfo);
				        	 
				        	  currentY = currentY -25;
			        	  }
				          
				    		Row totalInfo = Row.builder()
			        				.add(TextCell.builder().text("Total : ").colSpan(4).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(0.2F).build())				                
			        			  	.add(TextCell.builder().text(df.format(this.getTotalAmount())).horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(0.2F).build())
			        			  	.add(TextCell.builder().text("").horizontalAlignment(RIGHT).borderWidth(0.5F).lineSpacing(0.2F).build())
			        			  	.backgroundColor(Color.WHITE)
					                .textColor(Color.BLACK)
					                .font(PDType1Font.HELVETICA_BOLD)
					                .fontSize(9)				              
					                .horizontalAlignment(CENTER)
					                .height(25F)					                
					                .build();
			        	  
				    		tableDebtDetailsBuilder.addRow(totalInfo);
			        	  
			        	  creditDetails = tableDebtDetailsBuilder.build();
			         
			          
			          TableDrawer.builder()
		                .contentStream(contentStream)
		                .table(creditDetails)
		                .startX(PADDING5)
		                .startY(startY-70)
		                .build()
		                .draw();
			          contentStream.close();
				          
				       
			          
			          
			          
			          
			          
			          
				          
				          document.save(path+"/credit-collection-fromDate-" + this.getFromDate() +"-ToDate-"+this.getToDate()+"-customerIdName-"+this.getCustomerNameCode()+"-report.pdf");
					        document.close();
					        
					        response.setHeader("Content-disposition", "inline; filename=credit-collection-fromDate-" + this.getFromDate() +"-ToDate-"+this.getToDate()+"-customerIdName-"+this.getCustomerNameCode()+"-report.pdf");
							response.setContentType("application/pdf");
							
							FileInputStream fileInputStream = new FileInputStream(
								    path + "/credit-collection-fromDate-" 
								    + this.getFromDate()
								    + "-ToDate-" 
								    + this.getToDate()
								    + "-customerIdName-" 
								    + this.getCustomerNameCode()
								    + "-report.pdf"
								);

								ServletOutputStream out = response.getOutputStream();

								byte[] buffer = new byte[8192];
								int bytesRead;

								while ((bytesRead = fileInputStream.read(buffer)) != -1) {
								    out.write(buffer, 0, bytesRead);
								}

								fileInputStream.close();
								out.flush();
								out.close();
							
			}
   		
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
    		}catch (SQLException e) 
	    		{
		    		 e.printStackTrace();
		    				    			
		    			addActionError(e.getErrorCode()+" || "+e.getMessage() +" || Something Went Wrong!");
		    			
		    	} catch (Exception e) {
		    		
		    		e.printStackTrace();	    			
		    			addActionError(e.getMessage()+" || "+e.getCause()+" || Something Went Wrong!");
		    	}
	    			finally {
	    				if(resultSet != null)
						{
							try {resultSet.close(); resultSet = null;} catch (SQLException e) {}
						}
		    			if(preparedStatement != null)
		    			{
		    				try {preparedStatement.close(); preparedStatement = null;} catch (SQLException e) {}
		    			}
		    			if(connection != null)
		    			{
		    				
		    				try {connection.close(); connection = null;}catch (SQLException e) {}
		    			}
		    			
		    		}
	        }
				
	
	
        }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public HttpServletRequest getRequest() {
		return request;
	}
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	public HttpServletResponse getResponse() {
		return response;
	}
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	public SessionMap<String, Object> getSessionMap() {
		return sessionMap;
	}
	public void setSessionMap(SessionMap<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}
	public String getFromDate() {
		return fromDate;
	}
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}
	public String getToDate() {
		return toDate;
	}
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
	public HttpSession getSession() {
		return session;
	}
	public void setSession(HttpSession session) {
		this.session = session;
	}
	public String getCustomerNameCode() {
		return customerNameCode;
	}
	public void setCustomerNameCode(String customerNameCode) {
		this.customerNameCode = customerNameCode;
	}
	public String getAddSideBarJs() {
		return addSideBarJs;
	}
	public void setAddSideBarJs(String addSideBarJs) {
		this.addSideBarJs = addSideBarJs;
	}
	public List<String> getDownloadTypeList() {
		return downloadTypeList;
	}
	public void setDownloadTypeList(List<String> downloadTypeList) {
		this.downloadTypeList = downloadTypeList;
	}
	public String getDownloadType() {
		return downloadType;
	}
	public void setDownloadType(String downloadType) {
		this.downloadType = downloadType;
	}
	public Float getTotalAmount() {
		return totalAmount;
	}
	public void setTotalAmount(Float totalAmount) {
		this.totalAmount = totalAmount;
	}
	
	
	private String resolveCustomerSearchTerm(String customerNameCode) {
	    if (customerNameCode == null) {
	        return "";
	    }

	    String cleanedValue = customerNameCode.trim();

	    if (cleanedValue.isEmpty() || "Customer_Not_Found".equals(cleanedValue)) {
	        return "";
	    }

	    if (cleanedValue.contains("-")) {
	        return cleanedValue.split("-")[0].trim();
	    }

	    return cleanedValue;
	}
	
	
	public List<CustomerCreditColectionReportDAO> getCreditCollectionList() {
		return creditCollectionList;
	}


	public void setCreditCollectionList(List<CustomerCreditColectionReportDAO> creditCollectionList) {
		this.creditCollectionList = creditCollectionList;
	}

	@Override  
	public void setSession(Map<String, Object> map) {  
	    sessionMap=(SessionMap<String, Object>)map;  
	}
	
}
