Commit 032c6f10 authored by Ajit Deshmukh's avatar Ajit Deshmukh

Added the validations and item change

parent 4cc6891c
...@@ -7,6 +7,11 @@ import java.sql.PreparedStatement; ...@@ -7,6 +7,11 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node; import org.w3c.dom.Node;
...@@ -105,7 +110,150 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -105,7 +110,150 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
switch ( currentFormNo ) switch ( currentFormNo )
{ {
case 2: case 1:
{
parentList = dom.getElementsByTagName("Detail"+ currentFormNo);
int parentNodeListLength = parentList.getLength();
System.out.println("parentNodeListLength["+parentNodeListLength+"]");
for (int prntCtr = 0; prntCtr < parentNodeListLength; prntCtr++ )
{
parentNode = parentList.item(prntCtr);
System.out.println("value of parentNode"+parentNode);
childList = parentNode.getChildNodes();
noOfChilds = childList.getLength();
System.out.println("value of noOfChilds"+noOfChilds);
for (int ctr = 0; ctr < noOfChilds; ctr++)
{
childNode = childList.item(ctr);
System.out.println("childNode"+childNode);
if( childNode.getNodeType() != Node.ELEMENT_NODE )
{
continue;
}
childNodeName = childNode.getNodeName();
if( childNodeName.equalsIgnoreCase("cust_code") )
{
String custCode = checkNull(genericUtility.getColumnValue("cust_code", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC custCode wfValData case 1 [" + custCode + "]");
String checkCustCodeSql = "select count(cust_code) as custCodeCount from customer where cust_code = ?";
PreparedStatement checkCustCodePs = connection.prepareStatement(checkCustCodeSql);
checkCustCodePs.setString(1, custCode);
ResultSet checkCustCodeRs = checkCustCodePs.executeQuery();
while(checkCustCodeRs.next()) {
int custCodeCont = checkCustCodeRs.getInt("custCodeCount");
BaseLogger.log("3", null, null, "ReqForQuotationIC custCode wfValData case 1 custCodeCont::[" + custCodeCont + "]");
if(custCodeCont<=0) {
errString = getErrorString("cust_code", "VTCUST1", userId);
break;
}
}
if(checkCustCodeRs != null)
{
checkCustCodeRs.close();
checkCustCodeRs = null;
}
if(checkCustCodePs != null)
{
checkCustCodePs.close();
checkCustCodePs = null;
}
}
if( childNodeName.equalsIgnoreCase("valid_upto") )
{
String validUptoStr = checkNull(genericUtility.getColumnValue("valid_upto", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC validUptoStr wfValData case 1 [" + validUptoStr + "]");
if(isDateInvalid(validUptoStr))
{
errString = getErrorString("valid_upto", "VTINUPTO", userId);
break;
}
}
if( childNodeName.equalsIgnoreCase("site_code") )
{
String siteCode = checkNull(genericUtility.getColumnValue("site_code", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC siteCode wfValData case 1 [" + siteCode + "]");
String checkSiteCodeSql = "select count(site_code) as siteCodeCount from site where site_code = ?";
PreparedStatement checkSiteCodePs = connection.prepareStatement(checkSiteCodeSql);
checkSiteCodePs.setString(1, siteCode);
ResultSet checkSiteCodeRs = checkSiteCodePs.executeQuery();
while(checkSiteCodeRs.next()) {
int siteCodeCont = checkSiteCodeRs.getInt("siteCodeCount");
BaseLogger.log("3", null, null, "ReqForQuotationIC siteCode wfValData case 1 siteCodeCont::[" + siteCodeCont + "]");
if(siteCodeCont<=0) {
errString = getErrorString("site_code", "VTSITCD1", userId);
break;
}
}
if(checkSiteCodeRs != null)
{
checkSiteCodeRs.close();
checkSiteCodeRs = null;
}
if(checkSiteCodePs != null)
{
checkSiteCodePs.close();
checkSiteCodePs = null;
}
}
if( childNodeName.equalsIgnoreCase("item_ser") )
{
String itemSerStr = checkNull(genericUtility.getColumnValue("item_ser", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC itemSerStr wfValData case 1 [" + itemSerStr + "]");
if (itemSerStr != null && itemSerStr.length() > 0) {
String[] itemSerArr = itemSerStr.split(",");
for (String itemSer : itemSerArr) {
BaseLogger.log("3", null, null, "ReqForQuotationIC item_ser wfValData case 1 itemSer [" + itemSer + "]");
sql = "SELECT count(1) FROM itemser WHERE item_ser = ?";
pstmt = connection.prepareStatement(sql);
pstmt.setString(1, itemSer.trim());
rs = pstmt.executeQuery();
long count = 0;
if (rs.next()) {
count = rs.getLong(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
if (count == 0) {
errString = getErrorString("item_ser", "VTITEMSER1", userId);
break;
}
}
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
}
}
}
break;
}
case 2:
{ {
parentList = dom.getElementsByTagName("Detail"+ currentFormNo); parentList = dom.getElementsByTagName("Detail"+ currentFormNo);
int parentNodeListLength = parentList.getLength(); int parentNodeListLength = parentList.getLength();
...@@ -128,7 +276,34 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -128,7 +276,34 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
childNodeName = childNode.getNodeName(); childNodeName = childNode.getNodeName();
if( childNodeName.equalsIgnoreCase("item_code") )
{
String itemCode = checkNull(genericUtility.getColumnValue("item_code", dom));
BaseLogger.log("3", null, null, "ReqForQuotationWiz itemCode wfValData case 1 [" + itemCode + "]");
String checkItemCodeSql = "select count(item_code) as itemCodeCount from item where item_code = ?";
PreparedStatement checkItemCodePs = connection.prepareStatement(checkItemCodeSql);
checkItemCodePs.setString(1, itemCode);
ResultSet checkItemCodeRs = checkItemCodePs.executeQuery();
while(checkItemCodeRs.next()) {
int itemCodeCont = checkItemCodeRs.getInt("itemCodeCount");
BaseLogger.log("3", null, null, "ReqForQuotationWiz itemCode wfValData case 1 itemCodeCont::[" + itemCodeCont + "]");
if(itemCodeCont<=0) {
errString = getErrorString("item_code", "STKVALITNE", userId);
break;
}
}
if(checkItemCodeRs != null)
{
checkItemCodeRs.close();
checkItemCodeRs = null;
}
if(checkItemCodePs != null)
{
checkItemCodePs.close();
checkItemCodePs = null;
}
}
if( childNodeName.equalsIgnoreCase("ptr_flag") ) if( childNodeName.equalsIgnoreCase("ptr_flag") )
{ {
...@@ -156,6 +331,28 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -156,6 +331,28 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
} }
}
if( childNodeName.equalsIgnoreCase("rate_quot") )
{
String phyAttrVal = "";
String itemCode = checkNull(genericUtility.getColumnValue("item_code", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC in condition itemCode wfValData itemCode::: [" + itemCode + "]");
String phyAttrValSql = "select PHY_ATTRIB_19 from item where item_code = ?";
PreparedStatement phyAttrValPs = connection.prepareStatement(phyAttrValSql);
phyAttrValPs.setString(1, itemCode);
ResultSet phyAttrValRs = phyAttrValPs.executeQuery();
while(phyAttrValRs.next()) {
phyAttrVal = checkNull(phyAttrValRs.getString("PHY_ATTRIB_19"));
}
BaseLogger.log("3", null, null, "ReqForQuotationIC in condition itemCode wfValData phyAttrVal::: [" + phyAttrVal + "]");
if(phyAttrVal.equalsIgnoreCase("SRNA")) {
errString = getErrorString("rate_quot", "INVALRC", userId);
BaseLogger.log("3", null, null, "ReqForQuotationIC in PHY_ATTRIB_19 details null errString:: [" + errString + "]");
break;
}
} }
//End elseif //End elseif
}//End for loop }//End for loop
...@@ -253,6 +450,8 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -253,6 +450,8 @@ public class ReqForQuotationIC extends ValidatorEJB {
String priceList = ""; String priceList = "";
int rate= 0; int rate= 0;
String finEntity = ""; String finEntity = "";
List<String> itemCodeList = new ArrayList<>();
try { try {
UserInfoBean userInfo = getUserInfo(); UserInfoBean userInfo = getUserInfo();
String siteCode = checkNull(userInfo.getSiteCode()); String siteCode = checkNull(userInfo.getSiteCode());
...@@ -279,9 +478,64 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -279,9 +478,64 @@ public class ReqForQuotationIC extends ValidatorEJB {
switch (currentFormNo) { switch (currentFormNo) {
case 1:
{
valueXmlString.append("<Detail1>");
if ("cust_code".equalsIgnoreCase(currentColumn.trim())) {
BaseLogger.log("3", null, null, "ReqForQuotationIC in item change case 1 cust_code condition");
String custName = "", addr1 = "", addr2="", addr3="";
String custCode = checkNull(genericUtility.getColumnValue("cust_code", dom));
BaseLogger.log("3", null, null, "ReqForQuotationIC in case 1 cust_code:: "+custCode);
String custDetilsSql = "select cust_name, addr1 , addr2 , addr3 from customer where cust_code = ?";
PreparedStatement custDetailsPs = con.prepareStatement(custDetilsSql);
custDetailsPs.setString(1, custCode);
ResultSet custDetailsRs = custDetailsPs.executeQuery();
while(custDetailsRs.next()) {
custName = custDetailsRs.getString("cust_name");
addr1 = custDetailsRs.getString("addr1");
addr2 = custDetailsRs.getString("addr2");
addr3 = custDetailsRs.getString("addr3");
}
BaseLogger.log("3", null, null, "ReqForQuotationIC in case 1 custName:: "+custName);
valueXmlString.append("<cust_name>").append("<![CDATA["+custName+"]]>").append("</cust_name>\r\n");
valueXmlString.append("<addr1>").append("<![CDATA["+addr1+"]]>").append("</addr1>\r\n");
valueXmlString.append("<addr2>").append("<![CDATA["+addr2+"]]>").append("</addr2>\r\n");
valueXmlString.append("<addr3>").append("<![CDATA["+addr3+"]]>").append("</addr3>\r\n");
}
if ("item_ser".equalsIgnoreCase(currentColumn.trim()))
{
String itemSerDescr = "";
String itemSerForIC = checkNull(genericUtility.getColumnValue("item_ser", dom, "1"));
BaseLogger.log("0", null, userId, "case 1::: item_ser");
System.out.println("case 1---------itemSerForIC05M------[" + itemSerForIC + "]");
String itemSerSql = "select descr from itemser where item_ser = ?";
try (PreparedStatement itemSerPs = conn.prepareStatement(itemSerSql))
{
itemSerPs.setString(1, itemSerForIC);
try (ResultSet itemSerRs = itemSerPs.executeQuery())
{
if (itemSerRs.next())
{
itemSerDescr = checkNull(itemSerRs.getString("descr"));
}
}
}
valueXmlString.append("<descr><![CDATA[" + itemSerDescr + "]]></descr>\n");
}
valueXmlString.append("</Detail1>");
break;
}
case 2: case 2:
{
valueXmlString.append("<Detail2>"); valueXmlString.append("<Detail2>");
if ("itm_default".equalsIgnoreCase(currentColumn.trim())) { if ("itm_default".equalsIgnoreCase(currentColumn.trim())) {
String custCode = checkNull(genericUtility.getColumnValue("cust_code", dom1)); String custCode = checkNull(genericUtility.getColumnValue("cust_code", dom1));
...@@ -360,6 +614,148 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -360,6 +614,148 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
//PTR calculation start
String siteCustomerQuery =
"SELECT PRICE_LIST FROM SITE_CUSTOMER " +
"WHERE SITE_CODE = ? AND CUST_CODE = ?";
psSiteCustomer = con.prepareStatement(siteCustomerQuery);
psSiteCustomer.setString(1, siteCode);
psSiteCustomer.setString(2, custCode);
rs = psSiteCustomer.executeQuery();
if (rs.next()) {
priceList = rs.getString("PRICE_LIST");
}
rs.close();
psSiteCustomer.close();
// Step 2: If not found in SITE_CUSTOMER, fetch from CUSTOMER
if (priceList == null || priceList.trim().isEmpty()) {
String customerQuery =
"SELECT PRICE_LIST FROM CUSTOMER WHERE CUST_CODE = ?";
psCustomer = con.prepareStatement(customerQuery);
psCustomer.setString(1, custCode);
rs = psCustomer.executeQuery();
if (rs.next()) {
priceList = rs.getString("PRICE_LIST");
}
rs.close();
psCustomer.close();
}
// Step 3: Fetch RATE from PRICELIST table
if (priceList != null && !priceList.trim().isEmpty()) {
String priceListQuery =
"SELECT RATE FROM PRICELIST WHERE PRICE_LIST = ?";
psPriceList = con.prepareStatement(priceListQuery);
psPriceList.setString(1, priceList);
rs = psPriceList.executeQuery();
if (rs.next()) {
rate = rs.getInt("RATE");
}
rs.close();
psPriceList.close();
}
//PTR calculation end
valueXmlString.append("<rate_apprv>").append("<![CDATA["+MngmntAprvRate+"]]>").append("</rate_apprv>\r\n");
valueXmlString.append("<ptd>").append("<![CDATA["+ptd+"]]>").append("</ptd>\r\n");
valueXmlString.append("<pts>").append("<![CDATA["+pts+"]]>").append("</pts>\r\n");
valueXmlString.append("<ptr>").append("<![CDATA["+rate+"]]>").append("</ptr>\r\n");
//Management rate block[End]
}
if ("itm_defaultedit".equalsIgnoreCase(currentColumn.trim())) {
String custCode = checkNull(genericUtility.getColumnValue("cust_code", dom1));
BaseLogger.log("3", null, null, "ReqForQuotationIC in itm default ");
//Management rate block[Start]
String finEntityQuery = "select fin_entity from site where site_code = ?";
psFinEntity = con.prepareStatement(finEntityQuery);
psFinEntity.setString(1, siteCode);
rs = psFinEntity.executeQuery();
if(rs.next()) {
finEntity = checkNull(rs.getString("fin_entity"));
}
BaseLogger.log("3", null, null, "ReqForQuotationIC in itm default finEntity:: "+finEntity);
rs.close();
psFinEntity.close();
// Now, use finEntity to fetch VAR_VALUE from finparm
String varValueQuery = "select VAR_VALUE from finparm where ADDL_VALUE = ?";
PreparedStatement psVarValue = con.prepareStatement(varValueQuery);
psVarValue.setString(1, finEntity);
ResultSet rsVarValue = psVarValue.executeQuery();
String varValue = null;
if (rsVarValue.next()) {
varValue = checkNull(rsVarValue.getString("VAR_VALUE"));
}
BaseLogger.log("3", null, null, "ReqForQuotationIC in itm default varValue:: " + varValue);
// Clean up the result set and prepared statement for the varValue query
rsVarValue.close();
psVarValue.close();
// Finally, use varValue to fetch the rate from pricelist
String rateQuery = "select rate from pricelist where price_list = ?";
PreparedStatement psRate = con.prepareStatement(rateQuery);
psRate.setString(1, varValue);
ResultSet rsRate = psRate.executeQuery();
int MngmntAprvRate = 0;
if (rsRate.next()) {
MngmntAprvRate = rsRate.getInt("rate");
}
BaseLogger.log("3", null, null, "ReqForQuotationIC in itm default rate:: " + rate);
// Clean up the result set and prepared statement for the rate query
rsRate.close();
psRate.close();
String priceSql =
"SELECT fp.VAR_NAME, pl.rate " +
"FROM finparm fp " +
"JOIN site s ON s.fin_entity = fp.ADDL_VALUE " +
"JOIN pricelist pl ON pl.price_list = fp.VAR_VALUE " +
"WHERE s.site_code = ? " +
"AND fp.VAR_NAME IN ('RFQ_PTS','RFQ_PTD')";
PreparedStatement psPrice = con.prepareStatement(priceSql);
psPrice.setString(1, siteCode);
ResultSet rsPrice = psPrice.executeQuery();
BigDecimal pts = null;
BigDecimal ptd = null;
BigDecimal PriceRate = null;
while (rsPrice.next()) {
String varName = checkNull(rsPrice.getString("VAR_NAME"));
PriceRate = rsPrice.getBigDecimal("rate");
if ("RFQ_PTS".equals(varName)) {
pts = PriceRate;
} else if ("RFQ_PTD".equals(varName)) {
ptd = PriceRate;
}
}
//PTR calculation start //PTR calculation start
String siteCustomerQuery = String siteCustomerQuery =
"SELECT PRICE_LIST FROM SITE_CUSTOMER " + "SELECT PRICE_LIST FROM SITE_CUSTOMER " +
...@@ -459,7 +855,7 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -459,7 +855,7 @@ public class ReqForQuotationIC extends ValidatorEJB {
BigDecimal rateQuotVal = new BigDecimal(rateQuot); BigDecimal rateQuotVal = new BigDecimal(rateQuot);
BigDecimal ratePtrVal = new BigDecimal(ratePtr); BigDecimal ratePtrVal = new BigDecimal(ratePtr);
BaseLogger.log("3", null, null, "ReqForQuotationIC after conversion rateQuotVal:: "+rateQuotVal+" rateApprvVal::"+rateApprvVal); BaseLogger.log("3", null, null, "ReqForQuotationIC after conversion rateQuotVal:: "+rateQuotVal+" rateApprvVal::"+rateApprvVal+ " ratePtrVal::"+ratePtrVal);
...@@ -481,12 +877,12 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -481,12 +877,12 @@ public class ReqForQuotationIC extends ValidatorEJB {
if (rateApprvVal.compareTo(rateQuotVal) > 0) { if (rateApprvVal.compareTo(rateQuotVal) > 0) {
BaseLogger.log("3", null, null, "in rateApprvVal greater condition"); BaseLogger.log("3", null, null, "in rateApprvVal greater condition");
String detail1Xml = "<Detail1><mgmnt_apprv><![CDATA[Y]]></mgmnt_apprv><wf_status><![CDATA[P]]></wf_status></Detail1>"; String detail1Xml = "<mgmnt_apprv><![CDATA[Y]]></mgmnt_apprv><wf_status><![CDATA[P]]></wf_status>";
int pos = valueXmlString.indexOf("</header>"); int pos = valueXmlString.indexOf("<Detail1>");
if (pos != -1) { if (pos != -1) {
pos += "</header>".length(); // move after </header> pos += "<Detail1>".length(); // move after </header>
valueXmlString.insert(pos, detail1Xml); valueXmlString.insert(pos, detail1Xml);
} }
...@@ -494,13 +890,28 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -494,13 +890,28 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
//Added condition if ptr and special rate is same direct create the sales quotation
/*
* if (rateQuotVal.compareTo(ratePtrVal) == 0) { BaseLogger.log("3", null, null,
* "In PTR and Special rate equal condition"); ReqForQuotationAprv
* reqForQuotationAprv = new ReqForQuotationAprv(); String domString =
* genericUtility.serializeDom(dom).toString(); BaseLogger.log("3", null, null,
* "domString>>>>> "+domString); String result =
* reqForQuotationAprv.updateWFStatus(domString, con, xtraParams);
* BaseLogger.log("3", null, null, "ReqForQuotationAprv result>>>>> "+result);
*
* }
*/
} }
} }
valueXmlString.append("</Detail2>\r\n"); valueXmlString.append("</Detail2>\r\n");
break; break;
} }
}
BaseLogger.log("3", null, null, "in rateApprvVal greater condition reStr>>>>> "+reStr); BaseLogger.log("3", null, null, "in rateApprvVal greater condition reStr>>>>> "+reStr);
valueXmlString.append("</Root>\r\n"); valueXmlString.append("</Root>\r\n");
} catch (Exception e) { } catch (Exception e) {
...@@ -549,4 +960,26 @@ public class ReqForQuotationIC extends ValidatorEJB { ...@@ -549,4 +960,26 @@ public class ReqForQuotationIC extends ValidatorEJB {
} }
return input; return input;
} }
public static boolean isDateInvalid(String validUptoStr)
{
try
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yy");
LocalDate validDate = LocalDate.parse(validUptoStr, formatter);
LocalDate currentDate = LocalDate.now();
if(validDate.isBefore(currentDate))
{
return true;
}
}
catch(Exception e)
{
BaseLogger.log("3", null, null, "Exception in date validation [" + e + "]");
}
return false;
}
} }
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