Commit 2632c2ba authored by kmandhre's avatar kmandhre

System should allow to transfer material from one location to another location...

System should allow to transfer material from one location to another location if stock is not consumed even though allocated. DI3GSUN019


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@93847 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1bf4ef94
/** /**
* PURPOSE : Confirmation of Stock transfer transaction * PURPOSE : Confirmation of Stock transfer transaction
* AUTHOR : Gulzar on 13/09/11 * AUTHOR : Gulzar on 13/09/11
*/ */
package ibase.webitm.ejb.dis.adv; package ibase.webitm.ejb.dis.adv;
import ibase.webitm.utility.*; import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.*; import ibase.utility.CommonConstants;
import ibase.webitm.ejb.dis.*; import ibase.webitm.ejb.ActionHandlerEJB;
import ibase.webitm.ejb.fin.FinCommon; import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.sys.*; import ibase.webitm.ejb.dis.DistCommon;
import ibase.webitm.ejb.dis.InvAllocTraceBean;
import ibase.webitm.ejb.dis.StockUpdate;
import ibase.webitm.ejb.fin.InvAcct; import ibase.webitm.ejb.fin.InvAcct;
import ibase.system.config.*; import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException; import ibase.webitm.utility.ITMException;
//Changed by Rohan on 17-07-13 for import package import ibase.webitm.utility.TransIDGenerator;
import ibase.utility.CommonConstants;
import java.io.*;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.*; import java.sql.Connection;
import java.util.*; import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.text.*; import java.util.HashMap;
import javax.ejb.*;
import javax.naming.InitialContext;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import org.w3c.dom.*;
@Stateless @Stateless
public class StockTransferConf extends ActionHandlerEJB implements StockTransferConfRemote, StockTransferConfLocal public class StockTransferConf extends ActionHandlerEJB implements StockTransferConfRemote, StockTransferConfLocal
...@@ -75,6 +78,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -75,6 +78,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
String cctrCodeCr = ""; String cctrCodeCr = "";
//Chnaged by Rohan on 18-07-13 for define variables //Chnaged by Rohan on 18-07-13 for define variables
String lockCode = ""; String lockCode = "";
String lotNoTo = "";
String sql = ""; String sql = "";
String updateSql = ""; String updateSql = "";
...@@ -127,8 +131,10 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -127,8 +131,10 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
boolean isError = false; boolean isError = false;
ArrayList errList = null;
HashMap updateRowMap = null; HashMap updateRowMap = null;
HashMap strAllocate = null; HashMap strAllocate = null;
HashMap stockMap = null;//added by kunal on 25/OCT/13
StockUpdate stkUpdate = null; StockUpdate stkUpdate = null;
InvAcct invAct=null; InvAcct invAct=null;
...@@ -171,6 +177,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -171,6 +177,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
java.sql.Timestamp tranDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString( currDateStr , applDateFormat, dbDateFormat ) + " 00:00:00.0") ; java.sql.Timestamp tranDate = java.sql.Timestamp.valueOf(genericUtility.getValidDateString( currDateStr , applDateFormat, dbDateFormat ) + " 00:00:00.0") ;
updateRowMap = new HashMap(); updateRowMap = new HashMap();
stockMap = new HashMap();
stkUpdate = new StockUpdate(); stkUpdate = new StockUpdate();
sql = "SELECT CONFIRMED, SITE_CODE FROM STOCK_TRANSFER WHERE TRAN_ID = ?"; sql = "SELECT CONFIRMED, SITE_CODE FROM STOCK_TRANSFER WHERE TRAN_ID = ?";
...@@ -196,7 +203,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -196,7 +203,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
nearExpLoc = dComm.getDisparams("999999","NEAREXP_LOC",conn); nearExpLoc = dComm.getDisparams("999999","NEAREXP_LOC",conn);
partialGrlLoc = dComm.getDisparams("999999","PGRL_INVSTAT",conn); partialGrlLoc = dComm.getDisparams("999999","PGRL_INVSTAT",conn);
sql = "SELECT LINE_NO, ITEM_CODE, QUANTITY, LOC_CODE__FR, LOC_CODE__TO, LOT_NO__FR, LOT_SL__FR, LOT_SL__TO, ACCT_CODE__CR, CCTR_CODE__CR, NO_ART " + sql = "SELECT LINE_NO, ITEM_CODE, QUANTITY, LOC_CODE__FR, LOC_CODE__TO, LOT_NO__FR, LOT_SL__FR, LOT_SL__TO, ACCT_CODE__CR, CCTR_CODE__CR, NO_ART ,LOT_NO__TO " +
"FROM STOCK_TRANSFER_DET WHERE TRAN_ID = ? "; "FROM STOCK_TRANSFER_DET WHERE TRAN_ID = ? ";
pstmt = conn.prepareStatement(sql); pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId); pstmt.setString(1, tranId);
...@@ -229,6 +236,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -229,6 +236,7 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
lotNo = rs.getString( "LOT_NO__FR" ); lotNo = rs.getString( "LOT_NO__FR" );
lotSl = rs.getString( "LOT_SL__FR" ); lotSl = rs.getString( "LOT_SL__FR" );
lotSlTo = rs.getString( "LOT_SL__TO" ); lotSlTo = rs.getString( "LOT_SL__TO" );
lotNoTo = rs.getString( "LOT_NO__TO" );//added by kunal on 14/oct/13
noArt = rs.getDouble( "NO_ART" ); noArt = rs.getDouble( "NO_ART" );
acctCodeCr = rs.getString( "ACCT_CODE__CR" ); acctCodeCr = rs.getString( "ACCT_CODE__CR" );
cctrCodeCr = rs.getString( "CCTR_CODE__CR" ); cctrCodeCr = rs.getString( "CCTR_CODE__CR" );
...@@ -387,6 +395,77 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -387,6 +395,77 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
// end 16/10/11 manoharan hold_qty added // end 16/10/11 manoharan hold_qty added
//Changed by Rohan on 19-08-13 for getting atual rate //Changed by Rohan on 19-08-13 for getting atual rate
actualRate = rsStock.getDouble("actual_rate"); actualRate = rsStock.getDouble("actual_rate");
//added by kunal on 25/oct/13
stockMap.put("item_code", itemCode);
stockMap.put("site_code", siteCode);
stockMap.put("loc_code", locCodeFr);
stockMap.put("lot_no", lotNo);
stockMap.put("lot_sl", lotSl);
stockMap.put("quantity", ""+quantity);
if(invStatLocCodeTo.trim().equalsIgnoreCase(locCodeTo.trim()) && invStatLocCodeTo.trim().equalsIgnoreCase(partialGrlLoc.trim()))
{
stockMap.put("no_art", quantity);
}
else
{
stockMap.put("no_art", noArt);
}
stockMap.put("tran_ser", "XFRX");
stockMap.put("acct_code__cr",acctCodeCr);
stockMap.put("cctr_code__cr",cctrCodeCr);
stockMap.put("acct_code_inv",acctCodeCr);
stockMap.put("cctr_code_inv",cctrCodeCr);
stockMap.put("rate",Double.toString(stkRate));
stockMap.put("gross_rate",Double.toString(stkGrossRate));
System.out.println("stkGrossRate:::"+Double.toString(stkRate)+"stkRate::::"+Double.toString(stkGrossRate));
stockMap.put("tran_id", tranId );
stockMap.put("tran_date", tranDate );
//updateRowMap.put("tran_type","ID");
stockMap.put("qty_stduom", ""+quantity);
stockMap.put("unit",unit);
stockMap.put("grade",grade);
stockMap.put("remarks",remarks);
stockMap.put("dimension",dimension);
stockMap.put("tran_type", "I");
//updateRowMap.put("tran_type", "I");
stockMap.put("exp_date", expDate);
stockMap.put("pack_code", packCode);
stockMap.put("mfg_date", mfgDate);
stockMap.put("site_code__mfg", siteCodeMfg);
stockMap.put("pack_instr", packInstr);
stockMap.put("supp_code__mfg", suppCodeMfg);
stockMap.put("retest_date", restestDate);
stockMap.put("conv__qty_stduom", ""+convQtyStduom);
stockMap.put("unit__alt", unitAlt);
stockMap.put("batch_no", batchNo);
stockMap.put("batch_size", ""+batchSize);
stockMap.put("actual_rate", actualRate);
errList = allocTransfer(siteCode,itemCode,locCodeFr ,lotNo,lotSl,locCodeTo ,lotNoTo,lotSlTo, quantity,stockMap, xtraParams , conn );
System.out.println("from alloc transfer=="+errList.toString());
retString = errList.get(0).toString() ;
System.out.println("FROM allocTransfer 0 : "+retString);
if ( retString != null && retString.trim().length() > 0 )
{
isError = true;
break;
}
stockMap.clear();
quantity = Double.parseDouble( errList.get(1).toString() );
System.out.println("pending quantity FROM allocTransfer "+quantity);
if(quantity <= 0)
{
continue;
}
//added by kunal on 25/oct/13 end
} }
rsStock.close(); rsStock = null; rsStock.close(); rsStock = null;
pstmtStock.clearParameters(); pstmtStock.clearParameters();
...@@ -1022,4 +1101,1348 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer ...@@ -1022,4 +1101,1348 @@ public class StockTransferConf extends ActionHandlerEJB implements StockTransfer
return tranId; return tranId;
}//generateTranTd() }//generateTranTd()
//Changed by Rohan on 17-07-13 for generating tran id for INV_HOLD_REL_TRACE.end //Changed by Rohan on 17-07-13 for generating tran id for INV_HOLD_REL_TRACE.end
//addede by kunal on 25/oct/13
private ArrayList allocTransfer(String siteCode,String itemCode,String locCodeFr ,String lotNoFr,String lotSlFr,String locCodeTo ,String lotNoTo,String lotSlTo,double quantitydet,HashMap stockMap,String xtraParams ,Connection conn ) throws ITMException
{
String errString = "";
String sql = "";
String refSer = "", refId = "" ,tranId = "",workorder = "";
//double pendingQty = 0 ;
int refLine = 0,count = 0,k = 0 ,lineNo = 0 , maxLine = 0;
double quantity = 0 , refQty = 0 ,stockAllocQty = 0 ,invAllocQty = 0,stockQty = 0 ,pendingQty = 0 ;
double splitQty = 0, rate = 0;
boolean checkWOIssue = false;
PreparedStatement pstmt = null ,pstmt1 = null,pstmt2 = null;
ResultSet rs = null,rs1 = null,rs2 = null;
InvAllocTraceBean invAllocTrace = null;
StockUpdate stkUpdate = null;
ArrayList retValue = new ArrayList();
HashMap hashMap = null;
HashMap tempMap = null ;
try
{
System.out.println("allocTransfer called........");
invAllocTrace = new InvAllocTraceBean();
stkUpdate = new StockUpdate();
pendingQty = quantitydet ;
tempMap = stockMap;
sql = "select alloc_qty from stock where site_code = ? and loc_code = ? and item_code = ? "
+" and lot_no = ? and lot_sl = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, locCodeFr);
pstmt.setString(3, itemCode);
pstmt.setString(4, lotNoFr);
pstmt.setString(5, lotSlFr);
rs = pstmt.executeQuery();
if(rs.next())
{
stockAllocQty = rs.getDouble("alloc_qty");
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
sql = " select sum(a.qty) from "
+" (select ref_ser,ref_id ,trim(ref_line), sum(alloc_qty) as qty from invalloc_trace where site_code = ? and loc_code = ? and item_code = ? "
+" and lot_no = ? and lot_sl = ? group by ref_ser, ref_id, trim(ref_line) having sum(alloc_qty) > 0 order by sum(alloc_qty) ) a ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setString(2, locCodeFr);
pstmt.setString(3, itemCode);
pstmt.setString(4, lotNoFr);
pstmt.setString(5, lotSlFr);
rs = pstmt.executeQuery();
if(rs.next())
{
invAllocQty = rs.getDouble(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("invAllocQty="+invAllocQty+" stockAllocQty="+stockAllocQty);
if(invAllocQty < stockAllocQty) //check stock allocate qty and invalloc_trace qty
{
checkWOIssue = true;
}
sql = "select ref_ser,ref_id ,trim(ref_line) as ref_line, sum(alloc_qty) from invalloc_trace where "
+" site_code = ? and loc_code = ? and item_code = ? and lot_no = ? and lot_sl = ? "
+" group by ref_ser, ref_id ,trim( ref_line) having sum(alloc_qty) > 0 order by sum(alloc_qty) desc ";
pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1, siteCode);
pstmt.setString(2, locCodeFr);
pstmt.setString(3, itemCode);
pstmt.setString(4, lotNoFr);
pstmt.setString(5, lotSlFr);
rs = pstmt.executeQuery();
while(rs.next())
{
refSer = checkNull(rs.getString( "ref_ser" )) ;
refId = checkNull(rs.getString( "ref_id" ));
//refLine = rs.getInt("ref_line");
refLine = Integer.parseInt( checkNull(rs.getString("ref_line")).trim().length() == 0 ?"0":rs.getString("ref_line").trim()) ;
refQty = rs.getDouble(4);
System.out.println("pendingQty="+pendingQty);
System.out.println("refSer="+refSer);
System.out.println("refId="+refId);
System.out.println("refLine="+refLine);
System.out.println("refQty="+refQty);
if(pendingQty <= 0)
{
break;
}
if(pendingQty <= refQty)
{
quantity = pendingQty;
pendingQty = 0;
}
else
{
quantity = refQty;
pendingQty = pendingQty - refQty ;
}
stockQty = stockQty + quantity;
hashMap = new HashMap();
hashMap.put("tran_date",new java.sql.Date(System.currentTimeMillis()));
hashMap.put("ref_ser",refSer);
hashMap.put("ref_id",refId);
hashMap.put("ref_line",String.valueOf(refLine));
hashMap.put("site_code",siteCode);
hashMap.put("item_code",itemCode);
hashMap.put("loc_code",locCodeFr);
hashMap.put("lot_no",lotNoFr);
hashMap.put("lot_sl",lotSlFr);
hashMap.put("alloc_qty",new Double(-1*quantity));
hashMap.put("chg_user",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"loginCode"));
hashMap.put("chg_term",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"termId"));
errString = invAllocTrace.updateInvallocTrace(hashMap, conn);
System.out.println("updateInvallocTrace 1....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
}//end rs loop
System.out.println("Stock Qty="+stockQty+" pendingQty="+pendingQty);
if (stockQty > 0 && ( errString == null || errString.trim().length() == 0))
{
stockMap.put("quantity", ""+stockQty);
stockMap.put("qty_stduom", ""+stockQty);
//stock update for tran type = "I"
errString = stkUpdate.updateStock( stockMap, xtraParams, conn ); //updateStock called only once's
System.out.println("stock update FOR I ....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
else
{
stockMap = tempMap;
stockMap.put("loc_code", locCodeTo);
stockMap.put("lot_no", lotNoTo);
stockMap.put("lot_sl", lotSlTo);
stockMap.put("tran_type", "R");
//stock update for tran type = "R"
errString = stkUpdate.updateStock( stockMap, xtraParams, conn );
System.out.println("stock update FOR R ....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
}
if ( errString == null || errString.trim().length() == 0)
{
if(rs != null)
{
rs.first();
System.out.println("iterate rs for deallcation ");
pendingQty = quantitydet;
do //iterate rs for deallcation
{
splitQty = 0;
refSer = checkNull(rs.getString( "ref_ser" )) ;
refId = checkNull(rs.getString( "ref_id" ));
//refLine = rs.getInt("ref_line");
refLine = Integer.parseInt( checkNull(rs.getString("ref_line")).trim().length() == 0 ?"0":rs.getString("ref_line").trim()) ;
refQty = rs.getDouble(4);
System.out.println("quantitydet="+pendingQty);
System.out.println("refSer="+refSer);
System.out.println("refId="+refId);
System.out.println("refLine="+refLine);
System.out.println("refQty="+refQty);
if(pendingQty <= 0)
{
break;
}
if(pendingQty <= refQty)
{
quantity = pendingQty;
pendingQty = 0;
splitQty = refQty - quantity;
}
else
{
quantity = refQty;
pendingQty = pendingQty - refQty ;
}
hashMap = new HashMap();
hashMap.put("tran_date",new java.sql.Date(System.currentTimeMillis()));
hashMap.put("ref_ser",refSer);
hashMap.put("ref_id",refId);
hashMap.put("ref_line",String.valueOf(refLine));
hashMap.put("site_code",siteCode);
hashMap.put("item_code",itemCode);
hashMap.put("loc_code",locCodeTo);
hashMap.put("lot_no",lotNoTo);
hashMap.put("lot_sl",lotSlTo);
hashMap.put("alloc_qty",new Double(quantity));
hashMap.put("chg_user",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"loginCode"));
hashMap.put("chg_term",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"termId"));
errString = invAllocTrace.updateInvallocTrace(hashMap, conn);
System.out.println("updateInvallocTrace 2....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
else
{
System.out.println("DeAlloc updateInvallocTrace(HashMap, Connection) : Sucessuful!");
System.out.println("refSer:::::"+refSer);
if("S-ORD".equalsIgnoreCase(refSer.trim())) //sale order
{
System.out.println("update for sale order");
maxLine = 0;
System.out.println("update... "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = "update sord_alloc_det set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ? where sale_order = ? and line_no__sord = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setString(5,refId);
pstmt1.setInt(6,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sord_alloc_det ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from sord_alloc_det where sale_order = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into sord_alloc_det (tran_id,line_no,sale_order,line_no__sord,item_code,loc_code,lot_no,lot_sl,quantity,"
+" dealloc_qty,site_code,exp_lev,pending_qty,wave_flag) "
+" select tran_id,"+maxLine+",sale_order,line_no__sord,item_code,'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"',"+quantity+",dealloc_qty,"
+" site_code,exp_lev,pending_qty,wave_flag from sord_alloc_det where sale_order = ? and line_no__sord = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted sord_alloc_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = "update sord_alloc_det set loc_code = ? ,lot_no = ? ,lot_sl = ? where sale_order = ? and line_no__sord = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sord_alloc_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("D-ISS".equalsIgnoreCase(refSer.trim())) //1.Distribution Issue (DISS)
{
System.out.println("update for Distribution Issue (DISS)");
rate = 0;
maxLine = 0;
sql = " select rate from distord_issdet where tran_id = ? and line_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("update.. "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update distord_issdet set loc_code = ? ,lot_no = ? ,lot_sl = ? , quantity = ?,amount = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,splitQty*rate);
pstmt1.setString(6,refId);
pstmt1.setInt(7,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated distord_issdet ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from distord_issdet where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into distord_issdet (tran_id,line_no,dist_order,line_no_dist_order,item_code,quantity,unit,tax_class,tax_chap,tax_env,loc_code,lot_no,lot_sl,"
+" pack_code,rate,amount,tax_amt,net_amt,site_code__mfg,mfg_date,exp_date,potency_perc,no_art,gross_weight,tare_weight,net_weight,pack_instr,dimension,"
+" supp_code__mfg,batch_no,grade,retest_date,rate_clg,rate__clg,discount,disc_amt,remarks,cost_rate,unit__alt,conv__qty__alt,qty_order__alt,pallet_wt,"
+" rate__alt,conv__rate_alt,return_qty,return_date,returned,batch_size,carton_no,pallet_no) "
+" select tran_id,"+maxLine+",dist_order,line_no_dist_order,item_code,"+quantity+",unit,tax_class,tax_chap,tax_env,'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"',"
+" pack_code,rate,15*2,tax_amt,net_amt,site_code__mfg,mfg_date,exp_date,potency_perc,no_art,gross_weight,tare_weight,net_weight,"
+" pack_instr,dimension,supp_code__mfg,batch_no,grade,retest_date,rate_clg,rate__clg,discount,disc_amt,remarks,cost_rate,unit__alt,"
+" conv__qty__alt,qty_order__alt,pallet_wt,rate__alt,conv__rate_alt,return_qty,return_date,returned,batch_size,carton_no,pallet_no from distord_issdet where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted distord_issdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update distord_issdet set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated distord_issdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("S-DSP".equalsIgnoreCase(refSer.trim())) //Despatch
{
System.out.println("update for Despatch");
maxLine = 0;
System.out.println("update... "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update despatchdet set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ?,quantity__ord = ?,quantity__stduom = ? where desp_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,splitQty);
pstmt1.setDouble(6,splitQty);
pstmt1.setString(7,refId);
pstmt1.setInt(8,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated despatchdet ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max( line_no) from despatchdet where desp_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into despatchdet (desp_id,line_no,sord_no,line_no__sord,exp_lev,item_code__ord,item_code,lot_no,lot_sl,quantity__ord,quantity,loc_code,status,conv__qty_stduom,"
+" unit__std,unit,quantity__stduom,quantity_real,rate__stduom,invoice_id,quantity_inv,pack_instr,no_art,site_code,pack_qty,gross_weight,tare_weight,nett_weight,mfg_date,exp_date,"
+" chg_date,chg_user,chg_term,site_code__mfg,rate__clg,dimension,tax_amt,disc_amt,conf_diff_amt,rate__std,cost_rate,frequency,down_payment,down_payment_int,inst_amount,inst_int_amount,"
+" no_of_inst,line_type,conv__rtuom_stduom,pallet_wt,cust_item__ref,tran_id__invpack,retest_date,part_no,disc_schem_billback_amt,disc_schem_offinv_amt,sscc_18,pack_code,pallet_no) "
+" select desp_id,"+maxLine+",sord_no,line_no__sord,exp_lev,item_code__ord,item_code,'"+lotNoTo+"','"+lotSlTo+"',"+quantity+","+quantity+",'"+locCodeTo+"',status,conv__qty_stduom,unit__std,unit,"+quantity+",quantity_real,rate__stduom,"
+" invoice_id,quantity_inv,pack_instr,no_art,site_code,pack_qty,gross_weight,tare_weight,nett_weight,mfg_date,exp_date,chg_date,chg_user,chg_term,site_code__mfg,rate__clg,dimension,"
+" tax_amt,disc_amt,conf_diff_amt,rate__std,cost_rate,frequency,down_payment,down_payment_int,inst_amount,inst_int_amount,no_of_inst,line_type,conv__rtuom_stduom,pallet_wt,cust_item__ref,"
+" tran_id__invpack,retest_date,part_no,disc_schem_billback_amt,disc_schem_offinv_amt,sscc_18,pack_code,pallet_no "
+" from despatchdet where desp_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted despatchdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update despatchdet set loc_code = ? ,lot_no = ? ,lot_sl = ? where desp_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated despatchdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("XFRX".equalsIgnoreCase(refSer.trim())) // Stock Transfer Multiple
{
System.out.println("update for Stock Transfer Multiple");
maxLine = 0;
System.out.println("update... "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update stock_transfer_det set loc_code__to = ? ,lot_no__to = ? , lot_sl__to = ? ,quantity = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setString(5,refId);
pstmt1.setInt(6,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated stock_transfer_det ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from stock_transfer_det where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into stock_transfer_det (tran_id,line_no,item_code,quantity,loc_code__fr,loc_code__to,lot_no__fr,lot_no__to,lot_sl__fr,lot_sl__to,"
+" remarks,acct_code__cr,acct_code__dr,cctr_code__dr,cctr_code__cr,no_art,loc_code__sys) "
+" select tran_id,"+maxLine+",item_code,"+quantity+",'"+locCodeTo+"',loc_code__to,'"+lotNoTo+"',lot_no__to,'"+lotSlTo+"',lot_sl__to, "
+" remarks,acct_code__cr,acct_code__dr,cctr_code__dr,cctr_code__cr,no_art,loc_code__sys from stock_transfer_det where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted stock_transfer_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update stock_transfer_det set loc_code__to = ? ,lot_no__to = ? , lot_sl__to = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated stock_transfer_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("C-ISS".equalsIgnoreCase(refSer.trim())) // Consumption Issue(CISS).
{
System.out.println("update for Consumption Issue");
maxLine = 0;
rate = 0;
sql = " select rate from consume_iss_det where cons_issue = ? and line_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("update... "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update consume_iss_det set loc_code = ?,lot_no = ?,lot_sl = ? ,quantity = ? ,quantity__std = ? ,amount = ? where cons_issue = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,splitQty);
pstmt1.setDouble(6,splitQty*rate);
pstmt1.setString(7,refId);
pstmt1.setInt(8,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated consume_iss_det ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max( line_no) from consume_iss_det where cons_issue = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into consume_iss_det (cons_issue,line_no,cons_order,line_no__ord,item_code,quantity,unit,rate,amount,tax_class,tax_chap,tax_env,tax_amt,net_amt,"
+" acct_code,cctr_code,loc_code,lot_no,lot_sl,quantity__std,unit__std,conv_qty_stduom,qc_reqd,acct_code__inv,cctr_code__inv,no_art,anal_code,carton_no,pallet_no) "
+" select cons_issue,"+maxLine+",cons_order,line_no__ord,item_code,"+quantity+",unit,rate,"+rate*quantity+",tax_class,tax_chap,tax_env,tax_amt,net_amt,acct_code,"
+" cctr_code,'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"',"+quantity+",unit__std,conv_qty_stduom,qc_reqd,acct_code__inv,cctr_code__inv,no_art,anal_code,carton_no,pallet_no "
+" from consume_iss_det where CONS_ISSUE = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted consume_iss_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update consume_iss_det set loc_code = ?,lot_no = ?,lot_sl = ? where cons_issue = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated consume_iss_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("ADJISS".equalsIgnoreCase(refSer.trim())) // Adjustment Issue(ADJISS).
{
System.out.println("update for Adjustment Issue");
rate = 0;
maxLine = 0;
sql = " select rate from adj_issrcpdet where tran_id = ? and line_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("1420 "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update adj_issrcpdet set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ? , amount = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,rate * splitQty);
pstmt1.setString(6,refId);
pstmt1.setInt(7,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated adj_issrcpdet ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from adj_issrcpdet where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into adj_issrcpdet (tran_id,line_no,item_code,unit,loc_code,lot_no,lot_sl,quantity,sundry_type,sundry_code,rate,gross_rate,grade,dimension,no_art, "
+" amount,gross_weight,tare_weight,net_weight,acct_code__dr,cctr_code__dr,acct_code__cr,cctr_code__cr,potency_perc,pack_code,mfg_date,exp_date, "
+" site_code__mfg,conv__qty_stduom,unit__alt,conv_qty_stduom,unit_alt,theoretical_wt,retest_date,supp_code__mfg,batch_no) "
+" select tran_id,"+maxLine+",item_code,unit,'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"', "+quantity+", sundry_type,sundry_code,rate,gross_rate,grade,dimension,no_art, "
+ rate * quantity +",gross_weight,tare_weight,net_weight,acct_code__dr,cctr_code__dr,acct_code__cr,cctr_code__cr,potency_perc,pack_code,mfg_date,exp_date, "
+" site_code__mfg,conv__qty_stduom,unit__alt,conv_qty_stduom,unit_alt,theoretical_wt,retest_date,supp_code__mfg,batch_no from adj_issrcpdet "
+" where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted adj_issrcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update adj_issrcpdet set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ? , amount = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setDouble(4,quantity);
pstmt1.setDouble(5,rate * quantity);
pstmt1.setString(6,refId);
pstmt1.setInt(7,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated adj_issrcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("P-RET".equalsIgnoreCase(refSer.trim())) // Purchase Order Return(PRETURN).
{
System.out.println("update for PRETURN");
rate = 0;
maxLine = 0;
sql = " select rate from porcpdet where tran_id = ? and line_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("update.. "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update porcpdet set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ?, quantity__stduom = ?,net_amt = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,splitQty);
pstmt1.setDouble(6,rate * splitQty);
pstmt1.setString(7,refId);
pstmt1.setInt(8,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated porcpdet ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from porcpdet where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into porcpdet (tran_id,line_no,item_code,purc_order,quantity,unit,rate,discount,tax_amt,net_amt,loc_code,lot_no,lot_sl,line_no__ord,"
+" canc_bo,vouch_qty,acct_code__dr,cctr_code__dr,acct_code__cr,cctr_code__cr,unit__rate,conv__qty_stduom,conv__rtuom_stduom,unit__std,"
+" quantity__stduom,rate__stduom,pack_code,no_art,pack_instr,batch_no,mfg_date,expiry_date,gross_weight,tare_weight,net_weight,status,"
+" potency_perc,supp_code__mnfr,site_code__mfg,reas_code,remarks,challan_qty,grade,tax_class,tax_chap,tax_env,specific_instr,special_instr,"
+" loc_code__excess_short,excess_short_qty,additional_cost,rate__clg,supp_challan_qty,realised_qty,item_code__mfg,spec_ref,std_rate,dept_code,"
+" effect_stock,physical_status,benefit_type,licence_no,acct_code__prov_dr,cctr_code__prov_dr,acct_code__prov_cr,cctr_code__prov_cr,form_no,"
+" retest_date,duty_paid,batch_size,damage_qty,sample_qty,shelf_life__type,qc_reqd,sh_qty,rejc_qty,assetinstall_qty,part_qty,partial_yn,anal_code,carton_no,pallet_no) "
+" select tran_id,"+maxLine+",item_code,purc_order,"+quantity+",unit,rate,discount,tax_amt,"+quantity*rate+",'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"',line_no__ord,"
+" canc_bo,vouch_qty,acct_code__dr,cctr_code__dr,acct_code__cr,cctr_code__cr,unit__rate,conv__qty_stduom,conv__rtuom_stduom,unit__std, "
+ quantity+",rate__stduom,pack_code,no_art,pack_instr,batch_no,mfg_date,expiry_date,gross_weight,tare_weight,net_weight,status,potency_perc,supp_code__mnfr,"
+" site_code__mfg,reas_code,remarks,challan_qty,grade,tax_class,tax_chap,tax_env,specific_instr,special_instr,loc_code__excess_short,excess_short_qty,"
+" additional_cost,rate__clg,supp_challan_qty,realised_qty,item_code__mfg,spec_ref,std_rate,dept_code,effect_stock,physical_status,benefit_type,licence_no,"
+" acct_code__prov_dr,cctr_code__prov_dr,acct_code__prov_cr,cctr_code__prov_cr,form_no,retest_date,duty_paid,batch_size,damage_qty,sample_qty,shelf_life__type,"
+" qc_reqd,sh_qty,rejc_qty,assetinstall_qty,part_qty,partial_yn,anal_code,carton_no,pallet_no from porcpdet where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted porcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update porcpdet set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated porcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("R-BFS".equalsIgnoreCase(refSer.trim())) // Receipt Back Flush
{
System.out.println("update for Receipt Back Flush");
rate = 0;
maxLine = 0;
sql = " select rate from receipt_backflush_det where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("update.. "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update receipt_backflush_det set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ?,amount = ?,net_amt = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,rate * splitQty);
pstmt1.setDouble(6,rate * splitQty);
pstmt1.setString(7,refId);
pstmt1.setInt(8,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated receipt_backflush_det ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select select max(line_no) from receipt_backflush_det where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into receipt_backflush_det (tran_id,line_no,site_code,loc_code,lot_no,lot_sl,item_code,"
+" ref_no,quantity,rate,amount,tax_amt,discount,net_amt,unit,unit__doc,conv_qty_doc,qty_doc,rate_doc,no_art) "
+" select tran_id,"+maxLine+",site_code,'"+locCodeTo+"','"+lotNoTo+"','"+lotSlTo+"',item_code,ref_no,"+quantity+",rate,"+quantity*rate+",tax_amt,"
+" discount," +quantity*rate+",unit,unit__doc,conv_qty_doc,qty_doc,rate_doc,no_art from receipt_backflush_det where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted receipt_backflush_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update receipt_backflush_det set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated receipt_backflush_det ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("S-RET".equalsIgnoreCase(refSer.trim())) // (Sales Return)SRETURN.
{
System.out.println("update for SRETURN.");
rate = 0;
maxLine = 0;
sql = " select rate from receipt_backflush_det where tran_id = ? and line_no = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
pstmt2.setInt(2, refLine);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
rate = rs2.getDouble("rate");
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
System.out.println("update... "+rate+" "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update sreturndet set loc_code = ? ,lot_no = ? ,lot_sl = ? ,quantity = ?,quantity__stduom = ?,net_amt = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,rate * splitQty);
pstmt1.setDouble(6,rate * splitQty);
pstmt1.setString(7,refId);
pstmt1.setInt(8,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sreturndet ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " select max(line_no) from sreturndet where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, refId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
maxLine = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
maxLine++;
sql = " insert into sreturndet (tran_id,line_no,invoice_id,line_no__inv,item_code,quantity,net_amt,status,"
+" reas_code,loc_code,stk_opt,rate,lot_no,lot_sl,tax_class,tax_chap,tax_env,unit,chg_date,chg_user,chg_term,"
+" ret_rep_flag,eff_net_amt,conv__qty_stduom,conv__rtuom_stduom,unit__std,quantity__stduom,rate__stduom,exp_date,discount,tax_amt,"
+" site_code__mfg,mfg_date,unit__rate,pack_code,full_ret,item_ser,reas_code__org,no_art,rate__clg,rate__stk,cost_rate,"
+" expiry_deduction,rate__std,claim_qty,physical_qty,rate_std,qc_reqd,line_no__invtrace,mrp_value,sale_order,physical_status,line_type,"
+" invoice_id__club,part_qty,cust_item__ref,gross_weight,tare_weight,net_weight,cust_item__code,sord_line_no,contract_no,line_no__sform) "
+" select tran_id,"+maxLine+",invoice_id,line_no__inv,item_code,"+quantity+","+quantity * rate+",status,reas_code,'"+locCodeTo+"',stk_opt,"
+" rate,'"+lotNoTo+"','"+lotSlTo+"',tax_class,tax_chap,tax_env,unit,chg_date,chg_user,chg_term,ret_rep_flag,eff_net_amt,conv__qty_stduom,"
+" conv__rtuom_stduom,unit__std,"+quantity+",rate__stduom,exp_date,discount,tax_amt,site_code__mfg,mfg_date,unit__rate,pack_code,full_ret,"
+" item_ser,reas_code__org,no_art,rate__clg,rate__stk,cost_rate,expiry_deduction,rate__std,claim_qty,physical_qty,rate_std,qc_reqd,"
+" line_no__invtrace,mrp_value,sale_order,physical_status,line_type,invoice_id__club,part_qty,cust_item__ref,gross_weight,tare_weight,"
+" net_weight,cust_item__code,sord_line_no,contract_no,line_no__sform from sreturndet where tran_id = ? and line_no = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted adj_issrcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update sreturndet set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sreturndet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else if("W-ISS".equalsIgnoreCase(refSer.trim())) // Work order ISS .
{
sql = " update workorder_issdet set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated workorder_issdet ="+k);
pstmt1.close();
pstmt1 = null;
}
else if("S-ALC".equalsIgnoreCase(refSer.trim())) // Manual Sorder Allocation
{
System.out.println("update for Manual Sorder Allocation");
System.out.println("update.. "+quantity+" "+splitQty);
if(splitQty > 0)//insert new record for split quantity
{
sql = " update sordalloc set loc_code = ? ,lot_no = ? ,lot_sl = ? , quantity = ?,quantity__stduom = ? where sale_order = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeFr);
pstmt1.setString(2,lotNoFr);
pstmt1.setString(3,lotSlFr);
pstmt1.setDouble(4,splitQty);
pstmt1.setDouble(5,splitQty);
pstmt1.setString(6,refId);
pstmt1.setInt(7,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sordalloc ="+k);
pstmt1.close();
pstmt1 = null;
if(k > 0)
{
sql = " insert into sordalloc (sale_order,line_no,exp_lev,item_code__ord,item_code,lot_no,lot_sl,loc_code,item_ref,quantity,unit,qty_alloc,"
+" date_alloc,status,item_grade,exp_date,alloc_mode,site_code,conv__qty_stduom,unit__std,quantity__stduom,mfg_date,site_code__mfg,reas_code,ref_id__alloc,ref_line__no,wave_flag) "
+" select sale_order,line_no,exp_lev,item_code__ord,item_code,'"+lotNoTo+"','"+lotSlTo+"','"+locCodeTo+"',item_ref,"+quantity+",unit,qty_alloc,date_alloc,"
+" status,item_grade,exp_date,alloc_mode,site_code,conv__qty_stduom,unit__std,"+quantity+",mfg_date,site_code__mfg,reas_code,"
+" ref_id__alloc,ref_line__no,wave_flag from sordalloc where SALE_ORDER = ? and LINE_NO = ? "
+" and site_code = ? and loc_code = ? and item_code = ? and lot_no = ? and lot_sl = ? ";
System.out.println("insert qry="+sql);
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,refId);
pstmt1.setInt(2,refLine);
pstmt1.setString(3,siteCode);
pstmt1.setString(4,locCodeFr);
pstmt1.setString(5,itemCode);
pstmt1.setString(6,lotNoFr);
pstmt1.setString(7,lotSlFr);
k = pstmt1.executeUpdate();
System.out.println("No of row inserted adj_issrcpdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}
else
{
sql = " update sordalloc set loc_code = ? ,lot_no = ? ,lot_sl = ? where sale_order = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated sordalloc ="+k);
pstmt1.close();
pstmt1 = null;
}
}
}
}while(rs.next());
//end rs loop
}
}
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
System.out.println("after invtracealloc check .. pendingQty =="+pendingQty+" quantitydet="+quantitydet);
quantitydet = pendingQty;
if(pendingQty > 0)
{
if(checkWOIssue)//if qty alloc in work order
{
stockQty = 0;
System.out.println("qty alloc in work order ");
sql = " select inv_allocate.work_order ,inv_alloc_det.tran_id, inv_alloc_det.line_no ,inv_alloc_det.alloc_qty from inv_allocate , inv_alloc_det where inv_allocate.tran_id = inv_alloc_det.tran_id "
+" and case when inv_alloc_det.deallocated is null then 'N' else inv_alloc_det.deallocated end != 'Y' "
+" and inv_alloc_det.site_code = ? and inv_alloc_det.loc_code = ? and inv_alloc_det.item_code = ? "
+" and inv_alloc_det.lot_no = ? and inv_alloc_det.lot_sl = ? order by inv_alloc_det.alloc_qty desc " ;
pstmt = conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.setString(1, siteCode);
pstmt.setString(2, locCodeFr);
pstmt.setString(3, itemCode);
pstmt.setString(4, lotNoFr);
pstmt.setString(5, lotSlFr);
rs = pstmt.executeQuery();
while(rs.next())
{
refId = checkNull(rs.getString( "tran_id" ));
//refLine = rs.getInt("ref_line");
refLine = Integer.parseInt( checkNull(rs.getString("line_no")).trim().length() == 0 ?"0":rs.getString("line_no").trim()) ;
refQty = rs.getDouble("alloc_qty");
workorder = rs.getString("work_order");
System.out.println("pendingQty="+pendingQty);
System.out.println("refSer="+refSer);
System.out.println("refId="+refId);
System.out.println("refLine="+refLine);
System.out.println("refQty="+refQty);
if(pendingQty <= 0)
{
break;
}
if(pendingQty <= refQty)
{
quantity = pendingQty;
pendingQty = 0;
}
else
{
quantity = refQty;
pendingQty = pendingQty - refQty ;
}
stockQty = stockQty + quantity;
sql = " select workorder_issdet.tran_id ,workorder_issdet.line_no from workorder_iss , workorder_issdet where workorder_iss.tran_id = workorder_issdet.tran_id "
+" and workorder_iss.work_order = ? and workorder_iss.site_code = ? "
+" and workorder_issdet.loc_code = ? and workorder_issdet.item_code = ? and workorder_issdet.lot_no = ? and workorder_issdet.lot_sl = ? ";
pstmt1 = conn.prepareStatement(sql);
pstmt1.setString(1, workorder);
pstmt1.setString(2, siteCode);
pstmt1.setString(3, locCodeFr);
pstmt1.setString(4, itemCode);
pstmt1.setString(5, lotNoFr);
pstmt1.setString(6, lotSlFr);
rs1 = pstmt1.executeQuery();
while(rs1.next())
{
tranId = rs1.getString("tran_id");
//lineNo = rs1.getInt("line_no");
sql = " select count(*) from workorder_issdet_sl where tran_id = ? ";
pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, tranId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
count = rs2.getInt(1);
}
rs2.close();
rs2 = null;
pstmt2.close();
pstmt2 = null;
if(count > 0) //if weighing is done then give error
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
}
rs1.close();
rs1 = null;
pstmt1.close();
pstmt1 = null;
hashMap = new HashMap();
hashMap.put("tran_date",new java.sql.Date(System.currentTimeMillis()));
hashMap.put("ref_ser","W-ISS");
hashMap.put("ref_id",refId);
hashMap.put("ref_line",String.valueOf(refLine));
hashMap.put("site_code",siteCode);
hashMap.put("item_code",itemCode);
hashMap.put("loc_code",locCodeFr);
hashMap.put("lot_no",lotNoFr);
hashMap.put("lot_sl",lotSlFr);
hashMap.put("alloc_qty",new Double(-1*quantity));
hashMap.put("chg_user",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"loginCode"));
hashMap.put("chg_term",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"termId"));
errString = invAllocTrace.updateInvallocTrace(hashMap, conn);
System.out.println("updateInvallocTrace....."+errString);
if(errString != null && errString.trim().length() > 0)
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
}//rs loop end
System.out.println("Stock Qty="+stockQty+" pendingQty="+pendingQty);
if (stockQty > 0 && ( errString == null || errString.trim().length() == 0))
{
stockMap = tempMap;
stockMap.put("loc_code", locCodeFr);
stockMap.put("lot_no", lotNoFr);
stockMap.put("lot_sl", lotSlFr);
stockMap.put("tran_type", "I");
stockMap.put("quantity", ""+stockQty);
stockMap.put("qty_stduom", ""+stockQty);
//stock update for tran type = "I"
errString = stkUpdate.updateStock( stockMap, xtraParams, conn ); //updateStock called only once's
System.out.println("stock update FOR I ....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
else
{
stockMap.put("loc_code", locCodeTo);
stockMap.put("lot_no", lotNoTo);
stockMap.put("lot_sl", lotSlTo);
stockMap.put("tran_type", "R");
//stock update for tran type = "R"
errString = stkUpdate.updateStock( stockMap, xtraParams, conn ); //updateStock called only once's
System.out.println("stock update FOR R ....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
}
if ( errString == null || errString.trim().length() == 0)
{
if(rs != null)
{
rs.first();
pendingQty = quantitydet;
System.out.println("iterate rs for deallcation ");
do
{
refId = checkNull(rs.getString( "tran_id" ));
//refLine = rs.getInt("ref_line");
refLine = Integer.parseInt( checkNull(rs.getString("line_no")).trim().length() == 0 ?"0":rs.getString("line_no").trim()) ;
refQty = rs.getDouble("alloc_qty");
workorder = rs.getString("work_order");
System.out.println("pendingQty="+pendingQty);
System.out.println("refSer="+refSer);
System.out.println("refId="+refId);
System.out.println("refLine="+refLine);
System.out.println("refQty="+refQty);
if(pendingQty <= 0)
{
break;
}
if(pendingQty <= refQty)
{
quantity = pendingQty;
pendingQty = 0;
}
else
{
quantity = refQty;
pendingQty = pendingQty - refQty ;
}
hashMap = new HashMap();
hashMap.put("tran_date",new java.sql.Date(System.currentTimeMillis()));
hashMap.put("ref_ser",refSer);
hashMap.put("ref_id",refId);
hashMap.put("ref_line",String.valueOf(refLine));
hashMap.put("site_code",siteCode);
hashMap.put("item_code",itemCode);
hashMap.put("loc_code",locCodeTo);
hashMap.put("lot_no",lotNoTo);
hashMap.put("lot_sl",lotSlTo);
hashMap.put("alloc_qty",new Double(quantity));
hashMap.put("chg_user",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"loginCode"));
hashMap.put("chg_term",GenericUtility.getInstance().getValueFromXTRA_PARAMS(xtraParams,"termId"));
errString = invAllocTrace.updateInvallocTrace(hashMap, conn);
System.out.println("updateInvallocTrace 2....."+errString);
if ( errString != null && errString.trim().length() > 0 )
{
retValue.add("Error");
retValue.add(new Double(quantitydet));
return retValue;
}
else
{
sql = " update inv_alloc_det set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id = ? and line_no = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,refId);
pstmt1.setInt(5,refLine);
k = pstmt1.executeUpdate();
System.out.println("No of row updated inv_alloc_det ="+k);
pstmt1.close();
pstmt1 = null;
sql = " update workorder_issdet set loc_code = ? ,lot_no = ? ,lot_sl = ? where tran_id in (select tran_id from workorder_iss where work_order = ? and site_code = ? ) "
+" and loc_code = ? and item_code = ? and lot_no = ? and lot_sl = ? ";
pstmt1 =conn.prepareStatement(sql);
pstmt1.setString(1,locCodeTo);
pstmt1.setString(2,lotNoTo);
pstmt1.setString(3,lotSlTo);
pstmt1.setString(4,workorder);
pstmt1.setString(5,siteCode);
pstmt1.setString(6,locCodeFr);
pstmt1.setString(7,itemCode);
pstmt1.setString(8,locCodeFr);
pstmt1.setString(9,lotSlFr);
k = pstmt1.executeUpdate();
System.out.println("No of row updated workorder_issdet ="+k);
pstmt1.close();
pstmt1 = null;
}
}while(rs.next()); //rs 2nd lopp end
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
}
}
quantitydet = pendingQty;
}//check for work order alloc qty
}//check pending qty
} catch (SQLException e)
{
System.out.println("SQLException :allocDeAlloc :SQLException :==>\n"+e.getMessage());
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
catch (Exception e)
{
System.out.println("Exception :allocDeAlloc : :Exception :==>\n"+e.getMessage());
errString = e.getMessage();
e.printStackTrace();
throw new ITMException(e);
}
System.out.println("Befor Map");
System.out.println("err string::"+errString);
System.out.println("pending qty::"+quantitydet);
System.out.println("Befor Map");
retValue.add(errString);
retValue.add(new Double(quantitydet));
return retValue;
}//end allocTransfer
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment