package com.reallinkbilling.add;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.reallinkbilling.update.UpdateProductStockDetails;
import com.reallinkbilling.utils.GetAccountListForDrCr;
import com.reallinkbilling.utils.MaintainCloseingBalUtil;
import com.reallinkbilling.DAO.ProductBarcodeDetailsDAO;
import com.reallinkbilling.resource.CheckAlreadyAvailable;
import com.reallinkbilling.ajax.GetNewProductCodeForNewProduct;
import com.opensymphony.xwork2.ActionSupport;
import com.reallinkbilling.DAO.PurchaseInvoiceInformationDAO;
import com.reallinkbilling.DAO.PurchaseProductInfoDAO;
import com.reallinkbilling.db.GetDBConnection;
import com.reallinkbilling.resource.GetListResource;

public class SavePurchaseInvoice  extends ActionSupport implements SessionAware,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3005109908698701102L;
	private HttpSession session;
	private SessionMap<String,Object> sessionMap;
	private String purchaseDateTime;
	private PurchaseInvoiceInformationDAO purchaseInvoiceInformationDAO = null;	
	private List<PurchaseProductInfoDAO> purchaseProductInfoList = null;
	
	private Map<String,String> taxList = new LinkedHashMap<String,String>();
	private Map<String,String> unitList = new LinkedHashMap<String,String>();
	
	private String totalPurchaseAmount;
	private Float amountPaid;
	private String frightCharges;
	private String otherExpense;
	private File invoiceImage;
	private String comments;
	private DecimalFormat df;
	private String purchaseBy;
	private String totalNettAmount;
	private String totalCGST;
	private String totalSGST;
	private String totalIGST;
	
	
	
	private String productName;
	private String amount;
	private String quantity;
	private String purchaseUnit;
	private String purchaseRate;
	private String taxId;

	private String purchaseId;
	private String supplierName;
	private String invoiceNumber;

	private String invoiceImageContentType;
	private boolean addToStock;
	
	private Map<String,String> customerSearchOptionList = new HashMap<String,String>();
	private String customerSearchOption;
	private String defaultValue;
	private String paymentType;
	private Map<String,String> paymentTypeList = new  LinkedHashMap<String,String>();
	private String paymentDefaultValue;
	
	private Map<String,String> rateTypeList = new  LinkedHashMap<String,String>();
	private String rateTyprDefaultValue;
	
	private Float tcsPercentage;
	private Float tcsAmount;
	private Float directDiscountAmount;
	
	private List<String> paymentTypeList2 = new ArrayList<String>();
	private String modeOfPayment;
	private String accountId;
	private Map<String,String> accountList = new LinkedHashMap<String,String>();
   
	
	@SuppressWarnings("unchecked")
	public String execute() {
			
			
			String result = "login";
			session=ServletActionContext.getRequest().getSession(false); 
			
		        if(session==null || session.getAttribute("login")==null){ 
		        	addActionMessage("Please Login First !!!");
		        	result = "login";
		        }  
		        else{
		        	
		        	String shopId = (String) this.getSessionMap().get("shopId");
		    		String shopCode = (String) this.getSessionMap().get("shopCode");
		    		
		        	paymentTypeList.put("CASH","CASH");
		        	paymentTypeList.put("CREDIT","CREDIT");
		        		
		        	
		        	this.setPaymentDefaultValue(this.getPaymentDefaultValue());
		        	

		        	
		        	this.getRateTypeList().put("INCLUDINGGST", "Including GST");
		        	this.getRateTypeList().put("EXCLUDINGGST", "Excluding GST");
		        	
		        	this.setRateTyprDefaultValue(this.getPurchaseInvoiceInformationDAO().getRateType());
					customerSearchOptionList.put("BYNAME", "BY NAME");
					customerSearchOptionList.put("BYMOBILE", "BY MOBILE");
					customerSearchOptionList.put("BYADDRESS","BY ADDRESS");
					setDefaultValue("BYNAME");
					setCustomerSearchOption("BYNAME");
					
		        	 df = new DecimalFormat("0.00");
		        	
		        	 purchaseInvoiceInformationDAO = (PurchaseInvoiceInformationDAO) this.getSessionMap().get("purchaseInformation");
		        	purchaseProductInfoList = (List<PurchaseProductInfoDAO>) this.getSessionMap().get("purchaseProductList");
		        	Connection connection = null;
					PreparedStatement preparedStatement= null;
					ResultSet resultSet = null;
					
					String sql = "";
					String db = (String) this.getSessionMap().get("db");
					
        	try
			{
		        	if(this.getPurchaseInvoiceInformationDAO() != null && this.getPurchaseProductInfoList() != null)
		        	{
		        	
		        		connection = GetDBConnection.getDBConnection(db);
							connection.setAutoCommit(false);
							
							 java.util.Date date = new java.util.Date();
			        	      long t = date.getTime();	        	     
			        	      java.sql.Time time = new java.sql.Time(t);
			        	      
			        	      int newPurchaseId = 0;
			        	      if(this.getPurchaseInvoiceInformationDAO().getPurchaseId() == null || 
			        	    		  this.getPurchaseInvoiceInformationDAO().getPurchaseId().equals("NA") 
			        	    		  || this.getPurchaseInvoiceInformationDAO().getPurchaseId().equals(""))
			        	      {
			        	    		sql = "SELECT "
			    							+ "purchase_number "
			    							+ "FROM "
			    							+ "shop_purchase_info_master "
			    							+ "WHERE "
			    							+ "shop_id = ? "
			    							+ "AND "
			    							+ "shop_code = ? "
			    							+ "ORDER BY "
			    							+ "purchase_number "
			    							+ "DESC LIMIT 1;";
			    					
			    				
			    				preparedStatement = connection.prepareStatement(sql);
			    				preparedStatement.setString(1, shopId);
			    				preparedStatement.setString(2, shopCode);
			    				
			    				resultSet = preparedStatement.executeQuery();
			    			
			    				
			    				if(resultSet.next())
			    				{
			    					if(!(resultSet.getString(1) == null))
			    					{
			    						newPurchaseId = Integer.parseInt(resultSet.getString(1));
			    						
			    						
			    						 this.getPurchaseInvoiceInformationDAO().setPurchaseId(""+(newPurchaseId+1));
			    					}
			    					else
			    					{
			    						newPurchaseId =1;
			    						this.getPurchaseInvoiceInformationDAO().setPurchaseId(""+(newPurchaseId));
			    					
			    						
			    					}
			    				}
			    				else
			    				{	newPurchaseId =1;
			    					this.getPurchaseInvoiceInformationDAO().setPurchaseId(""+(newPurchaseId));
			    				}
			        	      }
			            		
			        	    if(resultSet != null)
			          		{
			          			resultSet.close();
			          			resultSet = null;
			          		}
			        	    
			          		if(preparedStatement!= null)
			          		{
			          			preparedStatement.close();
			          			preparedStatement = null;
			          		}
			          		FileInputStream fis = null;
			         		if(this.getInvoiceImage() != null)
			          		{
			          		 fis =  new FileInputStream(this.getInvoiceImage());
			          		}
			          		
			          		String fullUserName = (String) this.getSessionMap().get("userFullName");
				        	
				        	String splitUserName [] = new String[5];
				        	
				        	String entryBy = "";
				        	try
				        	{
				        		splitUserName = fullUserName.split(" ");
				        		entryBy = splitUserName[0];
				        		
				        	}catch(Exception e)
				        	{
				        		entryBy = fullUserName;
				        	}
				        	
	          		if(!this.getPurchaseInvoiceInformationDAO().isViewPurchaseInvoice() && !this.getPurchaseInvoiceInformationDAO().isPurchaseSaved())					
	          		{
	          			
			          		
							if(getInvoiceImage() != null)
							{
								
									 sql = "INSERT INTO "
									 		+ "shop_purchase_info_master "
									 		+ "("
									 		+ "purchase_number,"
									 		+ "shop_id,"
									 		+ "shop_code,"
											+ "purchase_invoice_number,"
											+ "purchase_date,"								
											+ "purchase_time,"									
											+ "supplier_id,"
											+ "transportation_charges,"
											+ "other_expenses,"
											+ "comments,"
											+ "total_purchase_amount,"
											+ "purchase_amount_paid,"
											+ "purchase_igst_amount,"
											+ "purchase_scgst_amount,"
											+ "purchase_cgst_amount,"
											+ "purchase_net_amount,"									
											+ "invoice_pic,"
											+ "payment_type,"
											+ "entry_by,"
											+ "purchased_by,"
											+ "supplier_name,"
											+ "rate_type,"
											+ "tcs_percentage,"
											+ "tcs_amount,"
											+ "direct_discount_amount) "
											+ "VALUES "
											+ "(?,?,?,?,STR_TO_DATE(?,'%d-%m-%Y'),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
									
									preparedStatement = connection.prepareStatement(sql);
									
									preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
									preparedStatement.setString(2, shopId);
									preparedStatement.setString(3, shopCode);
									preparedStatement.setString(4, this.getPurchaseInvoiceInformationDAO().getInvoiceNumber());									
									preparedStatement.setString(5, this.getPurchaseInvoiceInformationDAO().getPurchaseDate());
									preparedStatement.setTime(6, time);
									preparedStatement.setString(7, this.getPurchaseInvoiceInformationDAO().getSupplierId());
									preparedStatement.setFloat(8, this.getPurchaseInvoiceInformationDAO().getFrightCharges());
									preparedStatement.setFloat(9, this.getPurchaseInvoiceInformationDAO().getOtherExpense());
									preparedStatement.setString(10, this.getComments());
									preparedStatement.setFloat(11, this.getPurchaseInvoiceInformationDAO().getPurchaseTotalAmount());
									preparedStatement.setFloat(12, this.getAmountPaid());
									preparedStatement.setFloat(13, this.getPurchaseInvoiceInformationDAO().getTotalCGST());
									preparedStatement.setFloat(14, this.getPurchaseInvoiceInformationDAO().getTotalSGST());
									preparedStatement.setFloat(15, this.getPurchaseInvoiceInformationDAO().getTotalIGST());
									preparedStatement.setFloat(16, this.getPurchaseInvoiceInformationDAO().getTotalNettAmount());	
									
									preparedStatement.setBinaryStream(17, fis,(int)getInvoiceImage().length());
									
									preparedStatement.setString(18, this.getPurchaseInvoiceInformationDAO().getPaymentType());
									preparedStatement.setString(19, entryBy);
									preparedStatement.setString(20, this.getPurchaseInvoiceInformationDAO().getPurchaseBy());
									preparedStatement.setString(21, this.getPurchaseInvoiceInformationDAO().getSupplierName());
									preparedStatement.setString(22, this.getPurchaseInvoiceInformationDAO().getRateType());
									preparedStatement.setFloat(23, this.getPurchaseInvoiceInformationDAO().getTcsPercentage());
									preparedStatement.setFloat(24, this.getPurchaseInvoiceInformationDAO().getTcsAmount());
									preparedStatement.setFloat(25, this.getPurchaseInvoiceInformationDAO().getDirectDiscountAmount());
									
							}
							else
							{
								 sql = "INSERT INTO "
									 		+ "shop_purchase_info_master "
									 		+ "("
									 		+ "purchase_number,"
									 		+ "shop_id,"
									 		+ "shop_code,"
											+ "purchase_invoice_number,"
											+ "purchase_date,"								
											+ "purchase_time,"									
											+ "supplier_id,"
											+ "transportation_charges,"
											+ "other_expenses,"
											+ "comments,"
											+ "total_purchase_amount,"
											+ "purchase_amount_paid,"
											+ "purchase_igst_amount,"
											+ "purchase_scgst_amount,"
											+ "purchase_cgst_amount,"
											+ "purchase_net_amount,"
											+ "payment_type,"
											+ "entry_by,"
											+ "purchased_by,"
											+ "supplier_name,"
											+ "rate_type,"
											+ "tcs_percentage,"
											+ "tcs_amount,"
											+ "direct_discount_amount) "
											+ "VALUES "
											+ "(?,?,?,?,STR_TO_DATE(?,'%d-%m-%Y'),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
									
									preparedStatement = connection.prepareStatement(sql);
									
									preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
									preparedStatement.setString(2, shopId);
									preparedStatement.setString(3, shopCode);
									preparedStatement.setString(4, this.getPurchaseInvoiceInformationDAO().getInvoiceNumber());									
									preparedStatement.setString(5, this.getPurchaseInvoiceInformationDAO().getPurchaseDate());
									preparedStatement.setTime(6, time);
									preparedStatement.setString(7, this.getPurchaseInvoiceInformationDAO().getSupplierId());
									preparedStatement.setString(8, this.getFrightCharges());
									preparedStatement.setString(9, this.getOtherExpense());
									preparedStatement.setString(10, this.getComments());
									preparedStatement.setFloat(11, this.getPurchaseInvoiceInformationDAO().getPurchaseTotalAmount());
									preparedStatement.setFloat(12, this.getAmountPaid());
									preparedStatement.setFloat(13, this.getPurchaseInvoiceInformationDAO().getTotalCGST());
									preparedStatement.setFloat(14, this.getPurchaseInvoiceInformationDAO().getTotalSGST());
									preparedStatement.setFloat(15, this.getPurchaseInvoiceInformationDAO().getTotalIGST());
									preparedStatement.setFloat(16, this.getPurchaseInvoiceInformationDAO().getTotalNettAmount());							
									preparedStatement.setString(17, this.getPurchaseInvoiceInformationDAO().getPaymentType());
									preparedStatement.setString(18, entryBy);
									preparedStatement.setString(19, this.getPurchaseInvoiceInformationDAO().getPurchaseBy());
									preparedStatement.setString(20, this.getPurchaseInvoiceInformationDAO().getSupplierName());
									preparedStatement.setString(21, this.getPurchaseInvoiceInformationDAO().getRateType());
									preparedStatement.setFloat(22, this.getPurchaseInvoiceInformationDAO().getTcsPercentage());
									preparedStatement.setFloat(23, this.getPurchaseInvoiceInformationDAO().getTcsAmount());
									preparedStatement.setFloat(24, this.getPurchaseInvoiceInformationDAO().getDirectDiscountAmount());
							}
		        	}
	          		else
		        	{
	          			
		        		 sql = "UPDATE "
		        		 		+ "shop_purchase_info_master "
		        		 		+ "SET "
									+ "purchase_date=STR_TO_DATE(?,'%d-%m-%Y'),"								
									+ "purchase_time=?,"	
									+ "transportation_charges=?,"
									+ "comments=?,"
									+ "other_expenses=?,"
									+ "total_purchase_amount=?,"
									+ "purchase_amount_paid=?,"
									+ "purchase_igst_amount=?,"
									+ "purchase_scgst_amount=?,"
									+ "purchase_cgst_amount=?,"
									+ "purchase_net_amount=?,"
									+ "entry_by=?,"
									+ "payment_type=?,"
									+ "purchased_by=?,"
									+ "tcs_percentage=?,"
									+ "tcs_amount=?,"
									+ "direct_discount_amount = ? "
									+ "WHERE "
									+ "purchase_number = ? "
									+ "AND "
									+ "shop_id = ? "
									+ "AND "
									+ "shop_code = ?";
						 
						 
		        		 	preparedStatement = connection.prepareStatement(sql);
		        		 	preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseDate());
		        		 	preparedStatement.setTime(2, time);	
							preparedStatement.setString(3, this.getFrightCharges());
							preparedStatement.setString(4, this.getComments());
							preparedStatement.setString(5, this.getOtherExpense());								
							preparedStatement.setFloat(6, this.getPurchaseInvoiceInformationDAO().getPurchaseTotalAmount());
							preparedStatement.setFloat(7, this.getAmountPaid());
							preparedStatement.setFloat(8, this.getPurchaseInvoiceInformationDAO().getTotalCGST());
							preparedStatement.setFloat(9, this.getPurchaseInvoiceInformationDAO().getTotalSGST());
							preparedStatement.setFloat(10, this.getPurchaseInvoiceInformationDAO().getTotalIGST());
							preparedStatement.setFloat(11, this.getPurchaseInvoiceInformationDAO().getTotalNettAmount());							
							preparedStatement.setString(12, entryBy);							
							preparedStatement.setString(13, this.getPurchaseInvoiceInformationDAO().getPaymentType());	
							preparedStatement.setString(14, this.getPurchaseInvoiceInformationDAO().getPurchaseBy());
							preparedStatement.setFloat(15, this.getPurchaseInvoiceInformationDAO().getTcsPercentage());
							preparedStatement.setFloat(16, this.getPurchaseInvoiceInformationDAO().getTcsAmount());
							preparedStatement.setFloat(17, this.getPurchaseInvoiceInformationDAO().getDirectDiscountAmount());
							preparedStatement.setString(18, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
							preparedStatement.setString(19, shopId);
							preparedStatement.setString(20, shopCode);
								
				//			System.out.println(this.getPurchaseInvoiceInformationDAO().getPurchaseBy());
						
		        	}
	          		int rowsUpdated = preparedStatement.executeUpdate();
	          		if(fis != null)
					{
						fis.close();
						fis = null;
					}	
					
					if(rowsUpdated>0)
					{
						
						if(preparedStatement != null)
						{
							preparedStatement.close();
							preparedStatement = null;
						}
						
						int rowsToDelete = 0;
						int rowsDeleted = 0;
						
						String productId = null ;
						String productName = null;
						float quantity = 0 ;
						boolean stockMinus = true;
						
						
						sql = "SELECT "
								+ "count(*) "
								+ "FROM "
								+ "shop_purchase_product_info_master "
								+ "WHERE "
								+ "purchase_number = ? "
								+ "AND "
								+ "purchase_invoice_number=? "
								+ "AND "
								+ "shop_id = ? "
								+ "AND "
								+ "shop_code = ? ";
						
						preparedStatement = connection.prepareStatement(sql);
						preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
						preparedStatement.setString(2, this.getPurchaseInvoiceInformationDAO().getInvoiceNumber());
						preparedStatement.setString(3, shopId);
						preparedStatement.setString(4, shopCode);
						
						
						resultSet = preparedStatement.executeQuery();
						
						if(resultSet.next())
						{
							rowsToDelete = resultSet.getInt(1);
							
							
							sql = "SELECT "
									+ "product_id,"
									+ "product_name,"
									+ "puroduct_quantity "
									+ "FROM "
									+ "shop_purchase_product_info_master "
									+ "WHERE "
									+ "purchase_number = ? "
									+ "AND "
									+ "purchase_invoice_number=? "
									+ "AND "
									+ "shop_id = ? "
									+ "AND "
									+ "shop_code = ? ";
							
							preparedStatement = connection.prepareStatement(sql);
							preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
							preparedStatement.setString(2, this.getPurchaseInvoiceInformationDAO().getInvoiceNumber());
							preparedStatement.setString(3, shopId);
							preparedStatement.setString(4, shopCode);
							
							
							resultSet = preparedStatement.executeQuery();
							
							
							
							while(resultSet.next())
							{
								productId = resultSet.getString(1);
								productName = resultSet.getString(2);
								quantity = resultSet.getFloat(3);
								
								stockMinus = UpdateProductStockDetails.minusStockToCurrentStockForPurchase(connection, this.getSessionMap(), productId, productName, quantity);
								
								
							}
							
							
						}
						
						
						if(preparedStatement != null)
						{
							preparedStatement.close();
							preparedStatement = null;
						}
						if(rowsToDelete>0)
						{
							
							sql = "DELETE "
									+ "FROM "
									+ "shop_purchase_product_info_master "
									+ "WHERE "
									+ "purchase_number = ? "
									+ "AND "
									+ "purchase_invoice_number=? "
									+ "AND "
									+ "shop_id = ? "
									+ "AND "
									+ "shop_code = ? ";
							
							preparedStatement = connection.prepareStatement(sql);
							preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId());
							preparedStatement.setString(2, this.getPurchaseInvoiceInformationDAO().getInvoiceNumber());
							preparedStatement.setString(3, shopId);
							preparedStatement.setString(4, shopCode);
							
							
							rowsDeleted = preparedStatement.executeUpdate();
							
							if(rowsDeleted > 0)
							{
											
							}
						}
						
						
						if(rowsToDelete == rowsDeleted && stockMinus)
						{

							if(this.getPurchaseProductInfoList() != null)
								{
								// (Reverted) Do not auto-create products here; keep original functionality intact
										if(preparedStatement != null)
										{
											preparedStatement.close();
											preparedStatement = null;
										}
										
										sql = "INSERT into "
												+ "shop_purchase_product_info_master "
												+ "("
												+ "purchase_number,"
												+ "shop_id,"
												+ "shop_code,"
												+ "purchase_invoice_number,"
												+ "product_id,"
												+ "product_name,"
												+ "serial_no_batch_id,"
												+ "purchase_unit,"
												+ "tax_id,"
												+ "purchase_rate,"
												+ "puroduct_quantity,"
												+ "product_total_amount,"
												+ "product_net_amount,"
												+ "product_igst_amount,"
												+ "product_cgst_amount,"
												+ "product_sgst_amount,"
												+ "product_gross_amount,"
												+ "discount,"
												+ "discount_type "
												+ ") "
												+ "values"
												+ "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
										preparedStatement = connection.prepareStatement(sql);
										boolean stockAdded = false;
										
										for(PurchaseProductInfoDAO dao: this.getPurchaseProductInfoList())
										{
											
											
											preparedStatement.setString(1, this.getPurchaseInvoiceInformationDAO().getPurchaseId() );
											preparedStatement.setString(2, shopId);
											preparedStatement.setString(3, shopCode);
											preparedStatement.setString(4, invoiceNumber);
											preparedStatement.setString(5, dao.getProductId());
											preparedStatement.setString(6, dao.getProductName());
											preparedStatement.setString(7, dao.getSerialBatchNo());
											preparedStatement.setString(8, dao.getPurchaseUnit());
											preparedStatement.setString(9, dao.getTaxId());
											preparedStatement.setFloat(10, dao.getPurchaseRate());
											preparedStatement.setFloat(11, dao.getQuantity());
											preparedStatement.setFloat(12, dao.getAmount());
											preparedStatement.setFloat(13, dao.getNettAmount());
											preparedStatement.setFloat(14, dao.getIgst());
											preparedStatement.setFloat(15, dao.getCgst());
											preparedStatement.setFloat(16, dao.getSgst());
											preparedStatement.setFloat(17, dao.getGrossAmount());
											
											preparedStatement.setFloat(18, dao.getDiscount());
											preparedStatement.setString(19, dao.getDiscountType());
											preparedStatement.addBatch();
											
											stockAdded = UpdateProductStockDetails.addStockToCurrentStockForPurchase( connection, this.getSessionMap(),dao.getProductId(), dao.getProductName(), dao.getQuantity());
										}
										
										
										int [] numUpdates=preparedStatement.executeBatch();
										
										
										sql = "SELECT "
					  							+ "credit_debit_id "
					  							+ "FROM "
					  							+ "shop_purchase_info_master "
					  							+ "WHERE "
							        			+ "purchase_number = ? "
							        			+ "AND "
							        			+ "supplier_id = ? "
							        			+ "AND "
							        			+ "shop_id = ? "
												+ "AND "
												+ "shop_code = ?";
										
										preparedStatement = connection.prepareStatement(sql);
										
										preparedStatement.setString(1,purchaseInvoiceInformationDAO.getPurchaseId());
							        	preparedStatement.setString(2,purchaseInvoiceInformationDAO.getSupplierId());   
							        	preparedStatement.setString(3, shopId);
										preparedStatement.setString(4, shopCode);
										
										resultSet = preparedStatement.executeQuery();
										
										
										if(resultSet.next()){
											String crditDebitId = resultSet.getString(1);
											
											
											
											sql = "SELECT "
													+ "entry_id,"
													+ "account_id,"
													+ "account_number,"
													+ "entry_date,"
													+ "entry_time,"
													+ "entry_type,"
													+ "amount,"
													+ "payment_type,"
													+ "entry_by,"
													+ "entry_details "
													+ "FROM "
													+ "bank_account_credit_debit_master "
													+ "WHERE "
													+ "entry_id = ? "
													+ "AND "
													+ "shop_id = ? "
													+ "AND "
													+ "shop_code = ? ";
											
											preparedStatement = connection.prepareStatement(sql);
											preparedStatement.setString(1, crditDebitId);
											preparedStatement.setString(2, shopId);
											preparedStatement.setString(3, shopCode);

											
											resultSet = preparedStatement.executeQuery();
											
											int m = 0;
											if(resultSet.next())
											{
												
												PreparedStatement  insertIntoDeletedPSMT = null;
												
												String inertDeletedSQL = "INSERT "
														+ "INTO "
														+ "bank_account_credit_debit_updated_entry_master "
														+ "("
														+ "entry_id,"
														+ "shop_id,"
														+ "shop_code,"
														+ "account_id,"
														+ "account_number,"
														+ "entry_date,"
														+ "entry_time,"
														+ "entry_type,"
														+ "amount,"
														+ "payment_type,"
														+ "entry_by,"
														+ "entry_details) "
														+ "VALUES "
														+ "(?,?,?,?,?,?,?,?,?,?,?,?)";
												
												insertIntoDeletedPSMT = connection.prepareStatement(inertDeletedSQL);
												
												insertIntoDeletedPSMT.setString(1, crditDebitId);
												insertIntoDeletedPSMT.setString(2, shopId);
												insertIntoDeletedPSMT.setString(3, shopCode);
												insertIntoDeletedPSMT.setString(4, resultSet.getString(2));
												insertIntoDeletedPSMT.setString(5, resultSet.getString(3));
												insertIntoDeletedPSMT.setString(6, resultSet.getString(4));
												insertIntoDeletedPSMT.setTime(7, resultSet.getTime(5));
												insertIntoDeletedPSMT.setString(8, resultSet.getString(6));
												insertIntoDeletedPSMT.setFloat(9, this.getAmountPaid());
												insertIntoDeletedPSMT.setString(10, resultSet.getString(8));
												insertIntoDeletedPSMT.setString(11, entryBy);
												insertIntoDeletedPSMT.setString(12, resultSet.getString(10));
												
												
												  m = insertIntoDeletedPSMT.executeUpdate();
												  
												  String paymentType = resultSet.getString(6);
												   
												  
												  SimpleDateFormat inputDateFormat = new SimpleDateFormat("yyyy-MM-dd");
													Date parsedDate = null;

													try {
													    parsedDate = inputDateFormat.parse(resultSet.getString(4)); 
													} catch (ParseException e) {
													    e.printStackTrace();  
													}

													if (parsedDate != null) {
													     SimpleDateFormat outputDateFormat = new SimpleDateFormat("dd-MM-yyyy");
													    String formattedDate = outputDateFormat.format(parsedDate); 
										
													    
												 
												    
												    
												  boolean isCloseingBalMaintained = false;
												  
												  if (paymentType.equals("CREDIT")) {
												   isCloseingBalMaintained = MaintainCloseingBalUtil.maintainCloseingBal(resultSet.getString(2),"DEBIT", formattedDate, resultSet.getFloat(7), entryBy, connection, this.getSessionMap());
												  }else {
													   isCloseingBalMaintained = MaintainCloseingBalUtil.maintainCloseingBal(resultSet.getString(2),"CREDIT", formattedDate, resultSet.getFloat(7), entryBy, connection, this.getSessionMap());
													  
												  }
													}
												  
												if(insertIntoDeletedPSMT != null)
												{
													insertIntoDeletedPSMT.close();
													insertIntoDeletedPSMT = null;
												}
												
											}
											if(resultSet != null)
											{
												resultSet.close();
												resultSet = null;
											}
											if(preparedStatement != null)
											{
												preparedStatement.close();
												preparedStatement = null;
											}
											
											
											if(m>0)
											{
												
												
											
											sql = "DELETE "
													+ "FROM "
													+ "bank_account_credit_debit_master "
													+ "WHERE "
													+ "entry_id = ? "
													+ "AND "
													+ "shop_id = ? "
													+ "AND "
													+ "shop_code = ? ";
											
											preparedStatement = connection.prepareStatement(sql);
											preparedStatement.setString(1, crditDebitId);
											preparedStatement.setString(2, shopId);
											preparedStatement.setString(3, shopCode);
											
											int k = preparedStatement.executeUpdate();
											
											
											if(k > 0 )
											{
												sql = "UPDATE "
				        	        					+ "shop_purchase_info_master "
				        	        					+ "SET "
				        	        					+ "credit_debit_id = ? "
				        	        					+ "WHERE "
				    									+ "purchase_number = ? "
				    									+ "AND "
				    									+ "shop_id = ? "
				    									+ "AND "
				    									+ "shop_code = ? ";
				        	        			
				        	        			
					    						preparedStatement = connection.prepareStatement(sql);
					    						
					    						preparedStatement.setString(1, null);
					    						preparedStatement.setString(2, purchaseInvoiceInformationDAO.getPurchaseId());
					    						preparedStatement.setString(3, shopId);
					    		        		preparedStatement.setString(4, shopCode);
					    		        		
					    						int rowCreditDebitIdInsetred = preparedStatement.executeUpdate();
					        				
					    						
					    						
											}
							    		}
										}
										
										if(this.getPurchaseProductInfoList().size() == numUpdates.length)
										{
											
											if(stockAdded)
											{
												
												
												if(purchaseInvoiceInformationDAO.getPaymentType().equals("CASH"))
												{
													
													
													
													
													
												
												sql = "SELECT "
														+ "entry_id "
														+ "FROM "
														+ "bank_account_credit_debit_master "
														+ "WHERE "
														+ "shop_id = ? "
														+ "AND "
														+ "shop_code = ? "
														+ "ORDER BY "
														+ "entry_id "
														+ "DESC LIMIT 1;";
												
											
											preparedStatement = connection.prepareStatement(sql);
											preparedStatement.setString(1, shopId);
											preparedStatement.setString(2, shopCode);
											
											resultSet = preparedStatement.executeQuery();
											
											
											String purchaseIdString = purchaseInvoiceInformationDAO.getPurchaseId();

											
											int purchaseIdInt = Integer.parseInt(purchaseIdString);
											
											int bankEntryId = 1;
											if(resultSet.next())
											{
												if(!(resultSet.getString(1) == null))
												{
													bankEntryId = Integer.parseInt(resultSet.getString(1));
													bankEntryId = bankEntryId + 1;
													
												}
												
											}
											else
											{	bankEntryId =1;
												
											}
											
							        		if(resultSet != null)
							        		{
							        			resultSet.close();
							        			resultSet = null;
							        		}
							        		if(preparedStatement!= null)
							        		{
							        			preparedStatement.close();
							        			preparedStatement = null;
							        		}
							        		
							        		String accountNumber = "";
							        		sql = "SELECT "
							        				+ "account_number "
							        				+ "FROM "
							        				+ "bank_account "
							        				+ "WHERE "
							        				+ "account_id  = ?"
							        				+ "AND "
													+ "shop_id = ? "
													+ "AND "
													+ "shop_code = ? ";
							        			
							        		preparedStatement = connection.prepareStatement(sql);
							        		
							        		preparedStatement.setString(1, this.getAccountId());
							        		preparedStatement.setString(2, shopId);
											preparedStatement.setString(3, shopCode);
											
							        		resultSet = preparedStatement.executeQuery();
							        		if(resultSet.next())
							        		{
							        			accountNumber = resultSet.getString(1);
							        		}
							        		
							        		if(resultSet != null)
							        		{
							        			resultSet.close();
							        			resultSet = null;
							        		}
							        		if(preparedStatement!= null)
							        		{
							        			preparedStatement.close();
							        			preparedStatement = null;
							        		}
							        		
							        		
												sql = "INSERT "
														+ "INTO "
														+ "bank_account_credit_debit_master "
														+ "("
														+ "entry_id,"
														+ "shop_id,"
								        				+ "shop_code,"
								        				+ "account_id,"
														+ "account_number,"
														+ "entry_date,"
														+ "entry_time,"
														+ "entry_type,"
														+ "amount,"
														+ "payment_type,"
														+ "entry_by,"
														+ "entry_details) "
														+ "VALUES "
														+ "(?,?,?,?,?,STR_TO_DATE(?,'%d-%m-%Y'),?,?,?,?,?,?)";
												
												preparedStatement = connection.prepareStatement(sql);
												
												preparedStatement.setInt(1, bankEntryId);
												preparedStatement.setString(2, shopId);
								        		preparedStatement.setString(3, shopCode);
								        		preparedStatement.setString(4, this.getAccountId());
												preparedStatement.setString(5, accountNumber);
												preparedStatement.setString(6, purchaseInvoiceInformationDAO.getPurchaseDate());
												preparedStatement.setTime(7, time);
												preparedStatement.setString(8, "DEBIT");
												preparedStatement.setFloat(9, this.getAmountPaid());
												preparedStatement.setString(10, this.getModeOfPayment());
												preparedStatement.setString(11, entryBy);
												preparedStatement.setString(12, "PAID BY "+this.getSupplierName()+" Against Purchase amount: "+this.getTotalPurchaseAmount());
												   
												int rowInsetred = preparedStatement.executeUpdate();
												
												boolean isCloseingBalMaintained = MaintainCloseingBalUtil.maintainCloseingBal(this.getAccountId(),"DEBIT", purchaseInvoiceInformationDAO.getPurchaseDate(), this.getAmountPaid(), entryBy, connection, this.getSessionMap());
												
												if(isCloseingBalMaintained && rowInsetred > 0)
												{
													
													sql = "UPDATE "
					        	        					+ "shop_purchase_info_master "
					        	        					+ "SET "
					        	        					+ "credit_debit_id = ? "
					        	        					+ "WHERE "
					    									+ "purchase_number = ? "
					    									+ "AND "
					    									+ "shop_id = ? "
					    									+ "AND "
					    									+ "shop_code = ? ";
					        	        			     
					        	        			
						    						preparedStatement = connection.prepareStatement(sql);
						    						
						    						preparedStatement.setInt(1, bankEntryId);
						    						preparedStatement.setString(2, purchaseInvoiceInformationDAO.getPurchaseId());
						    						preparedStatement.setString(3, shopId);
						    		        		preparedStatement.setString(4, shopCode);
						    		        		
						    						int rowCreditDebitIdInsetred = preparedStatement.executeUpdate();
						        				
						    						
						    						
						    						if(rowCreditDebitIdInsetred > 0 )
						    						{
						    							connection.commit();
						    							result = "success";
						    							addActionMessage("Purchase Account Details Added Successfully !");
						    						}
														
												}
												else
												{
													result = "error";
													addActionError("Error Purchase Account Details Not Added Please Try Again !");
												}
												}
												
												
												this.getSessionMap().remove("deletedProductInfoList");
												this.getSessionMap().remove("purchaseProductList");
									        	this.getSessionMap().remove("purchaseInformation");
									        	
												connection.commit();
												this.getPurchaseInvoiceInformationDAO().setPurchaseSaved(true);
												result="success";
												addActionMessage("Purchase invoice saved successfully!");
											}
											else 
											{
												result="error";
												connection.rollback();
												addActionError("Error while adding stock! Please try again!");
												
											}
										}
										else
										{
											connection.rollback();
											result="error";
											addActionError("45. Purchase invoice details not saved ! Please try again !");
										}
									}
									else
									{
										connection.rollback();
										result="error";
										addActionError("56. Purchase invoice details not saved ! Please try again !");
									}
									
									
								
						}
						else
						{
							connection.rollback();
							result = "error";
							addActionError("78. Purchase information not saved! Unable to update stock details properly!");
							
						}
								
								
					}else
					{
						connection.rollback();
						result = "error";								
						addActionError("Purchase details not inserted! Please try again!");
					}
						
		        	
		        }else
		        {
		        	result = "error";
		        	addActionError("Purchase details not found!Please try again!");
		        }
		        	
			   }catch (SQLException e) {
					e.printStackTrace();
					result = "error";	
					addActionError(e.getErrorCode()+" || "+e.getMessage() +" || Purchase details not Saved!");
					
				} catch (Exception e) {
					e.printStackTrace();
					result = "error";						
					addActionError(e.getMessage()+" || "+e.getCause()+" || Purchase details not Saved!");
				}finally 
				{
					if(resultSet != null)
	   				{
	   					try {resultSet.close(); resultSet = null;}catch(SQLException sqe){}   					
	   				}
					if(preparedStatement != null)
					{
						try {preparedStatement.close(); preparedStatement = null;} catch (SQLException e) {}
					}
					if(connection != null)
					{
						
						try {connection.close(); connection = null;}catch (SQLException e) {}
					}
					
				}
			}
		        
		        
		       
					taxList = GetListResource.GetTaxList(this.getSessionMap());
		    	
		    	unitList = GetListResource.GetUnitList();
		    	
		    	
		    	
		    	 
	       	 float floatTotalPurchaseAmount = 0.0F;
	       	 float floatTotalCGST = 0.0F;
	       	 float floatTotalSGST = 0.0F;
	       	 float floatTotalIGST = 0.0F;
	       	 float floatTotalNettAmount = 0.0F;
	       	 
	       	 for (PurchaseProductInfoDAO pProductInfoDAO : purchaseProductInfoList)
	       	 {
	       		 floatTotalPurchaseAmount = floatTotalPurchaseAmount + pProductInfoDAO.getAmount();
	       		 floatTotalCGST = floatTotalCGST + pProductInfoDAO.getCgst();
	       		 floatTotalSGST = floatTotalSGST + pProductInfoDAO.getSgst();
	       		 floatTotalIGST = floatTotalIGST + pProductInfoDAO.getIgst();
	       		 floatTotalNettAmount = floatTotalNettAmount + pProductInfoDAO.getNettAmount();
	       	 }
	       	 
	       	 setTotalPurchaseAmount(""+df.format(purchaseInvoiceInformationDAO.getPurchaseTotalAmount()));
	       	 setTotalNettAmount(""+df.format(floatTotalNettAmount));
	       	 setTotalCGST(""+df.format(floatTotalCGST));
	       	 setTotalSGST(""+df.format(floatTotalSGST));
	       	 setTotalIGST(""+df.format(floatTotalIGST));
	   		
	       	 setPurchaseDateTime(purchaseInvoiceInformationDAO.getPurchaseDate());
	       	 setPurchaseId(purchaseInvoiceInformationDAO.getPurchaseId());
	       	 setSupplierName(purchaseInvoiceInformationDAO.getSupplierDetails());
	       	 setInvoiceNumber(purchaseInvoiceInformationDAO.getInvoiceNumber());
	      	this.setPaymentDefaultValue(purchaseInvoiceInformationDAO.getPaymentType());
	      	
	      
	       	 setAddToStock(purchaseInvoiceInformationDAO.isAddToStock());
	       	sessionMap.put("purchaseInformation", purchaseInvoiceInformationDAO);
	       	sessionMap.put("purchaseProductList", purchaseProductInfoList);
			
return result;
}

	@SuppressWarnings("unchecked")
	@Override
	public void validate() {

		 df = new DecimalFormat("0.00");
		purchaseInvoiceInformationDAO = (PurchaseInvoiceInformationDAO) sessionMap.get("purchaseInformation");
		purchaseProductInfoList = (List<PurchaseProductInfoDAO>) sessionMap.get("purchaseProductList");
		
		paymentTypeList2.add("CASH");
    	paymentTypeList2.add("UPI");
    	paymentTypeList2.add("RTGS");
    	paymentTypeList2.add("NEFT");
    	this.setAccountList(GetAccountListForDrCr.getAccountList(this.getSessionMap()));
	   	
    	
		if(this.getPurchaseInvoiceInformationDAO().getPaymentType().equals("CASH"))
		{
			if(this.getAccountId().equals(""))
			{
				addActionError("Please Select Account !");
			}
		}
		
		
		
		
		if(getAmountPaid().equals(""))
		{
			addActionError("Please provide amount paid value !");
		}
		
		if(!hasActionErrors())
		{
			if(getAmountPaid()!=null || !getAmountPaid().equals("") )
					{
						Float amtPaid =0.0F; 
						
						
						try
						{
							amtPaid = this.getAmountPaid();
							
							if(amtPaid<0 || amtPaid > this.getPurchaseInvoiceInformationDAO().getPurchaseTotalAmount())
							{
								addActionError("Please provide correct amount paid value ! ");
								addActionError("Amount paid cannot be less than '0' and cannot be greter than Total Amount !");
							}
						}catch(NumberFormatException nfe)
						{
							addActionError("Please provide correct value for amount paid !");
						}
					}
			
			
		}
		
		if(!hasActionErrors())
		{
			if(purchaseInvoiceInformationDAO.getPaymentType().equals("CREDIT") && this.getAmountPaid() > 0){
				addActionError("Payment type is credit amount paid cannot be greater than '0'!");
			}
		}
		
		  
		 taxList = GetListResource.GetTaxList(this.getSessionMap());
	   	
		 unitList = GetListResource.GetUnitList();
		 
	  	 float floatTotalPurchaseAmount = 0.0F;
	  	 float floatTotalCGST = 0.0F;
	  	 float floatTotalSGST = 0.0F;
	  	 float floatTotalIGST = 0.0F;
	  	 float floatTotalNettAmount = 0.0F;
	  	 
	  	 for (PurchaseProductInfoDAO pProductInfoDAO : purchaseProductInfoList)
	  	 {
	  		 floatTotalPurchaseAmount = floatTotalPurchaseAmount + pProductInfoDAO.getAmount();
	  		 floatTotalCGST = floatTotalCGST + pProductInfoDAO.getCgst();
	  		 floatTotalSGST = floatTotalSGST + pProductInfoDAO.getSgst();
	  		 floatTotalIGST = floatTotalIGST + pProductInfoDAO.getIgst();
	  		 floatTotalNettAmount = floatTotalNettAmount + pProductInfoDAO.getNettAmount();
	  	 }
	  	 
	  	if(this.getPurchaseInvoiceInformationDAO().getPaymentType().equals("CASH"))
		{
			if(this.getAmountPaid() <  floatTotalPurchaseAmount)
			{
				addActionError("Payment type is cash! Paid amount cannot be less than payable amount!");
			}
				
		}
	  	
	  	this.setTotalPurchaseAmount(""+df.format(floatTotalPurchaseAmount));
	  	this.setTotalNettAmount(""+df.format(floatTotalNettAmount));
	  	this.setTotalCGST(""+df.format(floatTotalCGST));
	  	this.setTotalSGST(""+df.format(floatTotalSGST));
	  	this.setTotalIGST(""+df.format(floatTotalIGST));
	  	this.setPurchaseBy(purchaseInvoiceInformationDAO.getPurchaseBy());
	  	this.setPurchaseDateTime(purchaseInvoiceInformationDAO.getPurchaseDate());
	  	this.setPurchaseId(purchaseInvoiceInformationDAO.getPurchaseId());
	  	this.setSupplierName(purchaseInvoiceInformationDAO.getSupplierDetails());
	  	this.setInvoiceNumber(purchaseInvoiceInformationDAO.getInvoiceNumber());
	  	this.setPaymentDefaultValue(purchaseInvoiceInformationDAO.getPaymentType());
	  	if(this.getPurchaseInvoiceInformationDAO().getDirectDiscountAmount() == null)
	  	{
	  		this.getPurchaseInvoiceInformationDAO().setDirectDiscountAmount(0.0F);
	  	}
	  	this.setDirectDiscountAmount(this.getPurchaseInvoiceInformationDAO().getDirectDiscountAmount());
		this.setTcsPercentage(purchaseInvoiceInformationDAO.getTcsPercentage());
		this.setTcsAmount(purchaseInvoiceInformationDAO.getTcsAmount());
		
	  	this.setAddToStock(purchaseInvoiceInformationDAO.isAddToStock());
	  	sessionMap.put("purchaseInformation", purchaseInvoiceInformationDAO);
	  	sessionMap.put("purchaseProductList", purchaseProductInfoList);
		
	  
	  	this.setPaymentDefaultValue(this.getPaymentDefaultValue());
	}

	
public void setSession(Map<String, Object> map) {  
    sessionMap=(SessionMap<String, Object>)map;  
}

public HttpSession getSession() {
	return session;
}

public void setSession(HttpSession session) {
	this.session = session;
}

public SessionMap<String, Object> getSessionMap() {
	return sessionMap;
}

public void setSessionMap(SessionMap<String, Object> sessionMap) {
	this.sessionMap = sessionMap;
}





public PurchaseInvoiceInformationDAO getPurchaseInvoiceInformationDAO() {
	return purchaseInvoiceInformationDAO;
}





public void setPurchaseInvoiceInformationDAO(PurchaseInvoiceInformationDAO purchaseInvoiceInformationDAO) {
	this.purchaseInvoiceInformationDAO = purchaseInvoiceInformationDAO;
}





public List<PurchaseProductInfoDAO> getPurchaseProductInfoList() {
	return purchaseProductInfoList;
}





public void setPurchaseProductInfoList(List<PurchaseProductInfoDAO> purchaseProductInfoList) {
	this.purchaseProductInfoList = purchaseProductInfoList;
}





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 String getTotalPurchaseAmount() {
	return totalPurchaseAmount;
}





public void setTotalPurchaseAmount(String totalPurchaseAmount) {
	this.totalPurchaseAmount = totalPurchaseAmount;
}





public Float getAmountPaid() {
	return amountPaid;
}

public void setAmountPaid(Float amountPaid) {
	this.amountPaid = amountPaid;
}

public String getFrightCharges() {
	return frightCharges;
}





public void setFrightCharges(String frightCharges) {
	this.frightCharges = frightCharges;
}





public String getOtherExpense() {
	return otherExpense;
}





public void setOtherExpense(String otherExpense) {
	this.otherExpense = otherExpense;
}





public File getInvoiceImage() {
	return invoiceImage;
}





public void setInvoiceImage(File invoiceImage) {
	this.invoiceImage = invoiceImage;
}





public String getComments() {
	return comments;
}





public void setComments(String comments) {
	this.comments = comments;
}





public DecimalFormat getDf() {
	return df;
}





public void setDf(DecimalFormat df) {
	this.df = df;
}





public String getTotalNettAmount() {
	return totalNettAmount;
}





public void setTotalNettAmount(String totalNettAmount) {
	this.totalNettAmount = totalNettAmount;
}





public String getTotalCGST() {
	return totalCGST;
}





public void setTotalCGST(String totalCGST) {
	this.totalCGST = totalCGST;
}





public String getTotalSGST() {
	return totalSGST;
}





public void setTotalSGST(String totalSGST) {
	this.totalSGST = totalSGST;
}





public String getTotalIGST() {
	return totalIGST;
}





public void setTotalIGST(String totalIGST) {
	this.totalIGST = totalIGST;
}





public String getProductName() {
	return productName;
}





public void setProductName(String productName) {
	this.productName = productName;
}





public String getAmount() {
	return amount;
}





public void setAmount(String amount) {
	this.amount = amount;
}





public String getQuantity() {
	return quantity;
}





public void setQuantity(String quantity) {
	this.quantity = quantity;
}





public String getPurchaseUnit() {
	return purchaseUnit;
}





public void setPurchaseUnit(String purchaseUnit) {
	this.purchaseUnit = purchaseUnit;
}





public String getPurchaseRate() {
	return purchaseRate;
}





public void setPurchaseRate(String purchaseRate) {
	this.purchaseRate = purchaseRate;
}





public String getTaxId() {
	return taxId;
}





public void setTaxId(String taxId) {
	this.taxId = taxId;
}





public String getPurchaseId() {
	return purchaseId;
}





public void setPurchaseId(String purchaseId) {
	this.purchaseId = purchaseId;
}





public String getSupplierName() {
	return supplierName;
}





public void setSupplierName(String supplierName) {
	this.supplierName = supplierName;
}





public String getInvoiceNumber() {
	return invoiceNumber;
}





public void setInvoiceNumber(String invoiceNumber) {
	this.invoiceNumber = invoiceNumber;
}





public String getInvoiceImageContentType() {
	return invoiceImageContentType;
}





public void setInvoiceImageContentType(String invoiceImageContentType) {
	this.invoiceImageContentType = invoiceImageContentType;
}





public boolean isAddToStock() {
	return addToStock;
}





public void setAddToStock(boolean addToStock) {
	this.addToStock = addToStock;
}





public Map<String, String> getCustomerSearchOptionList() {
	return customerSearchOptionList;
}





public void setCustomerSearchOptionList(Map<String, String> customerSearchOptionList) {
	this.customerSearchOptionList = customerSearchOptionList;
}





public String getCustomerSearchOption() {
	return customerSearchOption;
}





public void setCustomerSearchOption(String customerSearchOption) {
	this.customerSearchOption = customerSearchOption;
}





public String getDefaultValue() {
	return defaultValue;
}





public void setDefaultValue(String defaultValue) {
	this.defaultValue = defaultValue;
}





public static long getSerialversionuid() {
	return serialVersionUID;
}

public String getPurchaseDateTime() {
	return purchaseDateTime;
}

public void setPurchaseDateTime(String purchaseDateTime) {
	this.purchaseDateTime = purchaseDateTime;
}

public String getPaymentType() {
	return paymentType;
}

public void setPaymentType(String paymentType) {
	this.paymentType = paymentType;
}

public Map<String, String> getPaymentTypeList() {
	return paymentTypeList;
}

public void setPaymentTypeList(Map<String, String> paymentTypeList) {
	this.paymentTypeList = paymentTypeList;
}

public String getPaymentDefaultValue() {
	return paymentDefaultValue;
}

public void setPaymentDefaultValue(String paymentDefaultValue) {
	this.paymentDefaultValue = paymentDefaultValue;
}

public String getPurchaseBy() {
	return purchaseBy;
}

public void setPurchaseBy(String purchaseBy) {
	this.purchaseBy = purchaseBy;
}

public Map<String, String> getRateTypeList() {
	return rateTypeList;
}

public void setRateTypeList(Map<String, String> rateTypeList) {
	this.rateTypeList = rateTypeList;
}

public String getRateTyprDefaultValue() {
	return rateTyprDefaultValue;
}

public void setRateTyprDefaultValue(String rateTyprDefaultValue) {
	this.rateTyprDefaultValue = rateTyprDefaultValue;
}

public Float getTcsPercentage() {
	return tcsPercentage;
}

public void setTcsPercentage(Float tcsPercentage) {
	this.tcsPercentage = tcsPercentage;
}

public Float getTcsAmount() {
	return tcsAmount;
}

public void setTcsAmount(Float tcsAmount) {
	this.tcsAmount = tcsAmount;
}

public Float getDirectDiscountAmount() {
	return directDiscountAmount;
}

public void setDirectDiscountAmount(Float directDiscountAmount) {
	this.directDiscountAmount = directDiscountAmount;
}

public List<String> getPaymentTypeList2() {
	return paymentTypeList2;
}

public void setPaymentTypeList2(List<String> paymentTypeList2) {
	this.paymentTypeList2 = paymentTypeList2;
}

public String getModeOfPayment() {
	return modeOfPayment;
}

public void setModeOfPayment(String modeOfPayment) {
	this.modeOfPayment = modeOfPayment;
}

public String getAccountId() {
	return accountId;
}

public void setAccountId(String accountId) {
	this.accountId = accountId;
}

public Map<String, String> getAccountList() {
	return accountList;
}

public void setAccountList(Map<String, String> accountList) {
	this.accountList = accountList;
}



}
