/*Migrated by Khushal A 2025
 * component : nvo_bo_inv_allocate.sru
 */

package ibase.webitm.ejb.dis;
import java.rmi.RemoteException;	
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.fin.FinCommon;
import ibase.webitm.utility.ITMException;

public class ReserveInventoryIC extends ValidatorEJB{
	E12GenericUtility genericUtility = new E12GenericUtility();


	public String wfValData(Document dom, Document dom1, Document dom2, String objContext, String editFlag, String xtraParams) throws RemoteException, ITMException {
		String errString = "", sql = "", itemGrp = "", expDate = "", effDate = "", tranType = "", siteCode = "", itemCode = "", workOrder = "";
		ResultSet rs = null;
		PreparedStatement pstmt = null;
		int cnt = 0;
		int ctr=0;
		int childNodeListLength;
		Timestamp tranDate1=null;
		String childNodeName = null;
		ITMDBAccessEJB itmDbAccess = null;
		Timestamp expDatePS = null, effDatePS = null;
		String tranDate = "";
		NodeList parentNodeList = null;
		NodeList childNodeList = null;
		org.w3c.dom.Node parentNode = null;
		org.w3c.dom.Node childNode = null;
		FinCommon finCommon = null;
		boolean isError = false;
		java.sql.Connection conn = null;
		int currentFormNo = 0;
		String errcode="",tranId="";
		String ls_itemcode="";
		String ls_status="";
		String ls_crit_item="",ls_work_order="";
		Double lc_qty=0.0;
		String lotNo="";
		String lotSl="";
		String locCode="";
		double lc_quantity=0.0;
		String ls_qcreqd = "",lc_quantitystr="";
		String ls_iss_criteria = "";
		Double lc_stock = 0.0;
		Double lc_stk_qty = 0.0;
		String ls_track_shelf_life ="";
		String ls_auto_reqc="";
		Timestamp ldtoday=null;
		String ls_bomcode="" , ls_workorder="";
		String ls_bom_code="";
		try 
		{
			itmDbAccess = new ITMDBAccessEJB();
			conn = getConnection();
			if(objContext != null && objContext.trim().length() > 0)
			{
				currentFormNo = Integer.parseInt(objContext);
			}
			switch(currentFormNo) 
			{	
			case 1:
				parentNodeList = dom.getElementsByTagName("Detail1");
				parentNode = parentNodeList.item(0);
				childNodeList = parentNode.getChildNodes();
				childNodeListLength = childNodeList.getLength();
				for(ctr = 0; ctr < childNodeListLength; ctr++) 
				{
					isError = false;
					childNode = childNodeList.item(ctr);
					childNodeName = childNode.getNodeName();
					if (childNodeName == null)
					{
						continue;
					}
					childNodeName = childNodeName.trim();
					switch(childNodeName)
					{
					case "tran_date":
					{
						tranDate=whenNull(getItemString(dom, 1,"tran_date"));
						if(tranDate != null && tranDate.trim().length()>0) 
						{
							tranDate1 =Timestamp.valueOf(genericUtility.getValidDateString(tranDate, genericUtility.getApplDateFormat(), genericUtility.getDBDateFormat()) + " 00:00:00");
						}
						if (tranDate1 ==  null) {
							if ("E".equalsIgnoreCase(whenNull(insertError("VEDAT2", childNodeName)))) {
								isError = true;
								break;
							}
						}
						break;
					}
					case "tran_type":
					{
						tranType = whenNull(getItemString(dom, 1, "tran_type"));
						if (tranType.equals("AUT")) {
							if ("E".equalsIgnoreCase(whenNull(insertError("VTAUTOG1", childNodeName)))) {
								isError = true;
								break;
							}
						}
						break;
					}
					case "site_code":
					{
						siteCode = whenNull(getItemString(dom, 1, "site_code"));
						sql = "SELECT COUNT(*) FROM site WHERE site_code = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, siteCode);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;
						if (cnt == 0) {
							if ("E".equalsIgnoreCase(whenNull(insertError("VTSITECD1", childNodeName)))) {
								isError = true;
								break;
							}
						}
						break;
					}
					case "item_code":
					{
						itemCode = whenNull(getItemString(dom, 1, "item_code"));
						workOrder = whenNull(getItemString(dom, 1, "work_order"));
						tranId = whenNull(getItemString(dom, 1, "tran_id"));
						sql = "SELECT COUNT(*) FROM item WHERE item_code = ? ";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, itemCode);
						rs = pstmt.executeQuery();
						if (rs.next()) {
							cnt = rs.getInt(1);
						}
						rs.close();
						rs = null;
						pstmt.close();
						pstmt = null;

						if (cnt == 0) {
							if ("E".equalsIgnoreCase(whenNull(insertError("VTITEM1", childNodeName)))) {
								isError = true;
								break;
							}
						}
						BaseLogger.log("3", getUserInfo(), null,"tranId*********" +tranId);
						BaseLogger.log("3", getUserInfo(), null,"itemCode*********" +itemCode);
						BaseLogger.log("3", getUserInfo(), null,"workOrder*********" +itemCode);


						if (workOrder ==  null || workOrder.trim().length() == 0) {
							if (tranId == null) {
								tranId = " ";
							}
							sql = "SELECT COUNT(*) FROM inv_allocate WHERE item_code = ? AND tran_id <> ? AND confirmed = 'N' AND work_order IS NULL";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, itemCode);
							pstmt.setString(2, tranId);
							rs = pstmt.executeQuery();
							if (rs.next()) {
								cnt = rs.getInt(1);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if (cnt > 0) {
								if ("E".equalsIgnoreCase(whenNull(insertError("VTITEMCO", childNodeName)))) {
									isError = true;
									break;
								}
							}
						}
						break;
					}
					case "work_order":
					{
						workOrder = whenNull(getItemString(dom, 1, "work_order"));
						if (workOrder.trim().length() > 0) {
							sql = "SELECT status FROM workorder WHERE work_order = ?";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, workOrder);
							rs = pstmt.executeQuery();
							ls_status = null;
							if (rs.next()) {
								ls_status = rs.getString(1);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if ("X".equals(ls_status))
							{
								if ("E".equalsIgnoreCase(whenNull(insertError("VTWOCANCEL", childNodeName)))) {
									isError = true;
									break;
								}
							} else if ("C".equals(ls_status)) 
							{
								if ("E".equalsIgnoreCase(whenNull(insertError("VTWOCLOSE", childNodeName)))) {
									isError = true;
									break;
								}
							}
							else if (ls_status==null || ls_status.trim().length() == 0) {
								siteCode = whenNull(getItemString(dom, 1, "site_code"));
								sql = "SELECT site_code FROM workorder WHERE work_order = ?";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1, workOrder);
								rs = pstmt.executeQuery();
								String ls_wosite = null;
								if (rs.next()) {
									ls_wosite = rs.getString(1);
								}
								rs.close();
								rs = null;
								pstmt.close();
								pstmt = null;
								if (!siteCode.equals(ls_wosite)) {
									if ("E".equalsIgnoreCase(whenNull(insertError("VTWOSITE1", childNodeName)))) {
										isError = true;
										break;
									}
								}
							}
						}
						tranId = whenNull(getItemString(dom, 1, "tran_id"));
						if (tranId== null) {
							sql = "SELECT COUNT(*) FROM inv_allocate WHERE work_order = ? AND tran_id <> ? AND confirmed = 'N'";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, workOrder);
							pstmt.setString(2, tranId);
							rs = pstmt.executeQuery();
							if (rs.next()) {
								cnt = rs.getInt(1);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if (cnt > 0) {
								if ("E".equalsIgnoreCase(whenNull(insertError("VTWOCON", childNodeName)))) {
									isError = true;
									break;

								}
							}
						}
						break;
					}
					}
				}
				break;
			case 2:
			{
				parentNodeList = dom.getElementsByTagName("Detail2");
				parentNode = parentNodeList.item(0);
				childNodeList = parentNode.getChildNodes();
				childNodeListLength = childNodeList.getLength();
				for(ctr = 0; ctr < childNodeListLength; ctr++) 
				{
					isError = false;
					childNode = childNodeList.item(ctr);
					childNodeName = childNode.getNodeName();
					if (childNodeName == null)
					{
						continue;
					}
					childNodeName = childNodeName.trim();

					switch(childNodeName)
					{
					case "item_code":
					{
						itemCode = whenNull(getItemString(dom, 1,"item_code"));
						ls_workorder = whenNull(getItemString(dom1, 1,"work_order"));
						ls_itemcode = whenNull(genericUtility.getColumnValue("item_code", dom1));

						if (itemCode.trim() != null && itemCode.trim().length() > 0 && 
								ls_itemcode.trim() != null && ls_itemcode.trim().length() > 0) 
						{
							if (itemCode.trim().equals(ls_itemcode.trim())) 
							{
								System.out.println("Case10++itemcode " + itemCode);
								System.out.println("Case21 " + ls_itemcode);
								errString = "VTITMSAME";
								if ("E".equalsIgnoreCase(whenNull(insertError(errString, childNodeName)))) 
								{
									isError = true;
									break;
								}
							}
						}

						ls_work_order= whenNull(getItemString(dom1, 1,"work_order"));
						System.out.println("caseval+++++++++"+ls_work_order);

						if(ls_work_order != null && ls_work_order.trim().length() > 0) 
						{
							sql="select bom_code from workorder where work_order = ?";
							pstmt=conn.prepareStatement(sql);
							pstmt.setString(1, ls_work_order);
							rs=pstmt.executeQuery();
							if(rs.next())
							{
								ls_bom_code = rs.getString("bom_code");
							}
							rs.close(); 
							rs = null;
							pstmt.close();
							pstmt = null;

							sql = "select count(*) from bomdet where bom_code = ? and item_code = ?";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, ls_bom_code);
							pstmt.setString(2, itemCode);
							rs = pstmt.executeQuery();
							if (rs.next()) 
							{
								cnt = rs.getInt(1);
							}
							rs.close();
							rs = null;
							pstmt.close();
							pstmt = null;
							if (cnt <= 0) 
							{
								if("E".equalsIgnoreCase(whenNull(insertError("VTNOBOMITM", childNodeName))))
								{
									isError = true;
									break;
								}
							}
						}

						sql = "select count(*) from stock where item_code = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, itemCode);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();rs = null;
						pstmt.close();pstmt = null;
						if (cnt == 0) 
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VXSTKITM", childNodeName))))
							{
								isError = true;
								break;
							}
						}

						System.out.println("Khushal8888888888888880" + ls_workorder );

						if ((ls_workorder != null && ls_workorder.trim().length() > 0))
						{
							System.out.println("Inside Case 2 Work Order ");
							sql = "select bom_code, status from workorder where work_order = ?";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, ls_workorder);
							rs = pstmt.executeQuery();
							if (rs.next()) 
							{
								ls_bom_code = rs.getString("bom_code");
								ls_status = rs.getString("status");
							}
							rs.close();rs = null;
							pstmt.close();pstmt = null;
							if (ls_status != null && (ls_status.equalsIgnoreCase("R") || ls_status.equalsIgnoreCase("F")))
							{
								sql = "select crit_item, exp_lev from workorder_bill where work_order = ? and item_code = ?";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1, ls_workorder);
								pstmt.setString(2, itemCode);
								rs = pstmt.executeQuery();
								while(rs.next())
								{
									ls_crit_item = rs.getString("crit_item");
									String ls_explevstr=rs.getString("exp_lev");
									if (ls_crit_item == null) 
									{
										ls_crit_item = "N";
									}
									if (ls_status.equalsIgnoreCase("R")) 
									{
										if (ls_crit_item.equalsIgnoreCase("Y")) 
										{
											if("E".equalsIgnoreCase(whenNull(insertError("VTWOCRIT1", childNodeName))))
											{
												isError = true;
												break;
											}
										}
										else
										{
											sql = "select Sum(b.quantity) from workorder_iss a,workorder_issdet b where a.work_order = ? and a.tran_id = b.tran_id and b.item_code = ?";
											pstmt = conn.prepareStatement(sql);
											pstmt.setString(1, ls_workorder);
											pstmt.setString(2, itemCode);
											ResultSet rs1 = pstmt.executeQuery();
											if (rs1.next())
											{
												lc_qty = rs1.getDouble(1);
											}
											rs1.close();rs1 = null;
											pstmt.close();pstmt = null;
											if (lc_qty > 0)
											{
												if("E".equalsIgnoreCase(whenNull(insertError("VTALISS", childNodeName))))
												{
													isError = true;
													break;
												}
											}
										}
									}
									else if (ls_status.equalsIgnoreCase("F"))
									{
										if (ls_crit_item.equalsIgnoreCase("Y")) 
										{
											if("E".equalsIgnoreCase(whenNull(insertError("VTWOCRIT2", childNodeName))))
											{
												isError = true;
												break;
											}
										}
									}
								}	
							}
						}
						break;
					}
					case "site_code":
					{
						siteCode = whenNull(getItemString(dom, 1,"site_code"));
						sql = "Select Count(*) from stock where site_code = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, siteCode);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();rs = null;
						pstmt.close();pstmt = null;
						if (cnt == 0) 
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VXSTKSITE", childNodeName))))
							{
								isError = true;
								break;
							}
						}
						break;
					}
					case "loc_code":
					{
						locCode = whenNull(getItemString(dom, 1,"loc_code"));
						sql = "select count(*) from stock where loc_code = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, locCode);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();rs = null;
						pstmt.close();pstmt = null;
						if (cnt == 0) 
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VXSTKLOC", childNodeName))))
							{
								isError = true;
								break;
							}
						}
						break;
					}
					case "lot_no":
					{
						lotNo = whenNull(getItemString(dom, 1,"lot_no"));
						itemCode = whenNull(getItemString(dom, 1,"item_code"));
						siteCode = whenNull(getItemString(dom, 1,"site_code"));
						locCode = whenNull(getItemString(dom, 1,"loc_code"));
						sql = "select count(*) from stock where item_code = ? and site_code = ? and loc_code = ? and lot_no = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, itemCode);
						pstmt.setString(2, siteCode);
						pstmt.setString(3, locCode);
						pstmt.setString(4, lotNo);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();rs = null;
						pstmt.close();pstmt = null;
						if (cnt == 0) 
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VMLOTNO1", childNodeName))))
							{
								isError = true;
								break;
							}
						}
						break;
					}
					case "lot_sl":
					{
						lotSl = whenNull(getItemString(dom, 1,childNodeName));
						itemCode = whenNull(getItemString(dom, 1,"item_code"));
						siteCode = whenNull(getItemString(dom, 1,"site_code"));
						locCode = whenNull(getItemString(dom, 1,"loc_code"));
						lotNo = whenNull(getItemString(dom, 1,"lot_no"));
						sql = "select count(*) from stock where item_code = ? and site_code = ? and loc_code = ? and lot_no = ? and lot_sl = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, itemCode);
						pstmt.setString(2, siteCode);
						pstmt.setString(3, locCode);
						pstmt.setString(4, lotNo);
						pstmt.setString(5, lotSl);
						rs = pstmt.executeQuery();
						if (rs.next()) 
						{
							cnt = rs.getInt(1);
						}
						rs.close();rs = null;
						pstmt.close();pstmt = null;
						if (cnt == 0) 
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VMLOTSL1", childNodeName))))
							{
								isError = true;
								break;
							}
						}
						break;
					}
					case "quantity":
					{
						lc_quantitystr = (getItemString(dom, 1,"quantity"));
						if(lc_quantitystr != null && lc_quantitystr.trim().length()>0)
						{
							lc_quantity=Double.parseDouble(lc_quantitystr);
						}
						itemCode = whenNull(getItemString(dom, 1,"item_code"));
						siteCode = whenNull(getItemString(dom, 1,"site_code"));
						locCode = whenNull(getItemString(dom, 1,"loc_code"));
						lotNo = whenNull(getItemString(dom, 1,"lot_no"));
						lotSl = whenNull(getItemString(dom, 1,"lot_sl"));

						if (lc_quantity <= 0)
						{
							if("E".equalsIgnoreCase(whenNull(insertError("VTQTY", childNodeName))))
							{
								isError = true;
								break;
							}
						}
						else
						{
							sql = "SELECT (CASE WHEN qc_reqd IS NULL THEN 'N' ELSE qc_reqd END) AS qc_reqd," + 
									"(CASE WHEN iss_criteria IS NULL THEN 'I' ELSE iss_criteria END) AS iss_criteria," + 
									"(CASE WHEN track_shelf_life IS NULL THEN 'N' ELSE track_shelf_life END) AS track_shelf_life FROM item WHERE item_code =?";
							pstmt = conn.prepareStatement(sql);
							pstmt.setString(1, itemCode);
							rs = pstmt.executeQuery();
							if(rs.next())
							{
								ls_qcreqd = rs.getString("qc_reqd");
								ls_iss_criteria = rs.getString("iss_criteria");
								ls_track_shelf_life = rs.getString("track_shelf_life");
							}
							rs.close();rs = null;
							pstmt.close();pstmt = null;

							if (ls_qcreqd.equalsIgnoreCase("N"))
							{
								sql = "select quantity - (case when alloc_qty is null then 0 else alloc_qty end) - (case when hold_qty is null then 0 else hold_qty end) , quantity from stock,location,invstat where stock.loc_code = location.loc_code and location.inv_stat = invstat.inv_stat and stock.item_code = ? and stock.site_code = ? and stock.loc_code = ? and stock.lot_no = ? and stock.lot_sl = ? and invstat.available = 'Y'";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1, itemCode);
								pstmt.setString(2, siteCode);
								pstmt.setString(3, locCode);
								pstmt.setString(4, lotNo);
								pstmt.setString(5, lotSl);
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									lc_stock = rs.getDouble(1);
									lc_stk_qty = rs.getDouble(2);
								}
								rs.close();rs = null;
								pstmt.close();pstmt = null;
								if (ls_iss_criteria.equalsIgnoreCase("W") && lc_quantity != lc_stk_qty)
								{
									if("E".equalsIgnoreCase(whenNull(insertError("VTALOCQTY", childNodeName))))
									{
										isError = true;
										break;
									}
								}
							}
							else
							{
								ldtoday = new Timestamp(System.currentTimeMillis());
								sql = "select auto_reqc from siteitem where item_code = ? and site_code = ?";
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1, itemCode);
								pstmt.setString(2, siteCode);
								rs = pstmt.executeQuery();
								if(rs.next())
								{
									ls_auto_reqc = rs.getString("auto_reqc");
								}
								rs.close();rs = null;
								pstmt.close();pstmt = null;
								if (ls_auto_reqc == null) ls_auto_reqc = "N";
								sql = "select quantity - (case when alloc_qty is null then 0 else alloc_qty end) - (case when hold_qty is null then 0 else hold_qty end) from stock, location, invstat where stock.loc_code = location.loc_code and location.inv_stat = invstat.inv_stat and stock.item_code = ? and stock.site_code = ? and stock.loc_code = ? and stock.lot_no = ? and stock.lot_sl = ? and invstat.available = 'Y'";
								if (ls_track_shelf_life.equalsIgnoreCase("Y"))
								{
									sql = sql + "and (stock.exp_date > ? or stock.exp_date is null) ";
								}
								if (ls_auto_reqc.equalsIgnoreCase("Y"))
								{
									sql = sql + "and stock.retest_date > ? ";
								}
								pstmt = conn.prepareStatement(sql);
								pstmt.setString(1, itemCode);
								pstmt.setString(2, siteCode);
								pstmt.setString(3, locCode);
								pstmt.setString(4, lotNo);
								pstmt.setString(5, lotSl);
								int paramIndex = 6;
								if (ls_track_shelf_life.equalsIgnoreCase("Y"))
								{
									pstmt.setTimestamp(paramIndex, ldtoday);
									paramIndex++;
								}
								if (ls_auto_reqc.equalsIgnoreCase("Y"))
								{
									pstmt.setTimestamp(paramIndex, ldtoday);
								}
								rs = pstmt.executeQuery();
								if (rs.next())
								{
									lc_stock = rs.getDouble(1);
								}
								rs.close();rs = null;
								pstmt.close();pstmt = null;
							}
							if (lc_stock < lc_quantity)
							{
								if("E".equalsIgnoreCase(whenNull(insertError("VTQTYA2", childNodeName))))
								{
									isError = true;
									break;
								}
							}

						}
						break;
					}
					}
					if(isError)
					{
						break;
					}
				}

			}
			}

		}
		catch (Exception e)
		{
			e.printStackTrace();
			errString = e.getMessage();
			throw new ITMException(e);
		} 
		finally 
		{
			try {
				if (conn != null)
				{
					if (rs != null) 
					{
						rs.close();
						rs = null;
					}
					if (pstmt != null)
					{
						pstmt.close();
						pstmt = null;
					}
				}
			} catch (Exception d) {
				d.printStackTrace();
				throw new ITMException(d);
			}
		}
		return "";
	}


	public String itemChanged(Document dom, Document dom1, Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException, ITMException
	{
		BaseLogger.log("3", getUserInfo(), null,"Inside itemchanged method 111111");
		String ls_site_code="", ls_site_desc="", ls_aloc_cd="", ls_loc_descr="", colname ="" ,ls_item_descr=""  ;
		String ls_asset_code="", ls_asset_descr="", ls_emp_code="", ls_fname="", ls_lname="",ls_item_code ="" ;
		double ld_curr_code=0, ld_exch_rate=0, ld_exch_rate__inst=0, ld_chgs__bc=0, ld_original_value__bc=0 ;    
		int li_install_chgs=0, li_original_value=0;
		String ls_work_order = "";

		String  ls_item_desc="", ls_aloc_code=""  ;
		String  ls_lot_no="", ls_lot_sl="", ls_item_ser="",  ls_tran_id="", ls_loc_code="";
		String  ls_descr="", ls_tran_id__rcp="", ls_grp_code="", ls_grp_desc="", ls_supp_code="", ls_supp_name=""   ;
		String  modstr="", ls_var_value="", ld_excise_amt=""   ;
		double ld_quantity=0, ld_rate=0, ld_tax_amt=0, ld_net_amt=0;
		int li_line_no_rcp=0, li_quantity=0, li_line_no=0;
		long li_line=0;
		Timestamp mtoday;
		String msite="",ls_login_site ="";
		String ls_workorder = "";
		mtoday = new Timestamp(System.currentTimeMillis());
		colname = currentColumn.toLowerCase();
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String sql = null;
		int currFormNo = 0;
		Timestamp ldDate = null;
		try
		{
			SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
			ldDate = new Timestamp(sdf.parse(sdf.format(new Date())).getTime());
			if(objContext != null && objContext.trim().length() > 0)
			{
				currFormNo = Integer.parseInt(objContext);
			}

			switch(currFormNo)
			{
			case 1:
			{
				switch(colname)
				{
				case "itm_defaultedit":
				{
					ls_workorder = getItemString(dom, 1, "work_order");
					if(ls_workorder != null && ls_workorder.trim().length() > 0)
					{
						gbfItemchgModifierDs(dom, "item_code", "protect", "1");
					}
					else
					{
						gbfItemchgModifierDs(dom, "item_code", "protect", "0");
					}
					break;
				}
				case "itm_default":
				{
					ls_login_site = getValueFromXTRA_PARAMS(xtraParams, "loginSiteCode");
					System.out.println("Khushal77777" +ls_login_site );
					setItem(dom, 1, "site_code", ls_login_site);
					sql = " SELECT descr FROM site WHERE site_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_login_site);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						msite = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}

					setItem(dom, 1, "site_descr", msite);
					setItem(dom, 1, "tran_date",ldDate);
					break;
				}
				case "site_code":
				{
					ls_site_code = getItemString(dom, 1, "site_code");
					sql = " SELECT site.descr FROM site WHERE site.site_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_site_code);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						ls_site_desc = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}
					setItem(dom, 1, "site_descr", ls_site_desc);
					break;
				}
				case "item_code":
				{
					ls_item_code = getItemString(dom, 1, "item_code");
					sql = " SELECT item.descr FROM item WHERE item.item_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_item_code);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						ls_item_descr = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}
					setItem(dom, 1, "item_descr", ls_item_descr);
					break;
				}
				case "work_order":
				{
					ls_work_order = getItemString(dom, 1, "work_order");
					if (ls_work_order != null && ls_work_order.trim().length() > 0)
					{
						sql = " SELECT item_code FROM workorder WHERE work_order = ?";
						pstmt = conn.prepareStatement(sql);
						pstmt.setString(1, ls_work_order);
						rs = pstmt.executeQuery();
						if (rs.next()) {
							ls_item_code = rs.getString("item_code");
						}
						if (pstmt != null) {
							pstmt.close();
							pstmt = null;
						}
						if (rs != null) {
							rs.close();
							rs = null;
						}
						setItem(dom, 1, "item_code", ls_item_code);
						gbfItemchgModifierDs(dom, "item_code", "protect", "1");
					}
					else
					{
						gbfItemchgModifierDs(dom, "item_code", "protect", "0");
					}
					break;
				}
				}
				break;
			}
			case 2:
			{
				switch(colname)
				{
				case "itm_default":
				{
					String li_lineStr = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"line_no");
					if(li_lineStr != null && li_lineStr.trim().length() > 0)
					{
						li_line = Long.parseLong(li_lineStr);

					}
					else
					{
						li_line=0;	
					}
					BaseLogger.log("3", getUserInfo(), null,"Line No:::" +li_line);
					if(li_line > 0)
					{
						setItem(dom, 1, "line_no", String.valueOf(li_line));
					}
					setItem(dom, 1, "tran_id", getItemString(dom1, 1, "tran_id"));
					setItem(dom, 1, "site_code", getItemString(dom1, 1, "site_code"));
					setItem(dom, 1, "site_descr", getItemString(dom1, 1, "site_descr"));
					gbfItemchgModifierDs(dom, "line_no", "protect", "1");
					break;
				}
				case "item_code":
				{
					ls_item_code = getItemString(dom, 1, "item_code");
					sql = " SELECT item.descr FROM item WHERE item.item_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_item_code);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						ls_item_desc = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}
					setItem(dom, 1, "item_descr", ls_item_desc);
					break;
				}
				case "site_code":
				{
					ls_site_code = getItemString(dom, 1, "site_code");
					sql = " SELECT site.descr FROM site WHERE site.site_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_site_code);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						ls_site_desc = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}
					setItem(dom, 1, "site_descr", ls_site_desc);
					break;
				}
				case "loc_code":
				{
					ls_loc_code = getItemString(dom1, 1, "loc_code");
					sql = " SELECT location.descr FROM location WHERE location.loc_code = ?";
					pstmt = conn.prepareStatement(sql);
					pstmt.setString(1, ls_loc_code);
					rs = pstmt.executeQuery();
					if (rs.next()) {
						ls_loc_descr = rs.getString("descr");
					}
					if (pstmt != null) {
						pstmt.close();
						pstmt = null;
					}
					if (rs != null) {
						rs.close();
						rs = null;
					}
					setItem(dom, 1, "location_descr", ls_loc_descr);
					break;
				}
				}
				break;
			}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
			throw new ITMException(e);
		}
		finally
		{
			try
			{
				if (rs != null)
				{
					rs.close();
					rs = null;
				}
				if (pstmt != null)
				{
					pstmt.close();
					pstmt = null;
				}
			}
			catch (Exception e)
			{
				e.printStackTrace();
				throw new ITMException(e);
			}
		}
		return "";
	}

}