package ibase.webitm.ejb.dis;

import ibase.system.config.AppConnectParm;
import ibase.webitm.utility.ITMException;

import java.util.ArrayList;
import java.util.HashMap;

import javax.naming.InitialContext;

public class StockHelpBean
{
	String siteCode = "";
	String itemCode = "";
	
	public String locCode = "",lotNo = "",locSl = "",unit = "",dimention = "", mfgDate = "";
	public String quantity = "",allocQty = "",netAvailable = "",available = "", noArt = "", itemCodeStk = "",siteCodeStk= "";
	public String retestDate = "",expDate = "",potency = "",partialusedc = "",allocQuantLableC = "", suppCodeMfg = "",batchNo = "", rate = "", packRef = "";
	public String packCode = "", invStat = "", holdQuant = "", qtyPerArt = "", batchSize = "";
	public String ppoQty = "", pindQty = "",lotNo1 = "";	
	
    public String effqty = "",qtybefore = "",qtyaft = "",rateinv = "",noartinv = "",grossrate = "",actqty = "",convqty = "",amount = "",rateinsu = "";	
    public String trandate = "",tranidhere ="",refser = "",refid = "",refline = "",orderid = "",efedate = "",chgwin = "",reascode = "";
    public String sundrytype = "",sundrycode = "",refdate = "",refserfor = "",refidfor = "",acctcddr = "",cctrcddr = "",acctcdcr = "",cctrcdcr = "",grade = "",currLocCode1 = "",currLotNo1 = "",currLotSl1 = "",invStat1 = "";
	
	
	
	public HashMap beanLotQuantMap = new HashMap();
	public java.sql.Timestamp currDateTs = null;
	
	public void setSiteCode(String siteCodeJsp)
	{
		this.siteCode = siteCodeJsp;
	}
	public void setItemCode(String itemCodeJsp)
	{
		this.itemCode = itemCodeJsp;
	}
	public void setLotNo(String lotNoJsp)
	{
		this.lotNo = lotNoJsp;
	}
	
	public ArrayList getDetails() throws Exception
	{
		ArrayList stkHlpRetArr = new ArrayList();
		ArrayList thisBeanArray = new ArrayList();
		InitialContext ctx = null;
		StockHelp.StockDtlParams stkParms = null;
		StockHelpBean stkHlpBean = null;
		AppConnectParm appConnect = null;
		StockHelpLocal homeObj = null;
		StockHelpRemote stkHelpRemote = null;
		try
		{			
			appConnect = new AppConnectParm();
			ctx = new InitialContext(appConnect.getProperty());
			//homeObj = (StockHelpLocal)ctx.lookup("StockHelp");    for ejb2
			homeObj = (StockHelpLocal)ctx.lookup("ibase/StockHelp/local"); // for BaseInfo ejb3
			//stkHelpRemote = (StockHelpRemote)ctx.lookup(HelloEjb.class.getName());  // standard
			//stkHelpRemote = (StockHelpRemote)(homeObj.create());   //for ejb2
			stkHlpRetArr = homeObj.getDetails(this.siteCode,this.itemCode);
			if(stkHlpRetArr.size() > 0)
			{
				for (int i=0; i<stkHlpRetArr.size(); i++ )
				{
					stkParms = (StockHelp.StockDtlParams)(stkHlpRetArr.get(i));
					stkHlpBean = new StockHelpBean();
					stkHlpBean.itemCodeStk = stkParms.itemCode;
					stkHlpBean.locCode = stkParms.currLocCode;
					stkHlpBean.lotNo = stkParms.currLotNo;
					stkHlpBean.locSl = stkParms.currLotSl;
					stkHlpBean.mfgDate = stkParms.mfgDate;
					stkHlpBean.noArt = stkParms.noArt;
					stkHlpBean.rate = stkParms.rate;
					
					stkHlpBean.available = stkParms.available;
					stkHlpBean.unit = stkParms.unit;
					stkHlpBean.quantity = Double.toString(stkParms.quantity);
					stkHlpBean.allocQty = Double.toString(stkParms.allocQuant);
					stkHlpBean.allocQuantLableC = stkParms.allocQuantLable;
					stkHlpBean.holdQuant = Double.toString(stkParms.holdQuant);
					stkHlpBean.netAvailable = stkParms.netAvailable;
					stkHlpBean.retestDate = stkParms.retestDate;
					stkHlpBean.expDate = stkParms.expDate;					
					stkHlpBean.potency = stkParms.potencyPerc;
					stkHlpBean.partialusedc = stkParms.partialused;    //added by deepak sawant
					stkHlpBean.suppCodeMfg = stkParms.suppCodeMfg;					
					stkHlpBean.batchNo = stkParms.batchNo;
					stkHlpBean.dimention = stkParms.dimention;
					stkHlpBean.packCode = stkParms.packCode;
					stkHlpBean.invStat = stkParms.invStat;
					stkHlpBean.beanLotQuantMap = stkParms.lotQuantMap;
					stkHlpBean.currDateTs = stkParms.currDateTs;
					stkHlpBean.qtyPerArt = stkParms.qtyPerArt;
					stkHlpBean.batchSize = stkParms.batchSize;
					stkHlpBean.packRef = stkParms.packRef; //added by swati bade on 09-May-2013
					stkHlpBean.ppoQty = stkParms.ppoQty;
					stkHlpBean.pindQty = stkParms.pindQty;
					thisBeanArray.add(stkHlpBean);
				}
			}
			
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			appConnect = null;
			ctx = null;
			homeObj = null;
			stkHelpRemote = null;
			stkHlpRetArr = null;
			stkParms = null;
		}
		System.out.println(">>>>>>>>>>>>>>ddDD"+thisBeanArray);
		return thisBeanArray;
	}
	
	public ArrayList loaddata() throws Exception
	{
		
		ArrayList stkHlpRetArr = new ArrayList();
		ArrayList thisBeanArray = new ArrayList();
		InitialContext ctx = null;
		StockHelp.StockDtlParams stkParms = null;
		StockHelpBean stkHlpBean = null;
		AppConnectParm appConnect = null;
		StockHelpLocal homeObj = null;
		StockHelpRemote stkHelpRemote = null;
		
		try
		{
			appConnect = new AppConnectParm();
			ctx = new InitialContext(appConnect.getProperty());
			//homeObj = (StockHelpLocal)ctx.lookup("StockHelp");    for ejb2
			homeObj = (StockHelpLocal)ctx.lookup("ibase/StockHelp/local"); // for BaseInfo ejb3
			//stkHelpRemote = (StockHelpRemote)ctx.lookup(HelloEjb.class.getName());  // standard
			//stkHelpRemote = (StockHelpRemote)(homeObj.create());   //for ejb2
			System.out.println(">>>>>>BEFORE ADDING LOADDATA"+lotNo);
			stkHlpRetArr = homeObj.loadData(this.lotNo, this.siteCode,this.itemCode);
			if(stkHlpRetArr.size() > 0)
			{
				for (int i=0; i<stkHlpRetArr.size(); i++ )
				{
					stkParms = (StockHelp.StockDtlParams)(stkHlpRetArr.get(i));
					stkHlpBean = new StockHelpBean();
					stkHlpBean.tranidhere = stkParms.tranid;
					stkHlpBean.trandate = stkParms.trandate;
					stkHlpBean.refser =stkParms.refser;
					stkHlpBean.refid = stkParms.refid;
					stkHlpBean.refline = stkParms.refline;
					stkHlpBean.orderid = stkParms.orderid;
					stkHlpBean.itemCodeStk = stkParms.itemCode1;
					stkHlpBean.siteCodeStk = stkParms.siteCode1;
					stkHlpBean.currLocCode1 = stkParms.currLocCode;
					stkHlpBean.unit = stkParms.unit;
					stkHlpBean.currLotNo1 = stkParms.currLotNo;
					stkHlpBean.currLotSl1 = stkParms.currLotSl;
					stkHlpBean.quantity = Double.toString(stkParms.quantity);
					stkHlpBean.effqty = Double.toString(stkParms.effqty);
					stkHlpBean.efedate = stkParms.efedate;
					stkHlpBean.chgwin = stkParms.chgwin;
					stkHlpBean.qtybefore = Double.toString(stkParms.qtybefore);
					stkHlpBean.qtyaft = Double.toString(stkParms.qtyaft);
					stkHlpBean.reascode = stkParms.reascode;
					stkHlpBean.sundrytype = stkParms.sundrytype;
					stkHlpBean.sundrycode = stkParms.sundrycode;
					stkHlpBean.refdate = stkParms.refdate;
					stkHlpBean.refserfor = stkParms.refserfor;
					stkHlpBean.refidfor = stkParms.refidfor;
					stkHlpBean.acctcddr = stkParms.acctcddr;
					stkHlpBean.cctrcddr = stkParms.cctrcddr;
					stkHlpBean.acctcdcr = stkParms.acctcdcr;
					stkHlpBean.cctrcdcr = stkParms.cctrcdcr;
					stkHlpBean.grade = stkParms.grade;
					stkHlpBean.rateinv = Double.toString(stkParms.rateinv);
					stkHlpBean.grossrate = Double.toString(stkParms.grossrate);
					stkHlpBean.noartinv = Double.toString(stkParms.noartinv);
					stkHlpBean.dimention = stkParms.dimention;
					stkHlpBean.actqty = Double.toString(stkParms.actqty);
					stkHlpBean.convqty = Double.toString(stkParms.convqty);
					stkHlpBean.amount = Double.toString(stkParms.amount);
					stkHlpBean.invStat1 = stkParms.invStat1;
					stkHlpBean.rateinsu = Double.toString(stkParms.rateinsu);
					thisBeanArray.add(stkHlpBean);
				}
			}
			
		}catch(Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			appConnect = null;
			ctx = null;
			homeObj = null;
			stkHelpRemote = null;
			stkHlpRetArr = null;
			stkParms = null;
		}
		
		System.out.println(">>>>>>>>>>>>>>"+thisBeanArray);
		return thisBeanArray;
		
	}
	public String getItemDescr(String itemCode) throws Exception
	{
		InitialContext ctx = null;
		AppConnectParm appConnect = null;
		StockHelpLocal homeObj = null;
		String itemDescr = "";
		try
		{			
			appConnect = new AppConnectParm();
			ctx = new InitialContext(appConnect.getProperty());
			homeObj = (StockHelpLocal)ctx.lookup("ibase/StockHelp/local"); 
			itemDescr = homeObj.getItemDescr(itemCode);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			appConnect = null;
			ctx = null;
			homeObj = null;
		}
		return itemDescr;
	
	}
	
	
	
	
	
	
}