Commit 87e7b45f authored by ssalve's avatar ssalve

Sarita: Done changes to create method poRcpVouchRetrieve and checkReplRcp on 20 AUG 18

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@189429 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 28f74283
......@@ -11,6 +11,7 @@ import ibase.webitm.ejb.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.Date;
import javax.naming.InitialContext;
import org.w3c.dom.*;
import ibase.utility.UserInfoBean;
......@@ -2594,4 +2595,515 @@ public class CreatePoRcpVoucher
return retString;
}
//Sarita - Migrated Method gbf_porcp_vouch_retrieve[nvo_business_object_dist_voucher] on 10 AUG 18 [START]
public String poRcpVouchRetrieve(String tranId,String xtraParams, Connection conn) throws ITMException
{
String retString = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = "" , loginEmpCode = "",errCode = "",transactionId = "",dbName = "",receiptType = "";
double lcPassed = 0.0 , lcRejected = 0.0 , lcReturned = 0.0 , lcReceived = 0.0;
Timestamp cutrrentDate = null , tranDate = null;
Date today = null;
int count1 = 0, count2 = 0;
String msgString = "";
int rowCount = 0;
try
{
System.out.println("*** Inside poRcpVouchRetrieve Method ****");
today = new java.sql.Timestamp(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getDBDateFormat());
cutrrentDate = java.sql.Timestamp.valueOf(sdf.format(today) + " 00:00:00.000");
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
if(loginEmpCode == null || loginEmpCode.trim().length() == 0)
{
errCode = "EMPAPRV";
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
return retString;
}
sql = "select tran_id , tran_date from porcp where tran_id = ? "
+ "and confirmed = 'Y' "
+ "and (vouch_created = 'N' OR vouch_created = NULL) order by tran_id asc";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,tranId);
rs = pstmt.executeQuery();
if(rs.next())
{
rowCount++;
transactionId = checkNullAndTrim(rs.getString("tran_id"));
tranDate = rs.getTimestamp("tran_date");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("Current Date is :: ["+cutrrentDate+"] && Transaction ID is ["+transactionId+"] \t Transaction Date is ["+tranDate+"]");
if(tranDate != null && tranDate.after(cutrrentDate))
{
errCode = "VTPORCPDT";
retString = itmDBAccessEJB.getErrorString("tran_date",errCode,"","",conn);
return retString;
}
dbName = (CommonConstants.DB_NAME).trim(); System.out.println("dbName--["+dbName+"]");
if(rowCount > 0)
{
if (("db2".equalsIgnoreCase(dbName)) || ("mysql".equalsIgnoreCase(dbName)))
{
sql = "select reciept_type from porcp where tran_id = ? "
+ "and (vouch_created = 'N' OR vouch_created = NULL) "
+ "for update";
}
else if("db2".equalsIgnoreCase(dbName))
{
sql = "select reciept_type from porcp where tran_id = ? "
+ "and (vouch_created = 'N' OR vouch_created = NULL) ";
}
else
{
sql = "select reciept_type from porcp where tran_id = ? "
+ "and (vouch_created = 'N' OR vouch_created = NULL) "
+ "for update nowait";
}
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
rs = pstmt.executeQuery();
if(rs.next())
{
receiptType = checkNullAndTrim(rs.getString("reciept_type"));
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("Receipt Type is ["+receiptType+"]");
if("R".equalsIgnoreCase(receiptType))
{
errCode = "VTREPL";//Invalid Voucher Creation
retString = itmDBAccessEJB.getErrorString("reciept_type",errCode,"","",conn);
return retString;
}
if(retString == null || retString.trim().length() == 0)
{
retString = checkReplRcp(transactionId,conn);
if(retString != null && retString.trim().length() > 0)
{
return retString;
}
}
//Count for no. of item in QC_ORDER Table
sql = "select count(*) as cnt from qc_order where porcp_no = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
rs = pstmt.executeQuery();
if(rs.next())
{
count1 = rs.getInt("cnt");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
//Count for no. of item in QC_ORDER Table for QC Confirmed
sql = "select count(*) as cnt from qc_order where porcp_no = ? and status = ? ";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
pstmt.setString(2, "C");
rs = pstmt.executeQuery();
if(rs.next())
{
count2 = rs.getInt("cnt");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("Count1 is ["+count1+"] \t Count2 is ["+count2+"]");
if(count2 < count1)
{
errCode = "VTQCORDNC";
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
return retString;
}
if(count1 > 0)
{
sql = "select sum((case when qty_passed is null then 0 else qty_passed end ) + (case when qty_sample is null then 0 else qty_sample end )) as lc_passed , "
+ "sum(case when qty_rejected is null then 0 else qty_rejected end ) as lc_rejected "
+ "from qc_order where porcp_no = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
rs = pstmt.executeQuery();
if(rs.next())
{
lcPassed = rs.getDouble("lc_passed");
lcRejected = rs.getDouble("lc_rejected");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
sql = "select sum(case when a.quantity__stduom is null then 0 else a.quantity__stduom end ) as lc_returned "
+ "from porcpdet a, porcp b "
+ "where a.tran_id = b.tran_id "
+ "and b.tran_ser = 'P-RET' "
+ "and b.confirmed = 'Y' "
+ "and b.tran_id__ref = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
rs = pstmt.executeQuery();
if(rs.next())
{
lcReturned = rs.getDouble("lc_returned");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("lcPassed :["+lcPassed+"] \t lcRejected ["+lcRejected+"] \t lc_returned ["+lcReturned+"]");
if(lcRejected > lcReturned)
{
sql = "select sum(case when a.quantity__stduom is null then 0 else a.quantity__stduom end) as lc_received "
+ "from porcpdet a, porcp b "
+ "where a.tran_id = b.tran_id "
+ "and b.tran_id = ? "
+ "and b.confirmed = 'Y'";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, transactionId);
rs = pstmt.executeQuery();
if(rs.next())
{
lcReceived = rs.getDouble("lc_received");
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
System.out.println("(lcReceived["+lcReceived+"] - lcReturned["+lcReturned+"]) != lcPassed["+lcPassed+"])");
if((lcReceived - lcReturned) != lcPassed)
{
String str = " GIM : "+transactionId+" QC Rejected : "+ lcRejected + "not matching with Confirmed Return :"+lcReturned+ "";
msgString = msgString + str;
System.out.println("msgString is ["+msgString+"]");
}
}//end of if for(lcRejected > lcReturned)
}//end of if for (count1 > 0)
retString = createPoRcpVoucher(transactionId , xtraParams , conn);
System.out.println("retString [from createPoRcpVoucher] is ==\n" +retString);
}//rowCount if block end
else
{
System.out.println("Error block.......");
errCode = "VTINV00001";//QC Not Confirmed OR Voucher is not created against Receipt OR Voucher Already Created
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
return retString;
}
if(msgString != null && msgString.trim().length() > 0)
{
msgString = " For the following GIMs Voucher have not been created because "+ msgString +". "
+ "You have to create the vouchers manually.";
if(retString != null && retString.trim().length() > 0)
{
retString = replaceErrorMsg(retString,"trace",msgString);
return retString;
}
else
{
errCode = "VTREJRET";
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
retString = replaceErrorMsg(retString,"trace",msgString);
return retString;
}
}
}//end of try block
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception Inside Method [poRcpVouchRetrieve] ::" + e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(rs != null){rs.close();rs = null;}
if(pstmt != null){pstmt.close();pstmt = null;}
}
catch(Exception e)
{
System.out.println("Exception ::" + e.getMessage());
throw new ITMException(e);
}
}
return retString;
}
//Sarita - Migrated Method gbf_porcp_vouch_retrieve[nvo_business_object_dist_voucher] on 10 AUG 18 [END]
//Sarita - Migrated Method gbf_check_repl_rcp[nvo_business_object_dist_voucher] on 10 AUG 18 [START]
private String checkReplRcp(String tranId, Connection conn) throws ITMException
{
String errCode = "" , sql = "" ,sql1= "",sql2 = "", retString = "";
PreparedStatement pstmt = null , pstmt1 = null , pstmt2 = null;
ResultSet rs = null , rs1 = null , rs2 = null;
String transactionId = "" , lsDiffValue = "";
double amount = 0.0 , ldRetAmt = 0.0 , diffAmt = 0.0;
int count = 0;
try
{
System.out.println("**** Inside checkReplRcp Method ****");
sql = "select tran_id ,amount from porcp "
+ "where tran_id__ref = ? "
+ "and tran_ser = 'P-RET' "
+ "and ret_opt = 'R' "
+ "and confirmed = 'Y' ";
pstmt = conn.prepareStatement(sql);
sql1 = "select count(*) as cnt from porcp where tran_id__ref = ? "
+ "and tran_ser = 'P-RCP' "
+ "and confirmed = 'Y' ";
pstmt1 = conn.prepareStatement(sql1);
sql2 = "select nvl(sum(amount),0) as ld_ret_amt from porcp "
+ "where tran_id__ref = ? "
+ "and tran_ser = 'P-RCP' "
+ "and confirmed = 'Y'";
pstmt2 = conn.prepareStatement(sql2);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
while(rs.next())
{
transactionId = checkNullAndTrim(rs.getString("tran_id"));
amount = rs.getDouble("amount");
System.out.println("Transaction is :["+transactionId+"] \t amount is :["+amount+"]");
pstmt1.setString(1, transactionId);
rs1 = pstmt1.executeQuery();
if(rs1.next())
{
count = rs1.getInt("cnt");
}
pstmt1.clearParameters();
if(rs1 != null)
{
rs1.close();
rs1 = null;
}
System.out.println("count : ["+count+"]");
if(count == 0)
{
errCode = "VTNORCP"; //No Reciept found in replacement of items
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
return retString;
}
else
{
pstmt2.setString(1, transactionId);
rs2 = pstmt2.executeQuery();
if(rs2.next())
{
ldRetAmt = rs2.getDouble("ld_ret_amt");
}
pstmt2.clearParameters();
if(rs2!= null)
{
rs2.close();
rs2 = null;
}
lsDiffValue = itmDBAccessEJB.getEnvDis("999999","PERMIT_AMT",conn);
System.out.println("lsDiffValue ["+lsDiffValue+"]");
if(lsDiffValue != null && lsDiffValue.trim().length() > 0)
{
diffAmt = Double.valueOf(lsDiffValue);
}
System.out.println("lsDiffValue ["+lsDiffValue+"]\n (ldRetAmt ["+ldRetAmt+"]- amount ["+amount+"]) > diffAmt ["+diffAmt+"]) : ");
if(!("NULLFOUND".equalsIgnoreCase(lsDiffValue))
&& ((ldRetAmt - amount) > diffAmt))
{
errCode = "VTNOPERMIT"; //The diffrence in the value of return and reciept is grater than permissible limit
retString = itmDBAccessEJB.getErrorString("",errCode,"","",conn);
return retString;
}
}
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(pstmt1 != null)
{
pstmt1.close();
pstmt1 = null;
}
if(pstmt2 != null)
{
pstmt2.close();
pstmt2 = null;
}
}
catch(Exception e)
{
try {
conn.rollback();
} catch (SQLException e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
e.printStackTrace();
System.out.println("Exception Inside Method [checkReplRcp] ::" + e.getMessage());
throw new ITMException(e);
}
finally
{
try
{
if(rs != null){rs.close();rs = null;}
if(pstmt != null){pstmt.close();pstmt = null;}
if(rs1 != null){rs1.close();rs1 = null;}
if(pstmt1 != null){pstmt1.close();pstmt1 = null;}
if(rs2 != null){rs2.close();rs2 = null;}
if(pstmt2 != null){pstmt2.close();pstmt2 = null;}
}
catch(Exception e)
{
try {
conn.rollback();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("Exception ::" + e.getMessage());
throw new ITMException(e);
}
}
return retString;
}
//Sarita - Migrated Method gbf_check_repl_rcp[nvo_business_object_dist_voucher] on 10 AUG 18 [END]
//Added by sarita on 10 AUG 18 [START]
private String replaceErrorMsg (String retErrXml ,String tagName , String replaceWith)
{
E12GenericUtility genericUtility = new E12GenericUtility();
Document dom = null;
NodeList detail1NodeList = null;
Node parentNode = null;
Node childNode = null;
NodeList childNodeList = null;
int childNodeListLength = 0;
String changedErrorString = null;
try
{
if(retErrXml != null && retErrXml.trim().length() > 0)
{
dom = genericUtility.parseString(retErrXml);
detail1NodeList = dom.getElementsByTagName("error");
parentNode = detail1NodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for (int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
String childNodeName = childNode.getNodeName();
System.out.println("childNodeName---["+childNodeName+"]");
if(tagName.equalsIgnoreCase(childNodeName))
{
childNode.getFirstChild().setNodeValue(replaceWith);
}
}
changedErrorString = genericUtility.serializeDom(dom);
System.out.println("changedErrorString---["+changedErrorString+"]");
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
return changedErrorString;
}
public String checkNullAndTrim( String inputVal )
{
if ( inputVal == null )
{
inputVal = "";
}
else
{
inputVal = inputVal.trim();
}
return inputVal;
}
//Added by sarita on 10 AUG 18 [END]
}
\ No newline at end of file
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