package ibase.webitm.ejb.mfg.adv;

import ibase.webitm.utility.ITMException;
import ibase.webitm.utility.GenericUtility;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.*;
import ibase.system.config.AppConnectParm;
import javax.naming.InitialContext;
import java.sql.*;
import java.util.*;
import javax.ejb.*;

public class BOMStockBean
{
	public String itemCode = "",reqType = "",descr = "", bomCode = "",batchQtyD ="",iCode ="",iDescr="";
	public double stock = 0.0,batchQty = 0.0,qtyPar = 0.0,minQty = 0.0, reqQty = 0.0,stkQty = 0.0,nonStkQty = 0.0,quantity=0.0,allockQty=0.0;
	
	public void setBomCode(String bomCodeJsp)
	{
		this.bomCode = bomCodeJsp;
	}
	public void setBatchQtyD(String batchQtyDJsp)
	{
		this.batchQtyD = batchQtyDJsp;
	}
	
	
	public ArrayList getDetails() throws Exception
	{
		ArrayList stkBomRetArr = new ArrayList();
		ArrayList thisBeanArray = new ArrayList();
		InitialContext ctx = null;
		BOMAct.BOMStockDtlParams stkParms = null;
		BOMStockBean stkBomBean = null;
		AppConnectParm appConnect = null;
		BOMActLocal homeObj = null;
		try
		{			
			appConnect = new AppConnectParm();
			ctx = new InitialContext(appConnect.getProperty());
			homeObj = (BOMActLocal)ctx.lookup("ibase/BOMAct/local"); // for BaseInfo ejb3
			stkBomRetArr = homeObj.getDetails(this.bomCode,this.batchQtyD);
			if(stkBomRetArr.size() > 0)
			{
				for (int i=0; i<stkBomRetArr.size(); i++ )
				{
					stkParms = (BOMAct.BOMStockDtlParams)(stkBomRetArr.get(i));
					stkBomBean = new BOMStockBean();
					System.out.println("reqQty is in bean:::"+stkParms.reqQty);								
					stkBomBean.itemCode = stkParms.itemCode;
					stkBomBean.reqType = stkParms.reqType;
					stkBomBean.minQty = stkParms.minQty;
					stkBomBean.qtyPar = stkParms.qtyPar;
					stkBomBean.batchQty = stkParms.batchQty;
					stkBomBean.bomCode = stkParms.bomCode;
					stkBomBean.descr = stkParms.descr;
					stkBomBean.reqQty = stkParms.reqQty;
					stkBomBean.stkQty = stkParms.stkQty;
					stkBomBean.nonStkQty = stkParms.nonStkQty;
					//stkBomBean.stock = stkParms.stock;
				//	stkBomBean.quantity = Double.toString(stkParms.quantity);
					stkBomBean.allockQty = stkParms.allockQty;
				//	stkBomBean.reqQty = stkParms.reqQty;
					
					thisBeanArray.add(stkBomBean);
				}
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			appConnect = null;
			ctx = null;
			homeObj = null;
			stkBomRetArr = null;
			stkParms = null;
		}
		return thisBeanArray;
	}
}