package com.reallinkbilling.add;

import java.io.IOException;
import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
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.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.reallinkbilling.DAO.BillInformationDAO;
import com.reallinkbilling.DAO.BillProductInfoDAO;
import com.reallinkbilling.DAO.ProductBarcodeDetailsDAO;
import com.reallinkbilling.resource.CheckAlreadyAvailable;
import com.reallinkbilling.resource.GetListResource;
import com.reallinkbilling.utils.GetProductDealerPrice;
import com.reallinkbilling.utils.GetProductStockByName;

public class AddProductToBarcodeBill extends ActionSupport implements SessionAware,Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4890025189311593298L;
	private HttpServletRequest request = null;
	private HttpServletResponse response = null;
	private HttpSession session;
	private String billDateTime;
	private String operator;
	private String paymentType;
	private String customerName;
	private String productName;
	private String productMarathiName;
	private String alias;
	private String salesUnit;
	private String taxId;
	private Float salesRate;
	private Float quantity;
	private Float quantity2;
	private Float discountPercentage;
	private Float discountRupees;
	private Float amount;
	private String billType;
	private Float amountAfterDiscount;
	private Float transportCharge;
	private String comments;
	private boolean sendSMS;
	private String alternateMobileNumber;
	private Float amountPaid;
	private SessionMap<String,Object> sessionMap;  
	private Float returnAmount;
	private boolean billSaved;
	private String billNumber;
	private Map<String,String> taxList = new LinkedHashMap<String,String>();
	private Map<String,String> unitList = new LinkedHashMap<String,String>();
	private Map<String,String> paymentTypeList = new  LinkedHashMap<String,String>();
	private Map<String,String> billTypeList = new  LinkedHashMap<String,String>();
	private ArrayList<String> serailBatchIdList = new ArrayList<String>();
	private String serailNoBatchId;
	private List<BillProductInfoDAO> productInfoList ;
	private String defaultValue;
	private boolean addQuantity2;
	private Float totalAmount;
	private Float totalDiscount;
	private Float totalAmouAfterDisount;
	private String productCode;
	private boolean productReturn;
	private String removeVaules="false";
	private ArrayList<String> customerTypeList = new ArrayList<String>();
	private String customerType;
	private String customerId;
	private String customerMobileNumber;
	
	private BillInformationDAO billInfoDAO = null;
	
	private String viewBill;
	
	private Map<String,String> rateTypeList = new LinkedHashMap<String,String>();
	private String rateType;
	private Float makingLabourAmount;
	
	private Map<String,String> labourChargeTypeList = new LinkedHashMap<String,String>();
	private String labourChargeType;
	private String addLabourCharges;
	private Float cashAmount;
	private Float bankRtgsUpiAmount;
	
	private Map<String,String> discountTypeList = new LinkedHashMap<String,String>();
	private String discountType;
	
	private String customerIdNameAll;

	private String salesmanId;
	
	private String salesmanIdName;
	
	@SuppressWarnings("unchecked")
	 public String execute() throws IOException{
		 
		String result = "login";
		session=ServletActionContext.getRequest().getSession(false); 
		// Ensure productReturn is bound even if framework mapping fails
		try{
			HttpServletRequest req = ServletActionContext.getRequest();
			String pr = req.getParameter("productReturn");
			if(pr != null){
				this.setProductReturn("true".equalsIgnoreCase(pr) || "on".equalsIgnoreCase(pr));
			}
		}catch(Exception ignore){}
		
	        if(session==null || session.getAttribute("login")==null){ 
	        	addActionMessage("Please Logout and Login again !");
	        	result = "error";
	        }  
	        else{
	        	
	        	
	        	
	        	
	        	HashMap<String, String> settings = (HashMap<String, String>) this.getSessionMap().get("shop_settings");
	        	
	        	String shopId = (String) this.getSessionMap().get("shopId");
	    		String shopCode = (String) this.getSessionMap().get("shopCode");
	    		
	    		if(settings.get("add_quntity2").equals("TRUE"))
	        	{
	        		this.setAddQuantity2(true);
	        	}
	        	else
	        	{
	        		this.setAddQuantity2(false);
	        	}
	    		this.setProductInfoList((List<BillProductInfoDAO>) this.getSessionMap().get("productList"));
	        	
	        	this.setBillInfoDAO((BillInformationDAO) this.getSessionMap().get("billInformation"));
				
	        	if(this.getProductInfoList() == null)
	        	{
	        		this.setProductInfoList( new ArrayList<BillProductInfoDAO>());
	        	}
	        	
	        	if(this.getBillInfoDAO()==null)
	        	{
	        		this.setBillInfoDAO(new BillInformationDAO());
	        	}
	        
	        	int listSize = this.getProductInfoList().size();
	        	boolean billByProductName = false;
	        	
	        	if(!this.getProductName().equals(""))
	        	{
	        		billByProductName = true;
	        	}
	        	
	        	if(!billByProductName)
	        	{
	        	
	        	HashMap<String,ProductBarcodeDetailsDAO> productBarcodeDetailsMap = (HashMap<String, ProductBarcodeDetailsDAO>) this.getSessionMap().get("barcodeProductDetails");
	        	
	        	ProductBarcodeDetailsDAO productBarcodeDetails = productBarcodeDetailsMap.get(this.getProductCode().trim());
	        	
	        	String addDuplicateProductToList = settings.get("add_duplicate_items_to_bill");
	        	
	        	boolean duplicateProductFound = false;
	        	BillProductInfoDAO billProductInfoDAO = null;
	        	BillProductInfoDAO OldBillProductInfoDAO = null;
	        	
	        	int index = 0;
	        	int removeIndex = 0;
	        	
	        	if(addDuplicateProductToList.equals("TRUE"))
	    		{
	    			
	    					for(BillProductInfoDAO infoDAO:this.getProductInfoList())
	    					{
	    							if(infoDAO.getProductName().equals(productBarcodeDetails.getProductNameEn()))
	    							{
	    								duplicateProductFound = true;	    								
	    								OldBillProductInfoDAO = infoDAO;
	    								removeIndex = index;	    								
	    							}
	    						index++;
	    					}
	    				
	    		}
	        	
				
	        	if(duplicateProductFound)
				{
	        		this.getProductInfoList().remove(removeIndex);
	        		
	        		billProductInfoDAO = new BillProductInfoDAO();
	        		
	        		billProductInfoDAO.setId(null);	        	
		        	billProductInfoDAO.setSerialNumber(""+(this.getProductInfoList().size()+1));
		        	billProductInfoDAO.setProductId(productBarcodeDetails.getProductId());
		        	
		        	billProductInfoDAO.setProductCode(productBarcodeDetails.getProductCode());
		        	billProductInfoDAO.setSerialNoBatchId(this.getSerailNoBatchId());
		         	billProductInfoDAO.setRateType(this.getRateType());
		        	
			        
		         	
		        	if(this.isProductReturn())
		        	{
		        		billProductInfoDAO.setProductName(productBarcodeDetails.getProductNameEn()+"-RTN");
		        		billProductInfoDAO.setProductNameMarathi(productBarcodeDetails.getProductNameMr()+"-RTN");
		        		billProductInfoDAO.setProductReturn(true);
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setProductName(productBarcodeDetails.getProductNameEn());
		        		billProductInfoDAO.setProductNameMarathi(productBarcodeDetails.getProductNameMr());
		        		billProductInfoDAO.setProductReturn(false);
		        	}
		        	
		        	billProductInfoDAO.setSalesUnit(productBarcodeDetails.getSalesUnit());
		        	billProductInfoDAO.setTaxId(""+productBarcodeDetails.getTaxId());
		        	billProductInfoDAO.setSalesRate(productBarcodeDetails.getBarcodeMRP());
		        
		        	if(isAddQuantity2())
		        	{
		        		billProductInfoDAO.setQuantity2(this.getQuantity2());
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setQuantity2(0.0F);
		        		
		        	}
		        	billProductInfoDAO.setQuantity(productBarcodeDetails.getBarCodeQuantity() + OldBillProductInfoDAO.getQuantity());
		        	billProductInfoDAO.setDiscountPecentage(productBarcodeDetails.getDiscount());
		        	float disRs = productBarcodeDetails.getBarcodeMRP() - productBarcodeDetails.getSalesPrice();
		        	billProductInfoDAO.setDiscountRupees(disRs+OldBillProductInfoDAO.getDiscountRupees());
		        	if(this.isProductReturn())
		        	{
		        		billProductInfoDAO.setAmount(-(productBarcodeDetails.getBarcodeMRP()+OldBillProductInfoDAO.getAmount()));
		        		billProductInfoDAO.setAmountAfterDiscount(-(billProductInfoDAO.getAmount()  - billProductInfoDAO.getDiscountRupees()));
		        		billProductInfoDAO.setProductReturn(true);
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setAmount(productBarcodeDetails.getBarcodeMRP()+OldBillProductInfoDAO.getAmount());
		        		billProductInfoDAO.setAmountAfterDiscount(billProductInfoDAO.getAmount()  - billProductInfoDAO.getDiscountRupees());
		        		billProductInfoDAO.setProductReturn(false);
		        	
		        	}
                billProductInfoDAO.setAlias(this.getAlias());
                billProductInfoDAO.setSalesmanId(this.getSalesmanId());
		        	billProductInfoDAO.setAddedToDB(false);
		        	billProductInfoDAO.setShopId(shopId);
		        	billProductInfoDAO.setShopCode(shopCode);
		     
		        	if(settings.get("add_making_charge_column").equals("TRUE"))
		        	{
		        		billProductInfoDAO.setMakingLaborCharge(this.getMakingLabourAmount()+OldBillProductInfoDAO.getMakingLaborCharge());
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setMakingLaborCharge(0.0F);
		        		this.setMakingLabourAmount(0.0F);
		        	}
		        	
		        	
		        	
		        	float floatAmountAftDiscount = billProductInfoDAO.getAmountAfterDiscount();
		        	float totalProductDiscount = billProductInfoDAO.getDiscountRupees();
		       
		        	float sgst = 0.0F;
		        	float cgst = 0.0F;
		        	float igst = 0.0F;
		        	
					if(this.getBillType().equals("TAX-INVOICE"))
					{
					
						Map<String,String> taxInfo = GetListResource.GetTaxNamePercentage(""+productBarcodeDetails.getTaxId(),this.getSessionMap());
			        	
						String taxName = taxInfo.get("TAX-NAME");
						String taxPercentage = taxInfo.get("TAX-PERCENTAGE");
						
						billProductInfoDAO.setTaxName(taxName);
						billProductInfoDAO.setTaxPercentage(Float.parseFloat(taxPercentage));
						
						if(this.getRateType().equals("INCLUDEGST"))
						{
							
							float floatTaxRate = Float.parseFloat(taxPercentage);	
							
							float basicTax = floatTaxRate+100.0F;
				        	
				        	float grossAmount = (floatAmountAftDiscount / basicTax) * 100.0F;
				        	
				        	float totalTax = floatAmountAftDiscount - grossAmount;
							
							if(taxName.toUpperCase().contains("IGST"))
							{
								igst = totalTax;
							}
							else
							{
								sgst = totalTax/2.0F;
					        	cgst = totalTax/2.0F;
							}
			        	
			        	     
							 DecimalFormat df = new DecimalFormat("0.00");
						        
					        	
				        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(grossAmount)));
				        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
				        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
				        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
				        	 if(this.isProductReturn())
				        	 {
					        	 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
					        	 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
				        	 }
				        	 else
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount((floatAmountAftDiscount + this.getMakingLabourAmount()));
					        	 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());
					        
				        	 }
				        	
						}
						
						if(this.getRateType().equals("EXCLUDEGST"))
						{
							float floatTaxRate = Float.parseFloat(taxPercentage);	
							float totalTax = floatAmountAftDiscount * (floatTaxRate/100.0F);
							
							if(taxName.toUpperCase().contains("IGST"))
							{
								igst = totalTax;
							}
							else
							{
								sgst = totalTax/2.0F;
					        	cgst = totalTax/2.0F;
							}
							
							
							 DecimalFormat df = new DecimalFormat("0.00");
						        
					        	
				        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(floatAmountAftDiscount)));
				        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
				        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
				        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
				        	 if(this.isProductReturn())
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount()));
				        		 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount()));
				        	 }
				        	 else
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount());
					        	 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount());
					        	 
				        	 }
						}
					}
					else
					{
						 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
			        	 billProductInfoDAO.setGrossAmount(floatAmountAftDiscount);
			        	 billProductInfoDAO.setSgst(0.0F);
			        	 billProductInfoDAO.setCgst(0.0F);
			        	 billProductInfoDAO.setIgst(0.0F);
			        	 if(this.isProductReturn())
			        	 {
			        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
			        		 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
			        	 }
			        	 else
			        	 {
			        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
			        		 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());
			        
			        	 }
					}
					
					
				}
				else
				{
					billProductInfoDAO = new BillProductInfoDAO();
	        	
			        	billProductInfoDAO.setId(null);	        	
			        	billProductInfoDAO.setSerialNumber(""+(listSize+1));
			        	billProductInfoDAO.setProductId(productBarcodeDetails.getProductId());
			        	
			        	billProductInfoDAO.setSerialNoBatchId(this.getSerailNoBatchId());
			         	billProductInfoDAO.setRateType(this.getRateType());
			        	
				        
			        	
			        	if(this.isProductReturn())
			        	{
			        		billProductInfoDAO.setProductName(productBarcodeDetails.getProductNameEn()+"-RTN");
			        		billProductInfoDAO.setProductNameMarathi(productBarcodeDetails.getProductNameMr()+"-RTN");
			        		billProductInfoDAO.setProductReturn(true);
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setProductName(productBarcodeDetails.getProductNameEn());
			        		billProductInfoDAO.setProductNameMarathi(productBarcodeDetails.getProductNameMr());
			        		billProductInfoDAO.setProductReturn(false);
			        	}
			        	billProductInfoDAO.setProductCode(productBarcodeDetails.getProductCode());
			        	
			        	billProductInfoDAO.setSalesUnit(productBarcodeDetails.getSalesUnit());
			        	billProductInfoDAO.setTaxId(""+productBarcodeDetails.getTaxId());
			        	billProductInfoDAO.setSalesRate(productBarcodeDetails.getBarcodeMRP());
			        	if(isAddQuantity2())
			        	{
			        		billProductInfoDAO.setQuantity2(this.getQuantity2());
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setQuantity2(0.0F);
			        		
			        	}
			        	billProductInfoDAO.setQuantity(productBarcodeDetails.getBarCodeQuantity());
			        	billProductInfoDAO.setDiscountPecentage(productBarcodeDetails.getDiscount());
			        	billProductInfoDAO.setDiscountRupees(productBarcodeDetails.getBarcodeMRP()- productBarcodeDetails.getSalesPrice());
			        	if(this.isProductReturn())
			        	{
			        		billProductInfoDAO.setAmount(-(productBarcodeDetails.getBarcodeMRP()));
			        		billProductInfoDAO.setAmountAfterDiscount(-(productBarcodeDetails.getSalesPrice()));
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setAmount(productBarcodeDetails.getBarcodeMRP());
			        		billProductInfoDAO.setAmountAfterDiscount(productBarcodeDetails.getSalesPrice());
			        	}
			        	
			            billProductInfoDAO.setAlias(this.getAlias());
		                billProductInfoDAO.setSalesmanId(this.getSalesmanId());
			        	billProductInfoDAO.setAddedToDB(false);
			        	billProductInfoDAO.setShopId(shopId);
			        	billProductInfoDAO.setShopCode(shopCode);
			        	
			        
			        	if(settings.get("add_making_charge_column").equals("TRUE"))
			        	{
			        		billProductInfoDAO.setMakingLaborCharge(this.getMakingLabourAmount());
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setMakingLaborCharge(0.0F);
			        		this.setMakingLabourAmount(0.0F);
			        	}
			        	
			        	
			        	float floatAmountAftDiscount = productBarcodeDetails.getSalesPrice();
			        	float totalProductDiscount = productBarcodeDetails.getBarcodeMRP() - floatAmountAftDiscount;
			        	
			        	
			        	float sgst = 0.0F;
			        	float cgst = 0.0F;
			        	float igst = 0.0F;
			        	
						if(this.getBillType().equals("TAX-INVOICE"))
						{
						
							Map<String,String> taxInfo = GetListResource.GetTaxNamePercentage(""+productBarcodeDetails.getTaxId(),this.getSessionMap());
				        	
							String taxName = taxInfo.get("TAX-NAME");
							String taxPercentage = taxInfo.get("TAX-PERCENTAGE");
							
							billProductInfoDAO.setTaxName(taxName);
							billProductInfoDAO.setTaxPercentage(Float.parseFloat(taxPercentage));
							
							if(this.getRateType().equals("INCLUDEGST"))
							{
								
								float floatTaxRate = Float.parseFloat(taxPercentage);	
								
								float basicTax = floatTaxRate+100.0F;
					        	
					        	float grossAmount = (floatAmountAftDiscount / basicTax) * 100.0F;
					        	
					        	float totalTax = floatAmountAftDiscount - grossAmount;
								
								if(taxName.toUpperCase().contains("IGST"))
								{
									igst = totalTax;
								}
								else
								{
									sgst = totalTax/2.0F;
						        	cgst = totalTax/2.0F;
								}
				        	
				        	     
								 DecimalFormat df = new DecimalFormat("0.00");
							        
						        	
					        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
					        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(grossAmount)));
					        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
					        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
					        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
					        	 if(this.isProductReturn())
						         {
							        	 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
							        	 billProductInfoDAO.setAmount(-(productBarcodeDetails.getBarcodeMRP() + this.getMakingLabourAmount()));
						         }
					        	 else
					        	 {
					        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
						        	 billProductInfoDAO.setAmount(productBarcodeDetails.getBarcodeMRP() + this.getMakingLabourAmount());

					        	 }
							}
							
							if(this.getRateType().equals("EXCLUDEGST"))
							{
								float floatTaxRate = Float.parseFloat(taxPercentage);	
								float totalTax = floatAmountAftDiscount * (floatTaxRate/100.0F);
								
								if(taxName.toUpperCase().contains("IGST"))
								{
									igst = totalTax;
								}
								else
								{
									sgst = totalTax/2.0F;
						        	cgst = totalTax/2.0F;
								}
								
								
								 DecimalFormat df = new DecimalFormat("0.00");
							        
						        	
					        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
					        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(floatAmountAftDiscount)));
					        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
					        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
					        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
					        	 if(this.isProductReturn())
						         {
					        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount()));
					        		billProductInfoDAO.setAmount(-(productBarcodeDetails.getBarcodeMRP() + totalTax  + this.getMakingLabourAmount()));
						         }
					        	 else
					        	 {
					        	   	 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount());
						        	 billProductInfoDAO.setAmount(productBarcodeDetails.getBarcodeMRP() + totalTax  + this.getMakingLabourAmount());
							  
					        	 }
							}
						}
						else
						{
							 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(floatAmountAftDiscount);
				        	 billProductInfoDAO.setSgst(0.0F);
				        	 billProductInfoDAO.setCgst(0.0F);
				        	 billProductInfoDAO.setIgst(0.0F);
				        	 if(this.isProductReturn())
					         {
				        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
				        		 billProductInfoDAO.setAmount(-(productBarcodeDetails.getBarcodeMRP() + this.getMakingLabourAmount()));
					         }
				        	 else
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
				        		 billProductInfoDAO.setAmount(productBarcodeDetails.getBarcodeMRP() + this.getMakingLabourAmount());
					        
				        	 }
						}
				}
	        	
	        	
	        	
	        	 // Ensure return items are negative
	        	 if(billProductInfoDAO.getProductReturn()!=null && billProductInfoDAO.getProductReturn())
	        	 {
	        	 	billProductInfoDAO.setAmount(-Math.abs(billProductInfoDAO.getAmount()));
	        	 	billProductInfoDAO.setAmountAfterDiscount(-Math.abs(billProductInfoDAO.getAmountAfterDiscount()));
	        	 }
	        	 
	        	 
	        	 
	        	    billProductInfoDAO.setSalesmanId(this.getSalesmanId());
					
	        	    
	        	 this.getProductInfoList().add(billProductInfoDAO);
	        	
	        	float floatTotalAmount = 0.0F;
	        	float floatTotalDiscount = 0.0F;
	        	float floatTotalAmtAfterDiscount = 0.0F;
	        	
	        	
	        	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
	        	{
	        		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
	        		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
	        		floatTotalDiscount = floatTotalDiscount + infoDAO.getProductTotalDiscount();
	        		
	        	}
	        	
        		
	        	String custData [] = new String [5];
	        	try
	        	{
	        		//System.out.println(this.getCustomerIdNameAll());
	        		
	        		
	        		custData = this.getCustomerIdNameAll().split("-");
	        		
	        		if(custData.length > 2)
	        		{
		        		this.getBillInfoDAO().setCustId(custData[0]);
		        		this.getBillInfoDAO().setCustomerName(this.getCustomerName());
		        		this.getBillInfoDAO().setCustomerMobile(custData[2]);
		        		this.getBillInfoDAO().setCustomerType(this.getCustomerType());
		        		this.getBillInfoDAO().setCustomerIdNameAll(this.getCustomerIdNameAll());
		        		
		        		
	        		}
	        		else
	        		{
	        			this.getBillInfoDAO().setCustId("1");
		        		this.getBillInfoDAO().setCustomerName("1-"+custData[0]+"-"+custData[1]+"-REGULER");
		        		this.getBillInfoDAO().setCustomerMobile(custData[1]);
		        		this.getBillInfoDAO().setCustomerType(this.getCustomerType());
		        		
		        		this.setCustomerName("1-"+custData[0]+"-"+custData[1]+"-REGULER");
		        		this.getBillInfoDAO().setCustomerIdNameAll("1-"+custData[0]+"-"+custData[1]+"-REGULER");
	        		}
	        		
	        	}catch(Exception e)
	        	{
	        		this.getBillInfoDAO().setCustId("1");
	        		this.getBillInfoDAO().setCustomerMobile("9999999999");
	        		this.getBillInfoDAO().setCustomerName("1-"+this.getCustomerName().trim().toUpperCase()+"-9999999999-REGULER");  
	        		this.getBillInfoDAO().setCustomerType("REGULETR");
	        		this.getBillInfoDAO().setCustomerIdNameAll("1-"+custData[0]+"-"+custData[1]+"-REGULER");
	        	}
	        	
	        	
	        	
	        	
	         	this.getBillInfoDAO().setBillNumber(getBillNumber());	     
	        	this.getBillInfoDAO().setBillDate(this.getBillDateTime());
	        	this.getBillInfoDAO().setPaymentType(getPaymentType());
	        	this.getBillInfoDAO().setBillType(getBillType());
	        
	        	this.getBillInfoDAO().setBillSaved(false);
	        	this.getBillInfoDAO().setSendSMS(this.isSendSMS());
	        	this.getBillInfoDAO().setTransportCharge(this.getTransportCharge());
	        	String custMobNum  = "0";
	        	
	        	if(this.getBillInfoDAO().getCustomerMobile() == null || this.getBillInfoDAO().getCustomerMobile().equals(""))
	        	{
	        	
		        	String [] custData2 = new String[5];
		        	
		        	try
		        	{
		        		custData2 = this.getCustomerName().split("-");
		        		custMobNum = custData2[2];
		        		if(!(custMobNum.length() == 10) || custMobNum.contains("999999"))
		        		{
		        			this.getBillInfoDAO().setSendSMS(false);
		        		}
		        		
		        	}
		        	catch(Exception e)
		        	{
		        		if(getAlternateMobileNumber().length()==10)
		        		{
		        			custMobNum = getAlternateMobileNumber();
		        			this.getBillInfoDAO().setSendSMS(true);
		        		}
		        		else
		        		{
		        			this.getBillInfoDAO().setSendSMS(false);
		        		}
		        	}
		        	this.getBillInfoDAO().setCustomerMobile(custMobNum.trim());
	        	}
	        	//System.out.println("view : "+viewBill);
	        	
	        	this.setTotalAmount(floatTotalAmount);	        	
	        	this.setTotalDiscount(floatTotalDiscount);
	        	this.setTotalAmouAfterDisount(floatTotalAmtAfterDiscount);
	        	this.setCashAmount(floatTotalAmtAfterDiscount);
		    	this.setBankRtgsUpiAmount(0.0F);
		    	
	        	addActionMessage("Product added successfully to list !");
	        	this.setRemoveVaules("true");
	        	
	        	
	        	if(this.getPaymentType().equals("CASH"))
	        	{
	        		this.setAmountPaid(this.getTotalAmouAfterDisount());
	        		this.setReturnAmount(0.0F);
	        	}
	        	if(this.getPaymentType().equals("CREDIT")){
	        		this.setAmountPaid(0.0F);
	        		this.setReturnAmount(-this.getTotalAmouAfterDisount());
	        	}
	        	this.getSessionMap().put("billInformation", this.getBillInfoDAO());
	        	this.getSessionMap().put("productList", this.getProductInfoList());
	        	
	        	
	        	this.setProductCode("");
	        	
	        	this.setQuantity(0.0F);
	        	this.setSalesRate(0.0F);
	        	this.setAmount(0.0F);
	        	this.setDiscountRupees(0.0F);
	        	this.setAmountAfterDiscount(0.0F);
	        	this.setMakingLabourAmount(0.0F);
	        	this.setQuantity2(0.0F);
	        	this.setProductReturn(false);
	        	result = SUCCESS;
	        	
	        	this.setBillSaved(false);
	     }
    	else // By Product Name
    	{
	        		String addDuplicateProductToList = settings.get("add_duplicate_items_to_bill");
	        		
	        		boolean duplicateProductFound = false;
		        	
		        	BillProductInfoDAO OldBillProductInfoDAO = null;
		        	

				    String actualProductName = ""; 
					String productId = "";
					String productCode = "";
					try
					{
						productId = this.getProductName().split("-")[0];
						actualProductName = this.getProductName().split("-")[1];
						productCode = resolveProductShortCodeForBarcodeComposite(productId, this.getProductName().split("-")[2]);
					}
					catch (Exception e) {
						actualProductName = this.getProductName();
						addActionError("Please provide correct product name (with -)! ");
					}
		        	
		        	int index = 0;
		        	int removeIndex = 0;
		        	
		        	if(addDuplicateProductToList.equals("TRUE"))
		    		{
		    			
		    					for(BillProductInfoDAO infoDAO:this.getProductInfoList())
		    					{
		    							if(infoDAO.getProductName().equals(actualProductName))
		    							{
		    								duplicateProductFound = true;	    								
		    								OldBillProductInfoDAO = infoDAO;
		    								removeIndex = index;	    								
		    							}
		    						index++;
		    					}
		    				
		    		}
		        	
		        	BillProductInfoDAO billProductInfoDAO = null;
		        	
		        	
		        	
		        	if(duplicateProductFound)
		        	{

		        		this.getProductInfoList().remove(removeIndex);		        		
		        		billProductInfoDAO = new BillProductInfoDAO();		        		
		        		billProductInfoDAO.setId(null);	        	
			        	billProductInfoDAO.setSerialNumber(""+(listSize+1));
			        	billProductInfoDAO.setProductId(productId);
			        	billProductInfoDAO.setProductCode(productCode);
			         	billProductInfoDAO.setSerialNoBatchId(this.getSerailNoBatchId());
					       
			        	if(this.isProductReturn())
				         {
			        		billProductInfoDAO.setProductName(actualProductName+"-RTN");
				        	
			        		billProductInfoDAO.setProductNameMarathi(OldBillProductInfoDAO.getProductNameMarathi()+"-RTN");
				     
				         }
			        	else
			        	{
			        		billProductInfoDAO.setProductName(actualProductName);
				        	
			        		billProductInfoDAO.setProductNameMarathi(OldBillProductInfoDAO.getProductNameMarathi());
				        	
			        	}
			        	billProductInfoDAO.setSalesUnit(OldBillProductInfoDAO.getSalesUnit());
			        	billProductInfoDAO.setTaxId(""+OldBillProductInfoDAO.getTaxId());
			        	billProductInfoDAO.setSalesRate(OldBillProductInfoDAO.getSalesRate());
			        	billProductInfoDAO.setRateType(this.getRateType());
			        	
			        	
			        	if(isAddQuantity2())
			        	{
			        		billProductInfoDAO.setQuantity2(this.getQuantity2());
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setQuantity2(0.0F);
			        		
			        	}
			        	
			        	
			        	billProductInfoDAO.setQuantity(this.getQuantity() + OldBillProductInfoDAO.getQuantity());
			        	float disRs = this.getAmount() - this.getAmountAfterDiscount();
			        	billProductInfoDAO.setDiscountRupees(disRs+OldBillProductInfoDAO.getDiscountRupees());
			        	billProductInfoDAO.setDiscountPecentage(disRs+OldBillProductInfoDAO.getDiscountRupees());
			        	if(this.isProductReturn())
				         {
			        		billProductInfoDAO.setAmount(-(this.getAmount()+OldBillProductInfoDAO.getAmount()));
			        		billProductInfoDAO.setAmountAfterDiscount(-(billProductInfoDAO.getAmount()-billProductInfoDAO.getDiscountRupees()));
				         }
			        	else
			        	{
			        		billProductInfoDAO.setAmount(this.getAmount()+OldBillProductInfoDAO.getAmount());
			        		billProductInfoDAO.setAmountAfterDiscount(billProductInfoDAO.getAmount()-billProductInfoDAO.getDiscountRupees());

			        	}
                    billProductInfoDAO.setAlias(this.getAlias());
                  	billProductInfoDAO.setAddedToDB(false);
			        	billProductInfoDAO.setShopId(shopId);
			        	billProductInfoDAO.setShopCode(shopCode);
			        	
			      
			        	if(settings.get("add_making_charge_column").equals("TRUE"))
			        	{
			        		billProductInfoDAO.setMakingLaborCharge(this.getMakingLabourAmount()+OldBillProductInfoDAO.getMakingLaborCharge());
			        	}
			        	else
			        	{
			        		billProductInfoDAO.setMakingLaborCharge(0.0F);
			        		this.setMakingLabourAmount(0.0F);
			        	}
			        	
			        	
			        	
			        	float floatAmountAftDiscount = billProductInfoDAO.getAmountAfterDiscount();
			        	float totalProductDiscount = billProductInfoDAO.getDiscountRupees();
			       
			        	float sgst = 0.0F;
			        	float cgst = 0.0F;
			        	float igst = 0.0F;
			        	
						if(this.getBillType().equals("TAX-INVOICE"))
						{
						
							Map<String,String> taxInfo = GetListResource.GetTaxNamePercentage(""+this.getTaxId(),this.getSessionMap());
				        	
							String taxName = taxInfo.get("TAX-NAME");
							String taxPercentage = taxInfo.get("TAX-PERCENTAGE");
							
							billProductInfoDAO.setTaxName(taxName);
							billProductInfoDAO.setTaxPercentage(Float.parseFloat(taxPercentage));
							
							if(this.getRateType().equals("INCLUDEGST"))
							{
								
								float floatTaxRate = Float.parseFloat(taxPercentage);	
								
								float basicTax = floatTaxRate+100.0F;
					        	
					        	float grossAmount = (floatAmountAftDiscount / basicTax) * 100.0F;
					        	
					        	float totalTax = floatAmountAftDiscount - grossAmount;
								
								if(taxName.toUpperCase().contains("IGST"))
								{
									igst = totalTax;
								}
								else
								{
									sgst = totalTax/2.0F;
						        	cgst = totalTax/2.0F;
								}
				        	
				        	     
								 DecimalFormat df = new DecimalFormat("0.00");
							        
						        	
					        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
					        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(grossAmount)));
					        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
					        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
					        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
					        		if(this.isProductReturn())
							         {
							        	 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
							        	 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
							         }
					        		else
					        		{
					        			 billProductInfoDAO.setAmountAfterDiscount((floatAmountAftDiscount + this.getMakingLabourAmount()));
							        	 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());

					        		}
					        	 
					        	 
							}
							
							if(this.getRateType().equals("EXCLUDEGST"))
							{
								float floatTaxRate = Float.parseFloat(taxPercentage);	
								float totalTax = floatAmountAftDiscount * (floatTaxRate/100.0F);
								
								if(taxName.toUpperCase().contains("IGST"))
								{
									igst = totalTax;
								}
								else
								{
									sgst = totalTax/2.0F;
						        	cgst = totalTax/2.0F;
								}
								
								
								 DecimalFormat df = new DecimalFormat("0.00");
							        
						        	
					        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
					        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(floatAmountAftDiscount)));
					        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
					        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
					        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
					        	 if(this.isProductReturn())
						         {
					        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount()));
					        	     billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount()));
						         }
					        	 else
					        	 {	
					        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount());
				        	     	 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount());
							             		 
					        	 }
							}
						}
						else
						{
							 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(floatAmountAftDiscount);
				        	 billProductInfoDAO.setSgst(0.0F);
				        	 billProductInfoDAO.setCgst(0.0F);
				        	 billProductInfoDAO.setIgst(0.0F);
				        	 if(this.isProductReturn())
					         {
				        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
				        		 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
					         }
				        	 else
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
				        		 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());
				        	 }
						} 
					
		        	}
		        	else
		        	{
					
		        	 billProductInfoDAO = new BillProductInfoDAO();
		        	
		        	billProductInfoDAO.setId(null);	        	
		        	billProductInfoDAO.setSerialNumber(""+(listSize+1));
		        	billProductInfoDAO.setProductId(this.getProductName().split("-")[0]);
		        	billProductInfoDAO.setSerialNoBatchId(this.getSerailNoBatchId());
		        	billProductInfoDAO.setRateType(this.getRateType());
		        	
		        	 if(this.isProductReturn())
			         {
		        			billProductInfoDAO.setProductName(this.getProductName().split("-")[1]+"-RTN");
		        			billProductInfoDAO.setProductNameMarathi(this.getProductMarathiName()+"-RTN");
		    		        
			         }
		        	 else
		        	 {
		        		 	billProductInfoDAO.setProductName(this.getProductName().split("-")[1]);
		        			billProductInfoDAO.setProductNameMarathi(this.getProductMarathiName());
		        	 }
		        	billProductInfoDAO.setProductCode(
		        			resolveProductShortCodeForBarcodeComposite(this.getProductName().split("-")[0], this.getProductName().split("-")[2]));
		        	billProductInfoDAO.setSalesUnit(this.getSalesUnit());
		        	billProductInfoDAO.setTaxId(this.getTaxId());
		        	billProductInfoDAO.setSalesRate(this.getSalesRate());
		        	if(isAddQuantity2())
		        	{
		        		billProductInfoDAO.setQuantity2(this.getQuantity2());
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setQuantity2(0.0F);
		        		
		        	}
		        	billProductInfoDAO.setQuantity(this.getQuantity());
		        	billProductInfoDAO.setDiscountPecentage(this.getDiscountPercentage());
		        	billProductInfoDAO.setDiscountRupees(this.getDiscountRupees());
		        	if(this.isProductReturn())
			         {
		        		billProductInfoDAO.setAmount(-this.getAmount());
		        		billProductInfoDAO.setAmountAfterDiscount(-this.getAmountAfterDiscount());
			         }
		        	else
		        	{
		        		billProductInfoDAO.setAmount(this.getAmount());
		        		billProductInfoDAO.setAmountAfterDiscount(this.getAmountAfterDiscount());
		        	}
                    billProductInfoDAO.setAlias(this.getAlias());
                    billProductInfoDAO.setSalesmanId(this.getSalesmanId());
		        	billProductInfoDAO.setAddedToDB(false);
		        	billProductInfoDAO.setShopId(shopId);
		        	billProductInfoDAO.setShopCode(shopCode);
		        	
		        
		        	if(settings.get("add_making_charge_column").equals("TRUE"))
		        	{
		        		billProductInfoDAO.setMakingLaborCharge(this.getMakingLabourAmount());
		        	}
		        	else
		        	{
		        		billProductInfoDAO.setMakingLaborCharge(0.0F);
		        		this.setMakingLabourAmount(0.0F);
		        	}
		        	}
		        	
		        	
		        	float floatAmountAftDiscount = billProductInfoDAO.getAmountAfterDiscount();
		        	float totalProductDiscount = billProductInfoDAO.getDiscountRupees();
		        	
		        	
		        	float sgst = 0.0F;
		        	float cgst = 0.0F;
		        	float igst = 0.0F;
		        	
					if(this.getBillType().equals("TAX-INVOICE"))
					{
					
						Map<String,String> taxInfo = GetListResource.GetTaxNamePercentage(this.getTaxId(),this.getSessionMap());
			        	
						String taxName = taxInfo.get("TAX-NAME");
						String taxPercentage = taxInfo.get("TAX-PERCENTAGE");
						
						billProductInfoDAO.setTaxName(taxName);
						billProductInfoDAO.setTaxPercentage(Float.parseFloat(taxPercentage));
						
						if(this.getRateType().equals("INCLUDEGST"))
						{
							
							float floatTaxRate = Float.parseFloat(taxPercentage);	
							
							float basicTax = floatTaxRate+100.0F;
				        	
				        	float grossAmount = (floatAmountAftDiscount / basicTax) * 100.0F;
				        	
				        	float totalTax = floatAmountAftDiscount - grossAmount;
							
							if(taxName.toUpperCase().contains("IGST"))
							{
								igst = totalTax;
							}
							else
							{
								sgst = totalTax/2.0F;
					        	cgst = totalTax/2.0F;
							}
			        	
			        	     
							 DecimalFormat df = new DecimalFormat("0.00");
						        
					        	
				        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(grossAmount)));
				        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
				        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
				        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
				        		if(this.isProductReturn())
						         {
				        			billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
				        			billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
						         }
				        		else
				        		{
				        			billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
				        			billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());
				        		}
						}
						
						if(this.getRateType().equals("EXCLUDEGST"))
						{
							float floatTaxRate = Float.parseFloat(taxPercentage);	
							float totalTax = floatAmountAftDiscount * (floatTaxRate/100.0F);
							
							if(taxName.toUpperCase().contains("IGST"))
							{
								igst = totalTax;
							}
							else
							{
								sgst = totalTax/2.0F;
					        	cgst = totalTax/2.0F;
							}
							
							
							 DecimalFormat df = new DecimalFormat("0.00");
						        
					        	
				        	 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
				        	 billProductInfoDAO.setGrossAmount(Float.valueOf(df.format(floatAmountAftDiscount)));
				        	 billProductInfoDAO.setSgst(Float.valueOf(df.format(sgst)));
				        	 billProductInfoDAO.setCgst(Float.valueOf(df.format(cgst)));
				        	 billProductInfoDAO.setIgst(Float.valueOf(df.format(igst)));
				        	 if(this.isProductReturn())
					         {
				        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount()));
				        		 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount()));
					         }
				        	 else
				        	 {
				        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + totalTax + this.getMakingLabourAmount());
				        		 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + totalTax  + this.getMakingLabourAmount()); 
				        	 }
						}
					}
					else
					{
						 billProductInfoDAO.setProductTotalDiscount(totalProductDiscount);
			        	 billProductInfoDAO.setGrossAmount(floatAmountAftDiscount);
			        	 billProductInfoDAO.setSgst(0.0F);
			        	 billProductInfoDAO.setCgst(0.0F);
			        	 billProductInfoDAO.setIgst(0.0F);
			        	 if(this.isProductReturn())
				         {
			        		 billProductInfoDAO.setAmountAfterDiscount(-(floatAmountAftDiscount + this.getMakingLabourAmount()));
			        		 billProductInfoDAO.setAmount(-(billProductInfoDAO.getAmount() + this.getMakingLabourAmount()));
				         }
			        	 else
			        	 {
			        		 billProductInfoDAO.setAmountAfterDiscount(floatAmountAftDiscount + this.getMakingLabourAmount());
				        	 billProductInfoDAO.setAmount(billProductInfoDAO.getAmount() + this.getMakingLabourAmount());
			        	 }
					}
					
			         // Ensure return items are negative
			         if(billProductInfoDAO.getProductReturn()!=null && billProductInfoDAO.getProductReturn())
			         {
			         	billProductInfoDAO.setAmount(-Math.abs(billProductInfoDAO.getAmount()));
			         	billProductInfoDAO.setAmountAfterDiscount(-Math.abs(billProductInfoDAO.getAmountAfterDiscount()));
			         }
			         
			         billProductInfoDAO.setSalesmanId(this.getSalesmanId());
					    
			         this.getProductInfoList().add(billProductInfoDAO);
		        	
		        	float floatTotalAmount = 0.0F;
		        	float floatTotalDiscount = 0.0F;
		        	float floatTotalAmtAfterDiscount = 0.0F;
		        	
		        	
		        	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
		        	{
		        		
		        		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
		        		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
		        		floatTotalDiscount = floatTotalDiscount + infoDAO.getProductTotalDiscount();
		        		
		        	}

		        	String custData [] = new String [5];
		        	try
		        	{
		        		custData = this.getCustomerIdNameAll().split("-");
		        	
		        		

		        		if(custData.length > 2)
		        		{
			        		this.getBillInfoDAO().setCustId(custData[0]);
			        		this.getBillInfoDAO().setCustomerName(this.getCustomerName());
			        		this.getBillInfoDAO().setCustomerMobile(custData[2]);
			        		this.getBillInfoDAO().setCustomerType(this.getCustomerType());
			        		this.getBillInfoDAO().setCustomerIdNameAll(this.getCustomerIdNameAll());
			        		
			        		
		        		}
		        		else
		        		{
		        			this.getBillInfoDAO().setCustId("1");
			        		this.getBillInfoDAO().setCustomerName("1-"+custData[0]+"-"+custData[1]+"-REGULER");
			        		this.getBillInfoDAO().setCustomerMobile(custData[1]);
			        		this.getBillInfoDAO().setCustomerType(this.getCustomerType());
			        		
			        		this.setCustomerName("1-"+custData[0]+"-"+custData[1]+"-REGULER");
			        		this.getBillInfoDAO().setCustomerIdNameAll("1-"+custData[0]+"-"+custData[1]+"-REGULER");
		        		}
		        		
		        	}catch(Exception e)
		        	{
		        		this.getBillInfoDAO().setCustId("1");
		        		this.getBillInfoDAO().setCustomerMobile("9999999999");
		        		this.getBillInfoDAO().setCustomerName("1-"+this.getCustomerName().trim().toUpperCase()+"-9999999999-REGULER");  
		        		this.getBillInfoDAO().setCustomerIdNameAll(this.getCustomerIdNameAll());
		        	}
		        	
		        	
		        	
		         	this.getBillInfoDAO().setBillNumber(getBillNumber());	     
		        	this.getBillInfoDAO().setBillDate(this.getBillDateTime());
		        	this.getBillInfoDAO().setPaymentType(getPaymentType());
		        	this.getBillInfoDAO().setBillType(getBillType());
		        		
		        	this.getBillInfoDAO().setBillSaved(false);
		        	this.getBillInfoDAO().setSendSMS(this.isSendSMS());
		        	this.getBillInfoDAO().setTransportCharge(this.getTransportCharge());
		        	String custMobNum  = "0";
		        	
		        	if(this.getBillInfoDAO().getCustomerMobile() == null || this.getBillInfoDAO().getCustomerMobile().equals(""))
		        	{
		        	
			        	String [] custData2 = new String[5];
			        	
			        	try
			        	{
			        		custData2 = this.getCustomerName().split("-");
			        		custMobNum = custData2[2];
			        		if(!(custMobNum.length() == 10) || custMobNum.contains("999999"))
			        		{
			        			this.getBillInfoDAO().setSendSMS(false);
			        		}
			        		
			        	}
			        	catch(Exception e)
			        	{
			        		if(getAlternateMobileNumber().length()==10)
			        		{
			        			custMobNum = getAlternateMobileNumber();
			        			this.getBillInfoDAO().setSendSMS(true);
			        		}
			        		else
			        		{
			        			this.getBillInfoDAO().setSendSMS(false);
			        		}
			        	}
			        	this.getBillInfoDAO().setCustomerMobile(custMobNum.trim());
		        	}
		        	//System.out.println("view : "+viewBill);
		        	
		        	this.setTotalAmount(floatTotalAmount);	        	
		        	this.setTotalDiscount(floatTotalDiscount);
		        	this.setTotalAmouAfterDisount(floatTotalAmtAfterDiscount);
		        	this.setCashAmount(floatTotalAmtAfterDiscount);
			    	this.setBankRtgsUpiAmount(0.0F);
			    	
		        	addActionMessage("Product added successfully to list !");
		        	this.setRemoveVaules("true");
		        	
		        	
		        	if(this.getPaymentType().equals("CASH"))
		        	{
		        		this.setAmountPaid(this.getTotalAmouAfterDisount());
		        		this.setReturnAmount(0.0F);
		        	}
		        	
		        	if(this.getPaymentType().equals("CREDIT")){
		        		this.setAmountPaid(0.0F);
		        		this.setReturnAmount(-this.getTotalAmouAfterDisount());
		        	}
		        	
		        	this.getSessionMap().put("billInformation", this.getBillInfoDAO());
		        	this.getSessionMap().put("productList", this.getProductInfoList());
		        	
		        	this.setProductCode("");
		        	this.setProductName("");
		        	this.setQuantity(0.0F);
		        	this.setSalesRate(0.0F);
		        	this.setAmount(0.0F);
		        	this.setDiscountRupees(0.0F);
		        	this.setAmountAfterDiscount(0.0F);
		        	this.setMakingLabourAmount(0.0F);
		        	this.setQuantity2(0.0F);
		        	this.setProductReturn(false);
		        	result = SUCCESS;
		        	
		        	this.setBillSaved(false);
	        	}
	        	
	        }
	     
	        return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public void validate() {
		// Mirror checkbox mapping for safety during validation rerenders
		try{
			HttpServletRequest req = ServletActionContext.getRequest();
			String pr = req.getParameter("productReturn");
			if(pr != null){
				this.setProductReturn("true".equalsIgnoreCase(pr) || "on".equalsIgnoreCase(pr));
			}
		}catch(Exception ignore){}
		
		this.getRateTypeList().put("INCLUDEGST", "WITH GST");
    	this.getRateTypeList().put("EXCLUDEGST", "WITH-OUT GST");
    	
    	this.getLabourChargeTypeList().put("QUANTITYWISE", "BY QUANTITY");
    	this.getLabourChargeTypeList().put("PERCENTAGEWISE", "BY PERCENTAGE");
    	
    	this.getDiscountTypeList().put("PERCENTAGE", "PERCENTAGE");
    	this.getDiscountTypeList().put("PERQUANTITY", "PERQUANTITY");
     	this.setCustomerTypeList(GetListResource.getCustomerTypeList());
	       
	
		boolean billByProductName = false;
		
		 if(!this.getProductName().equals(""))
		 {
			 billByProductName = true;
		 }
		 
		
		
		session=ServletActionContext.getRequest().getSession(false); 
		List<BillProductInfoDAO> productInfoListTest = (List<BillProductInfoDAO>) this.getSessionMap().get("productList");
		
		//String checkCustName = (String) sessionMap.get("checkCustName");
    	
	  	this.setBillInfoDAO((BillInformationDAO) this.getSessionMap().get("billInformation"));
		
		paymentTypeList.put("CASH","CASH");
    	paymentTypeList.put("CREDIT","CREDIT");
    	
    	if(productInfoListTest == null)
    	{    	
    		setDefaultValue("CASH");
    	}
    	else
    	{
    		setDefaultValue(getPaymentType());
    	}
    	
    	
    	
    	

    
			taxList = GetListResource.GetTaxList(this.getSessionMap());
		
    	
    	unitList = GetListResource.GetUnitList();
    	billTypeList = GetListResource.GetBillTypeList();
    	//setBillType(billTypeList.get("CASH-MEMO"));
    	 if(billByProductName)
		 {
			if(this.getCustomerName() == null || this.getProductName().equals(""))
			{
				addActionError("Fields marked with astrik(*) are mandetory 1!");
			}
		 }    	 
    	 else
    	 {
    		 if(this.getCustomerName() == null || this.getProductCode().equals(""))
 			{
 				addActionError("Fields marked with astrik(*) are mandetory 1!");
 			} 
    	 }
		
		
		if(getCustomerName().equals("Customer_Not_Found"))
		{
			addActionError("Given customer name is not correct !");
		}
		
		if(!hasActionErrors())
		{
			if(this.getRateType() == null || this.getRateType().equals(""))
			{
				addActionError("Please select rate type!");
			}
		}
		
	if(!billByProductName)
	{
		HashMap<String,ProductBarcodeDetailsDAO> productBarcodeDetailsMap = (HashMap<String, ProductBarcodeDetailsDAO>) this.getSessionMap().get("barcodeProductDetails");
    	
		ProductBarcodeDetailsDAO productDetails = productBarcodeDetailsMap.get(this.getProductCode().trim());

	if(productDetails != null)
	{
		if(!hasActionErrors())
		{

			String isCustomerAdded = "false";
			
			String [] result = new String[2];
			
			result = new CheckAlreadyAvailable().checkAvaibility("shop_product_master", "product_name_eng", "NA", productDetails.getProductNameEn(), this.getSessionMap());
			
			isCustomerAdded = result[0];
			
			if(!isCustomerAdded.equals("true"))
			{
				addActionError("Product name given not found ! Please provide correct product name !");
			}	
			
		}
	
		
		HashMap<String,String> shopSettingsMap = (HashMap<String, String>) this.getSessionMap().get("shop_settings");
		
		
    	if(shopSettingsMap.get("add_quntity2").equals("TRUE"))
    	{
    		this.setAddQuantity2(true);
    	}
    	else
    	{
    		this.setAddQuantity2(false);
    	}
		String addDuplicateProductToList = shopSettingsMap.get("add_duplicate_items_to_bill");
		
	
		if(!hasActionErrors())
		{
			
			if(isAddQuantity2())
			{
				if(this.getQuantity2() == null || this.getQuantity2().equals(""))
				{
					addActionError("Please provide 2nd quanity !");
				}
				else
				{
					 if(!this.isProductReturn())
			         {
							try
				    		{
				    		String dbStockQuantity = GetProductStockByName.getProductStockByName2ndQty(productDetails.getProductId(),productDetails.getProductCode(),this.getSessionMap());
				    		
				    		if(!dbStockQuantity.equals("NA"))
				    		{
				    			float dbStockQuantityFloat = Float.parseFloat(dbStockQuantity);
				    			
				    			if(dbStockQuantityFloat == 0 || dbStockQuantityFloat < 0)
				    			{
				    				addActionError("2 nd Quantity is less ("+dbStockQuantity+") in stock of "+this.getProductName()+"! Cannot Sale!");
				    			}else
				    			{
				    				float saleProductQuantity =this.getQuantity();
				    				
				    				float diffToUpdateQuantity = dbStockQuantityFloat - saleProductQuantity;
				    				
				    				if(diffToUpdateQuantity < 0)
				    				{
				    					addActionError("2 nd Quantity is less ("+dbStockQuantity+") in stock of "+productDetails.getProductNameEn()+"! Cannot Sale!");
				    				}
				    			}
				    			
				    		}
				    		else
				    		{
				    			addActionError("Error while getting DB stock quantity of product 1!");
				    		}
				    		
				    		}catch(Exception e)
				    		{
				    			addActionError("Error while getting DB stock quantity of product 2!");
				    		}
			         }
				}
			
	         }
		}
	
		if(addDuplicateProductToList.equals("FALSE"))
		{
			if(productInfoListTest !=null)
			{
				if(!productInfoListTest.isEmpty())
				{
					for(BillProductInfoDAO infoDAO:productInfoListTest)
					{
					
						
							if(infoDAO.getProductName().equals(productDetails.getProductNameEn()))
							{
								addActionError("Product is alredy added to list!");
								productInfoList = productInfoListTest;
							}
						
						
					}
				}
				else
				{
					this.setProductInfoList(productInfoListTest);
				}
			}
		}
		
		
		
    	
    	if(getCustomerName().equals("Customer_Not_Found"))
    	{
    		addActionError("Please Provide Correct Customer Name !");
    	}
    	
    	
    	if(!hasActionErrors())
    	{
    		if(this.getPaymentType().equals("CREDIT") && !this.getCustomerIdNameAll().equals("Customer_Not_Found"))
    		{
    			this.setDefaultValue(this.getPaymentType());
    			String isCustomerAdded = "false";
    			String [] custData = new String [5];
    			try
    			{
    				//System.out.println(this.getCustomerIdNameAll());
    				
	    			custData = this.getCustomerIdNameAll().split("-");
	    			
	    			String [] result = new String[2];
	    			String condition  = " or mobile_number = '"+custData[2]+"' ";
	    			
	    			
	    			result = new CheckAlreadyAvailable().checkAvaibility("shop_customer_master", "customer_name", condition, custData[1], this.getSessionMap());
	    			
	    			isCustomerAdded = result[0];
	    			
	    			if(isCustomerAdded.equals("false"))
	    			{
	    				addActionError("If Payment is 'CREDIT' then customer information must be added first! Please Check Customer Details First !");
	    			}
    			}
    			catch(Exception e)
    			{
    				e.printStackTrace();
    				addActionError("If Payment is 'CREDIT' then customer information must be added first!");
    			}
    					
    		}
    	}
    	
    	if(!hasActionErrors())
    	{
    		 if(!this.isProductReturn())
	         {
		    		try
		    		{
		    		String dbStockQuantity = GetProductStockByName.getProductStockByName(productDetails.getProductId(),productDetails.getProductCode(),this.getSessionMap());
		    		
		    		if(!dbStockQuantity.equals("NA"))
		    		{
		    			float dbStockQuantityFloat = Float.parseFloat(dbStockQuantity);
		    			
		    			if(dbStockQuantityFloat == 0 || dbStockQuantityFloat < 0)
		    			{
		    				addActionError("Quantity is less ("+dbStockQuantity+") in stock of "+productDetails.getProductNameEn()+"! Cannot Sale!");
		    			}else
		    			{
		    				float saleProductQuantity =productDetails.getBarCodeQuantity();
		    				
		    				float diffToUpdateQuantity = dbStockQuantityFloat - saleProductQuantity;
		    				
		    				if(diffToUpdateQuantity < 0)
		    				{
		    					addActionError("Quantity is less ("+dbStockQuantity+") in stock of "+productDetails.getProductNameEn()+"! Cannot Sale!");
		    				}
		    			}
		    			
		    		}
		    		else
		    		{
		    			addActionError("Error while getting DB stock quantity of product 3!");
		    		}
		    		
		    		}catch(Exception e)
		    		{
		    			
		    			addActionError("Error while getting DB stock quantity of product 4!");
		    		}
	         }
    		
    	}
    	
    	
    	
    	if(billByProductName)
    	{
		    	if(!hasActionErrors())
		    	{
		    		float dealerPrice = GetProductDealerPrice.getDealarPrice(productDetails.getProductId(), productDetails.getProductNameEn(), productDetails.getProductCode(), this.getSessionMap());
		    		
		    		if(dealerPrice <= 0)
		    		{
		    			addActionError("Please add dealer price to this product!");
		    			
		    		}
		    		else if(this.getSalesRate() < dealerPrice)
		    		{
		    			addActionError("Price of the product cannot be less than dealer price! Please check the product price!");
		    		}
		    		
		    		
		    		
		    	}
    	

    	}

    
    	this.setAddLabourCharges((String) shopSettingsMap.get("add_making_charge_column"));
    	
    	if(this.getAddLabourCharges().equals("TRUE")){
    		if(this.getMakingLabourAmount() == null || this.getMakingLabourAmount().equals(""))
    		{
    			addActionError("Please provide making / labor charges!");
    		}
    	}
		}
		else
		{
			

			float floatTotalAmount = 0.0F;
	    	float floatTotalDiscount = 0.0F;
	    	float floatTotalAmtAfterDiscount = 0.0F;
	    	
	    	if(this.getProductInfoList() == null)
	    	{
	    		this.setProductInfoList((List<BillProductInfoDAO>) this.getSessionMap().get("productList"));
	    	}
	    	

	    	if(this.getProductInfoList() !=null)
	    	{
		    	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
		    	{
		    		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
		    		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
		    		
		    		
		    	}
		    	floatTotalDiscount = floatTotalAmount - floatTotalAmtAfterDiscount;
		    	
		    	this.setTotalAmount(floatTotalAmount);
		    	this.setTotalDiscount(floatTotalDiscount);
		    	this.setTotalAmouAfterDisount(floatTotalAmtAfterDiscount);
		    	this.setCashAmount(floatTotalAmtAfterDiscount);
		    	this.setBankRtgsUpiAmount(0.0F);
		    	this.setReturnAmount(0.0F);
		    	this.setAmountPaid(floatTotalAmtAfterDiscount);
	    	}
	    	
			addActionError("Product details not found for this code! Please check!");
		}
	}
	else
	{
	
		    String actualProductName = ""; 
			String productId = "";
			String productCode = "";
			try
			{
				productId = this.getProductName().split("-")[0];
				actualProductName = this.getProductName().split("-")[1];
				productCode = resolveProductShortCodeForBarcodeComposite(productId, this.getProductName().split("-")[2]);
			}
			catch (Exception e) {
				actualProductName = this.getProductName();
				addActionError("Please provide correct product name (with -)! ");
			}
			
			if(!hasActionErrors())
			{
				if(this.getSessionMap().get("batchbased").equals("1"))
				{
					if(this.getSerailNoBatchId() == null || this.getSerailNoBatchId().equals(""))
					{
						addActionError("Please select serial number / batch Id!");
					}
				}
			}
	try
	{

		if(!hasActionErrors())
		{

			String isCustomerAdded = "false";
			
			String [] result = new String[2];
			
			result = new CheckAlreadyAvailable().checkAvaibility("shop_product_master", "product_name_eng", "NA", actualProductName, this.getSessionMap());
			
			isCustomerAdded = result[0];
			
			if(!isCustomerAdded.equals("true"))
			{
				addActionError("Product name given not found ! Please provide correct product name !");
			}	
			
		}
		
		HashMap<String,String> shopSettingsMap = (HashMap<String, String>) this.getSessionMap().get("shop_settings");
		
		
    	if(shopSettingsMap.get("add_quntity2").equals("TRUE"))
    	{
    		this.setAddQuantity2(true);
    	}
    	else
    	{
    		this.setAddQuantity2(false);
    	}
		String addDuplicateProductToList = shopSettingsMap.get("add_duplicate_items_to_bill");
	
		if(!hasActionErrors())
		{
			if(isAddQuantity2())
			{
				if(this.getQuantity2() == null || this.getQuantity2().equals(""))
				{
					addActionError("Please provide 2nd quanity !");
				}
				else
				{ if(!this.isProductReturn())
		         {
					
		         
					try
		    		{
		    		String dbStockQuantity = GetProductStockByName.getProductStockByName2ndQty(productId,productCode,this.getSessionMap());
		    		
		    		if(!dbStockQuantity.equals("NA"))
		    		{
		    			float dbStockQuantityFloat = Float.parseFloat(dbStockQuantity);
		    			
		    			if(dbStockQuantityFloat == 0 || dbStockQuantityFloat < 0)
		    			{
		    				addActionError("2 nd Quantity is less ("+dbStockQuantity+") in stock of "+this.getProductName()+"! Cannot Sale!");
		    			}else
		    			{
		    				float saleProductQuantity =this.getQuantity();
		    				
		    				float diffToUpdateQuantity = dbStockQuantityFloat - saleProductQuantity;
		    				
		    				if(diffToUpdateQuantity < 0)
		    				{
		    					addActionError("2 nd Quantity is less ("+dbStockQuantity+") in stock of "+actualProductName+"! Cannot Sale!");
		    				}
		    			}
		    			
		    		}
		    		else
		    		{
		    			addActionError("Error while getting DB stock quantity of product 1!");
		    		}
		    		
		    		}catch(Exception e)
		    		{
		    			addActionError("Error while getting DB stock quantity of product 2!");
		    		}
		         }
				}
			}
		}
	
		if(addDuplicateProductToList.equals("FALSE"))
		{
			if(productInfoListTest !=null)
			{
				if(!productInfoListTest.isEmpty())
				{
					for(BillProductInfoDAO infoDAO:productInfoListTest)
					{
					
						
							if(infoDAO.getProductName().equals(this.getProductName().split("-")[1]))
							{
								addActionError("Product is alredy added to list!");
								productInfoList = productInfoListTest;
							}
						
						
					}
				}
				else
				{
					this.setProductInfoList(productInfoListTest);
				}
			}
		}
		
		
	
    	
    	
    	if(getCustomerName().equals("Customer_Not_Found"))
    	{
    		addActionError("Please Provide Correct Customer Name !");
    	}
    	
    	if(!hasActionErrors())
    	{
    		//System.out.println(this.getCustomerIdNameAll());
    		
    		if(this.getPaymentType().equals("CREDIT") && !this.getCustomerIdNameAll().equals("Customer_Not_Found"))
    		{
    			this.setDefaultValue(this.getPaymentType());
    			String isCustomerAdded = "false";
    			String [] custData = new String [5];
    			try
    			{
    				//System.out.println(this.getCustomerIdNameAll());
    				
	    			custData = this.getCustomerIdNameAll().split("-");
	    			
	    			String [] result = new String[2];
	    			String condition  = " or mobile_number = '"+custData[2]+"' ";
	    			
	    			
	    			result = new CheckAlreadyAvailable().checkAvaibility("shop_customer_master", "customer_name", condition, custData[1], this.getSessionMap());
	    			
	    			isCustomerAdded = result[0];
	    			
	    			if(isCustomerAdded.equals("false"))
	    			{
	    				addActionError("If Payment is 'CREDIT' then customer information must be added first! Please Check Customer Details First !");
	    			}
    			}
    			catch(Exception e)
    			{
    				e.printStackTrace();
    				
    				addActionError("If Payment is 'CREDIT' then customer information must be added first!");
    			}
    					
    		}
    	}
    	
    	
    	if(!hasActionErrors())
    	{ if(!this.isProductReturn())
        {
    		try
    		{
    		String dbStockQuantity = GetProductStockByName.getProductStockByName(productId,productCode,this.getSessionMap());
    		
    		//System.out.println("dbStockQuantity : "+dbStockQuantity);
    		if(!dbStockQuantity.equals("NA"))
    		{
    			float dbStockQuantityFloat = Float.parseFloat(dbStockQuantity);
    			
    			if(dbStockQuantityFloat == 0 || dbStockQuantityFloat < 0)
    			{
    				addActionError("Quantity is less ("+dbStockQuantity+") in stock of "+this.getProductName()+"! Cannot Sale!");
    			}else
    			{
    				float saleProductQuantity =this.getQuantity();
    				
    				float diffToUpdateQuantity = dbStockQuantityFloat - saleProductQuantity;
    				
    				if(diffToUpdateQuantity < 0)
    				{
    					addActionError("Quantity is less ("+dbStockQuantity+") in stock of "+actualProductName+"! Cannot Sale!");
    				}
    			}
    			
    		}
    		else
    		{
    			addActionError("Error while getting DB stock quantity of product! 3");
    		}
    		
    		}catch(Exception e)
    		{
    			e.printStackTrace();
    			addActionError("Error while getting DB stock quantity of product! 4");
    		}
    		
        }
    		float floatTotalAmount = 0.0F;
        	float floatTotalDiscount = 0.0F;
        	float floatTotalAmtAfterDiscount = 0.0F;
        	
        	if(this.getProductInfoList() == null)
        	{
        		this.setProductInfoList((List<BillProductInfoDAO>) this.getSessionMap().get("productList"));
        	}
        	

        	if(this.getProductInfoList() !=null)
        	{
    	    	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
    	    	{
    	    		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
    	    		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
    	    		
    	    		
    	    	}
    	    	floatTotalDiscount = floatTotalAmount - floatTotalAmtAfterDiscount;
    	    	
    	    	this.setTotalAmount(floatTotalAmount);
    	    	this.setTotalDiscount(floatTotalDiscount);
    	    	this.setTotalAmouAfterDisount(floatTotalAmtAfterDiscount);
    	    	this.setCashAmount(floatTotalAmtAfterDiscount);
    	    	this.setBankRtgsUpiAmount(0.0F);
    	    	this.setReturnAmount(0.0F);
    	    	this.setAmountPaid(floatTotalAmtAfterDiscount);
        	}
        	
    		
    		
    	}
	}catch (Exception e) {
		// TODO: handle exception
	}
	finally{
		float floatTotalAmount = 0.0F;
    	float floatTotalDiscount = 0.0F;
    	float floatTotalAmtAfterDiscount = 0.0F;
    	
    	if(this.getProductInfoList() == null)
    	{
    		this.setProductInfoList((List<BillProductInfoDAO>) this.getSessionMap().get("productList"));
    	}
    	

    	if(this.getProductInfoList() !=null)
    	{
	    	for(BillProductInfoDAO infoDAO : this.getProductInfoList())
	    	{
	    		floatTotalAmount  = floatTotalAmount+ infoDAO.getAmount();
	    		floatTotalAmtAfterDiscount = floatTotalAmtAfterDiscount + infoDAO.getAmountAfterDiscount();
	    		
	    		
	    	}
	    	floatTotalDiscount = floatTotalAmount - floatTotalAmtAfterDiscount;
	    	
	    	this.setTotalAmount(floatTotalAmount);
	    	this.setTotalDiscount(floatTotalDiscount);
	    	this.setTotalAmouAfterDisount(floatTotalAmtAfterDiscount);
	    	this.setCashAmount(floatTotalAmtAfterDiscount);
	    	this.setBankRtgsUpiAmount(0.0F);
	    	this.setReturnAmount(0.0F);
	    	this.setAmountPaid(floatTotalAmtAfterDiscount);
    	}
	}
    	
	}
	
	
	if(this.getSalesmanIdName() != null)
	{
	
	if(!this.getSalesmanIdName().equals(""))
	{
		try
		{
			if(this.getSalesmanIdName().contains("-"))
			{
				String [] salsManIdData = this.getSalesmanIdName().split("-");
				
				this.setSalesmanId(salsManIdData[0]);
						
			}
			else
			{
				this.setSalesmanId(this.getSalesmanIdName());
			}
			
			
		}
		catch(Exception e)
		{
			this.setSalesmanId(this.getSalesmanIdName());
		}
	}

	}
    	
	  
	}

	public HttpSession getSession() {
		return session;
	}


	public void setSession(HttpSession session) {
		this.session = session;
	}


	public String getBillDateTime() {
		return billDateTime;
	}


	public void setBillDateTime(String billDateTime) {
		this.billDateTime = billDateTime;
	}


	public String getOperator() {
		return operator;
	}


	public void setOperator(String operator) {
		this.operator = operator;
	}


	public String getPaymentType() {
		return paymentType;
	}


	public void setPaymentType(String paymentType) {
		this.paymentType = paymentType;
	}


	public String getCustomerName() {
		return customerName;
	}


	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}


	public String getAlias() {
		return alias;
	}


	public void setAlias(String alias) {
		this.alias = alias;
	}





	public String getSalesUnit() {
		return salesUnit;
	}

	public void setSalesUnit(String salesUnit) {
		this.salesUnit = salesUnit;
	}

	

	public String getTaxId() {
		return taxId;
	}

	public void setTaxId(String taxId) {
		this.taxId = taxId;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getBillType() {
		return billType;
	}

	public void setBillType(String billType) {
		this.billType = billType;
	}

	public String getBillNumber() {
		return billNumber;
	}

	public void setBillNumber(String billNumber) {
		this.billNumber = billNumber;
	}

	public Map<String, String> getTaxList() {
		return taxList;
	}

	public void setTaxList(Map<String, String> taxList) {
		this.taxList = taxList;
	}

	public Map<String, String> getUnitList() {
		return unitList;
	}

	public void setUnitList(Map<String, String> unitList) {
		this.unitList = unitList;
	}

	public Map<String, String> getPaymentTypeList() {
		return paymentTypeList;
	}

	public void setPaymentTypeList(Map<String, String> paymentTypeList) {
		this.paymentTypeList = paymentTypeList;
	}

	public Map<String, String> getBillTypeList() {
		return billTypeList;
	}

	public void setBillTypeList(Map<String, String> billTypeList) {
		this.billTypeList = billTypeList;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getProductMarathiName() {
		return productMarathiName;
	}

	public void setProductMarathiName(String productMarathiName) {
		this.productMarathiName = productMarathiName;
	}


	public Float getAmountAfterDiscount() {
		return amountAfterDiscount;
	}

	public void setAmountAfterDiscount(Float amountAfterDiscount) {
		this.amountAfterDiscount = amountAfterDiscount;
	}

	public List<BillProductInfoDAO> getProductInfoList() {
		return productInfoList;
	}

	public void setProductInfoList(List<BillProductInfoDAO> productInfoList) {
		this.productInfoList = productInfoList;
	}

	
	public Float getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(Float totalAmount) {
		this.totalAmount = totalAmount;
	}

	public Float getTotalDiscount() {
		return totalDiscount;
	}

	public void setTotalDiscount(Float totalDiscount) {
		this.totalDiscount = totalDiscount;
	}

	public Float getTotalAmouAfterDisount() {
		return totalAmouAfterDisount;
	}

	public void setTotalAmouAfterDisount(Float totalAmouAfterDisount) {
		this.totalAmouAfterDisount = totalAmouAfterDisount;
	}

	public String getRemoveVaules() {
		return removeVaules;
	}

	public void setRemoveVaules(String removeVaules) {
		this.removeVaules = removeVaules;
	}

	public BillInformationDAO getBillInfoDAO() {
		return billInfoDAO;
	}

	public void setBillInfoDAO(BillInformationDAO billInfoDAO) {
		this.billInfoDAO = billInfoDAO;
	}

	public SessionMap<String, Object> getSessionMap() {
		return sessionMap;
	}

	public void setSessionMap(SessionMap<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}

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

	

	public Float getSalesRate() {
		return salesRate;
	}

	public void setSalesRate(Float salesRate) {
		this.salesRate = salesRate;
	}

	public Float getQuantity() {
		return quantity;
	}

	public void setQuantity(Float quantity) {
		this.quantity = quantity;
	}

	public Float getDiscountPercentage() {
		return discountPercentage;
	}

	public void setDiscountPercentage(Float discountPercentage) {
		this.discountPercentage = discountPercentage;
	}

	public Float getDiscountRupees() {
		return discountRupees;
	}

	public void setDiscountRupees(Float discountRupees) {
		this.discountRupees = discountRupees;
	}

	public Float getAmount() {
		return amount;
	}

	public void setAmount(Float amount) {
		this.amount = amount;
	}

	public Float getTransportCharge() {
		return transportCharge;
	}

	public void setTransportCharge(Float transportCharge) {
		this.transportCharge = transportCharge;
	}

	public Float getAmountPaid() {
		return amountPaid;
	}

	public void setAmountPaid(Float amountPaid) {
		this.amountPaid = amountPaid;
	}

	public Float getReturnAmount() {
		return returnAmount;
	}

	public void setReturnAmount(Float returnAmount) {
		this.returnAmount = returnAmount;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	public String getViewBill() {
		return viewBill;
	}

	public void setViewBill(String viewBill) {
		this.viewBill = viewBill;
	}

	public boolean isSendSMS() {
		return sendSMS;
	}

	public void setSendSMS(boolean sendSMS) {
		this.sendSMS = sendSMS;
	}

	public String getAlternateMobileNumber() {
		return alternateMobileNumber;
	}

	public void setAlternateMobileNumber(String alternateMobileNumber) {
		this.alternateMobileNumber = alternateMobileNumber;
	}

	public boolean isBillSaved() {
		return billSaved;
	}

	public void setBillSaved(boolean billSaved) {
		this.billSaved = billSaved;
	}

	public Map<String, String> getRateTypeList() {
		return rateTypeList;
	}

	public void setRateTypeList(Map<String, String> rateTypeList) {
		this.rateTypeList = rateTypeList;
	}

	public String getRateType() {
		return rateType;
	}

	public void setRateType(String rateType) {
		this.rateType = rateType;
	}

	public Float getMakingLabourAmount() {
		return makingLabourAmount;
	}

	public void setMakingLabourAmount(Float makingLabourAmount) {
		this.makingLabourAmount = makingLabourAmount;
	}

	public Map<String, String> getLabourChargeTypeList() {
		return labourChargeTypeList;
	}

	public void setLabourChargeTypeList(Map<String, String> labourChargeTypeList) {
		this.labourChargeTypeList = labourChargeTypeList;
	}

	public String getLabourChargeType() {
		return labourChargeType;
	}

	public void setLabourChargeType(String labourChargeType) {
		this.labourChargeType = labourChargeType;
	}

	public String getAddLabourCharges() {
		return addLabourCharges;
	}

	public void setAddLabourCharges(String addLabourCharges) {
		this.addLabourCharges = addLabourCharges;
	}

	public Float getQuantity2() {
		return quantity2;
	}

	public void setQuantity2(Float quantity2) {
		this.quantity2 = quantity2;
	}

	public boolean isAddQuantity2() {
		return addQuantity2;
	}

	public void setAddQuantity2(boolean addQuantity2) {
		this.addQuantity2 = addQuantity2;
	}

	public Float getCashAmount() {
		return cashAmount;
	}

	public void setCashAmount(Float cashAmount) {
		this.cashAmount = cashAmount;
	}

	public Float getBankRtgsUpiAmount() {
		return bankRtgsUpiAmount;
	}

	public void setBankRtgsUpiAmount(Float bankRtgsUpiAmount) {
		this.bankRtgsUpiAmount = bankRtgsUpiAmount;
	}

	public Map<String, String> getDiscountTypeList() {
		return discountTypeList;
	}

	public void setDiscountTypeList(Map<String, String> discountTypeList) {
		this.discountTypeList = discountTypeList;
	}

	public String getDiscountType() {
		return discountType;
	}

	public void setDiscountType(String discountType) {
		this.discountType = discountType;
	}

	
	

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 void setServletResponse(HttpServletResponse httpServletResponse) {
	this.response = httpServletResponse;
}

public void setServletRequest(HttpServletRequest httpServletRequest) {
	this.request = httpServletRequest;
}

public String getProductCode() {
	return productCode;
}

public void setProductCode(String productCode) {
	this.productCode = productCode;
}

public boolean isProductReturn() {
	return productReturn;
}

public void setProductReturn(boolean productReturn) {
	this.productReturn = productReturn;
}

public ArrayList<String> getSerailBatchIdList() {
	return serailBatchIdList;
}

public void setSerailBatchIdList(ArrayList<String> serailBatchIdList) {
	this.serailBatchIdList = serailBatchIdList;
}

public String getSerailNoBatchId() {
	return serailNoBatchId;
}

public void setSerailNoBatchId(String serailNoBatchId) {
	this.serailNoBatchId = serailNoBatchId;
}
	
	

	public ArrayList<String> getCustomerTypeList() {
		return customerTypeList;
	}

	public void setCustomerTypeList(ArrayList<String> customerTypeList) {
		this.customerTypeList = customerTypeList;
	}

	public String getCustomerType() {
		return customerType;
	}

	public void setCustomerType(String customerType) {
		this.customerType = customerType;
	}

	public String getCustomerIdNameAll() {
		return customerIdNameAll;
	}

	public void setCustomerIdNameAll(String customerIdNameAll) {
		this.customerIdNameAll = customerIdNameAll;
	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public String getCustomerMobileNumber() {
		return customerMobileNumber;
	}

	public void setCustomerMobileNumber(String customerMobileNumber) {
		this.customerMobileNumber = customerMobileNumber;
	}

	public String getSalesmanId() {
		return salesmanId;
	}

	public void setSalesmanId(String salesmanId) {
		this.salesmanId = salesmanId;
	}

	public String getSalesmanIdName() {
		return salesmanIdName;
	}

	public void setSalesmanIdName(String salesmanIdName) {
		this.salesmanIdName = salesmanIdName;
	}

	/**
	 * productName from the form may be product_id-english_name-product_alias. The third segment is
	 * the alias, not the short code. Resolve product_short_code from the session map by product_id.
	 */
	@SuppressWarnings("unchecked")
	private String resolveProductShortCodeForBarcodeComposite(String productId, String thirdSegment) {
		if (productId == null || thirdSegment == null) {
			return thirdSegment;
		}
		try {
			Map<String, ProductBarcodeDetailsDAO> map = (Map<String, ProductBarcodeDetailsDAO>) this.getSessionMap()
					.get("barcodeProductDetails");
			if (map == null) {
				return thirdSegment;
			}
			for (ProductBarcodeDetailsDAO d : map.values()) {
				if (d != null && d.getProductId() != null && d.getProductId().trim().equals(productId.trim())) {
					return d.getProductCode();
				}
			}
		} catch (Exception ignore) {
		}
		return thirdSegment;
	}

}

