Commit 34bc152f authored by Ajit Deshmukh's avatar Ajit Deshmukh

Made changes to the Sales Quotation transaction creation, added 'Valid Upto'...

Made changes to the Sales Quotation transaction creation, added 'Valid Upto' from RFQ transaction, and included the Effective Date of the approval workflow.
parent 5432fe3a
package ibase.webitm.ejb.dis;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import javax.naming.InitialContext;
import org.w3c.dom.Document;
import ibase.ejb.CommonDBAccessEJB;
import ibase.system.config.AppConnectParm;
import ibase.system.config.ConnDriver;
import ibase.utility.BaseLogger;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.MasterStatefulLocal;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.ejb.XML2DBEJB;
import ibase.webitm.utility.GenericWorkflowClass;
import ibase.webitm.utility.ITMException;
public class ReqForQuotationAprv extends ValidatorEJB{
E12GenericUtility genericUtility = new E12GenericUtility();
public String updateWFStatus()throws RemoteException,ITMException
{
BaseLogger.log("3", null, null, "ReqForQuotationAprv.updateWFStatus calling......");
return "";
}
public String updateWFStatus(String domString, Connection conn, String xtraParams) throws RemoteException,ITMException
{
BaseLogger.log("3", null, null, "ReqForQuotationAprv.updateWFStatus() calling......03/FEB/26 "+domString);
BaseLogger.log("3", null, null, "ReqForQuotationAprv.updateWFStatus() xtraParams:: "+xtraParams);
String retVal = "";
String refSer = "";
String tranID = "";
String signStatus = "";
String enterprises1 = "";
boolean isLocalConn = false;
PreparedStatement rfqPstmt = null;
PreparedStatement mgmntApprvUpdatePs = null;
ResultSet mgmntApprvUpdateRs = null;
ResultSet rfqRs = null;
PreparedStatement rfqDetPstmt = null;
ResultSet rfqDetRs = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
PreparedStatement rateComparePstmt = null;
ResultSet rateCompareRs = null;
PreparedStatement checkAppr2StatusPs = null;
ResultSet checkAppr2StatusRs = null;
PreparedStatement updateWfStatusPstmt = null;
ResultSet updateWfStatusRs = null;
String empCode = "";
String entityCode = "",reportTo="",allocatedTo;
LocalDate tranDate = LocalDate.now();// for tranDate
LocalTime tranTime = LocalTime.now();
String tranDateStr = formatDateTime(tranDate, tranTime);
String tranId = "";
String reqId = "";
String custCode = "";
String quotType = "";
String itemSer = "";
String validUpto = "";
String executed = "";
String tranIdOrg = "";
String activeYn = "";
String itmVer = "";
String chgUser = "";
String chgTerm = "";
String confirmed = "";
String empCodeAprv = "";
String enterprises = "";
String applDb = "";
String execRights = "";
int domId=0;
String tranIdRef = "";
String quantity = "";
String lineNo = "";
String itemCode = "";
int rate = 0;
String wrkflwInit = "";
//InitialContext ctx = null;
String retString = "";
String executionRights = "";
String objName = "";
String roleCodeSign = "";
StringBuffer processDynXmlString = new StringBuffer();
XML2DBEJB xml2dbObj = new XML2DBEJB();
Boolean tranFlag = false;
String processRequestResult = "";
try
{
UserInfoBean userInfo = new UserInfoBean();
CommonDBAccessEJB commonDBAccessEJB = new CommonDBAccessEJB();
AppConnectParm appConnect = new AppConnectParm();
InitialContext initialContext = new InitialContext(appConnect.getProperty());
System.out.println("ReqForQuotationAprv.updateWFStatus() domString test["+domString+"]!!!!!!!");
if (conn == null)
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB(userInfo.getTransDB());
}
Document dom = genericUtility.parseString(domString);
signStatus = checkNull(genericUtility.getColumnValue("sign_status",dom,"1"));
refSer = checkNull(genericUtility.getColumnValue("ref_ser",dom,"1"));
tranID = checkNull(genericUtility.getColumnValue("ref_id",dom,"1"));
signStatus = checkNull(genericUtility.getColumnValue("sign_status",dom,"1"));
empCode = checkNull(genericUtility.getColumnValue("emp_code",dom,"1"));
allocatedTo = checkNull(genericUtility.getColumnValue("allocated_to",dom,"1"));
objName = checkNull(genericUtility.getColumnValue("obj_name",dom,"1"));
roleCodeSign = checkNull(genericUtility.getColumnValue("role_code__sign",dom,"1"));
if(roleCodeSign.equalsIgnoreCase("VHB_MNGMNT") && signStatus.equalsIgnoreCase("S")) {
String updateWfStatusSql = "update SALES_QUOT_REQ set WF_STATUS = 'A' where tran_id = ?";
updateWfStatusPstmt = conn.prepareStatement(updateWfStatusSql);
updateWfStatusPstmt.setString(1, tranID);
int updateWfStatusCount = updateWfStatusPstmt.executeUpdate();
System.out.println("updateWfStatusCount::::: =[" + updateWfStatusCount + "]");
}
System.out.println("enterprises::::: =[" + enterprises1 + "]"+" tran_id::"+tranID);
userInfo = commonDBAccessEJB.createUserInfo(empCode);
System.out.println("signStatus::"+signStatus+" enterprises::::: =[" + enterprises1 + "]"+" tran_id::"+tranID+" empCode::"+empCode);
//Changes on 06-Feb-26 by Ajit [Start]
String rateCompareSql = "SELECT RATE_QUOT,PTR,RATE_APPRV,LINE_NO FROM SALES_QUOT_REQ_DET WHERE tran_id = ?";
rateComparePstmt = conn.prepareStatement(rateCompareSql);
rateComparePstmt.setString(1, tranID);
rateCompareRs = rateComparePstmt.executeQuery();
while (rateCompareRs.next()) {
BigDecimal rateQuot = rateCompareRs.getBigDecimal("RATE_QUOT");
BigDecimal rateApprv = rateCompareRs.getBigDecimal("RATE_APPRV");
BigDecimal PTR = rateCompareRs.getBigDecimal("PTR");
int lineNoOfDet = rateCompareRs.getInt("LINE_NO");
//Added a condition if PTR and special rate is equal directly create the sales quotation transaction
if (PTR.compareTo(rateQuot) == 0) {
tranFlag = false;
}
if (rateApprv.compareTo(rateQuot) > 0) {
tranFlag = true;
}
}
if (rateComparePstmt != null) {
rateComparePstmt.close();
rateComparePstmt = null;
}
if (rateCompareRs != null) {
rateCompareRs.close();
rateCompareRs = null;
}
if(tranFlag) {
String checkAppr2StatusSql = "SELECT WF_STATUS FROM SALES_QUOT_REQ WHERE tran_id = ?";
checkAppr2StatusPs = conn.prepareStatement(checkAppr2StatusSql);
checkAppr2StatusPs.setString(1, tranID);
checkAppr2StatusRs = checkAppr2StatusPs.executeQuery();
while (checkAppr2StatusRs.next()) {
String wfStatus = checkAppr2StatusRs.getString("WF_STATUS");
if (wfStatus.equalsIgnoreCase("A")) {
tranFlag = false;
}
}
}
if (checkAppr2StatusRs != null) {
checkAppr2StatusRs.close();
checkAppr2StatusRs = null;
}
if (checkAppr2StatusPs != null) {
checkAppr2StatusPs.close();
checkAppr2StatusPs = null;
}
BaseLogger.log("3", null, null, "in ReqForQuotationAprv tranFlag::"+ tranFlag);
if(!tranFlag) {
BaseLogger.log("3", null, null, "in ReqForQuotationAprv tranFlag true condition::");
String rfqSql = "select CUST_CODE ,QUOT_TYPE ,ITEM_SER, VALID_UPTO "
+ "FROM SALES_QUOT_REQ where tran_id = ?";
rfqPstmt = conn.prepareStatement(rfqSql);
rfqPstmt.setString(1, tranID);
rfqRs = rfqPstmt.executeQuery();
while (rfqRs.next()) {
// Directly fetching and using values from result set without declaring variables
custCode = checkNull(rfqRs.getString("CUST_CODE"));
quotType = checkNull(rfqRs.getString("QUOT_TYPE"));
itemSer = checkNull(rfqRs.getString("ITEM_SER"));
validUpto = checkNull(rfqRs.getString("VALID_UPTO"));
// Do something with these values directly (e.g., use them in logic, or store in a collection)
System.out.println("custCode: " + custCode + ", " +
"quotType: " + quotType + ", " +
"validUpto: " + validUpto + ", " +
"itemSer: " + itemSer );
}
// Start building the XML string
processDynXmlString.append("<DocumentRoot><description>Datawindow Root</description><group0>");
processDynXmlString.append(
"<description>Group0 description</description><Header0><description>Header0 members</description>");
processDynXmlString.append("<objName><![CDATA[salesquot]]></objName>");
processDynXmlString.append("<pageContext><![CDATA[1]]></pageContext>");
processDynXmlString.append("<objContext><![CDATA[1]]></objContext>");
processDynXmlString.append("<editFlag><![CDATA[A]]></editFlag>");
processDynXmlString.append("<focusedColumn><![CDATA[]]></focusedColumn>");
processDynXmlString.append("<action><![CDATA[SAVE]]></action>");
processDynXmlString.append("<elementName><![CDATA[]]></elementName>");
processDynXmlString.append("<keyValue><![CDATA[1]]></keyValue>");
processDynXmlString.append("<saveLevel><![CDATA[1]]></saveLevel>");
processDynXmlString.append("<forcedSave><![CDATA[false]]></forcedSave>");
processDynXmlString.append("<Detail1 dbID='' domID='1' objContext='1' objName='salesquot'>");
processDynXmlString
.append("<attribute IS_CHANGE='Y' pkNames='TRAN_ID' selected='N' status='N' updateFlag='A'/>");
//processDynXmlString.append("<tran_id/>");
processDynXmlString.append("<inq_date><![CDATA[" + dateFormatter(tranDateStr) + "]]></inq_date>");
processDynXmlString.append("<cust_code><![CDATA[" + custCode + "]]></cust_code>");
processDynXmlString.append("<quot_type><![CDATA[" + quotType + "]]></quot_type>");
processDynXmlString.append("<item_ser><![CDATA[" + itemSer + "]]></item_ser>");
processDynXmlString.append("<eff_date><![CDATA[" + dateFormatter(tranDateStr) + "]]></eff_date>");
processDynXmlString.append("<valid_upto><![CDATA[" + validUpto + "]]></valid_upto>");
processDynXmlString.append("<curr_code><![CDATA[INR]]></curr_code>");
processDynXmlString.append("<confirmed><![CDATA[N]]></confirmed>");
processDynXmlString.append("</Detail1>");
String rfqDet1Sql = "SELECT LINE_NO, ITEM_CODE, QTY_QUOT, RATE_QUOT FROM SALES_QUOT_REQ_DET WHERE tran_id = ?";
rfqDetPstmt = conn.prepareStatement(rfqDet1Sql);
rfqDetPstmt.setString(1, tranID);
rfqDetRs = rfqDetPstmt.executeQuery();
while (rfqDetRs.next()) {
domId++;
BaseLogger.log("3", getUserInfo(), null, "domId :: "+domId);
lineNo = checkNull(rfqDetRs.getString("LINE_NO"));
itemCode = checkNull(rfqDetRs.getString("ITEM_CODE"));
quantity = checkNull(rfqDetRs.getString("QTY_QUOT"));
rate = rfqDetRs.getInt("RATE_QUOT");
String resvisedRateSql = "select PHY_ATTRIB_13,PHY_ATTRIB_14,PHY_ATTRIB_15 from item where item_code = ?";
PreparedStatement resvisedRatePstmt = conn.prepareStatement(resvisedRateSql);
resvisedRatePstmt.setString(1, itemCode);
ResultSet resvisedRateRs = resvisedRatePstmt.executeQuery();
while(resvisedRateRs.next()) {
int distMargin = resvisedRateRs.getInt("PHY_ATTRIB_13");
int stockMargin = resvisedRateRs.getInt("PHY_ATTRIB_14");
int retailMargin = resvisedRateRs.getInt("PHY_ATTRIB_15");
BigDecimal rateBD = new BigDecimal(rate);
BigDecimal hundred = new BigDecimal(100);
BigDecimal retailMarginBD = new BigDecimal(retailMargin);
BigDecimal stockMarginBD = new BigDecimal(stockMargin);
BigDecimal distMarginBD = new BigDecimal(distMargin);
BaseLogger.log("3", null, null, "distMargin::" + distMargin + " stockMargin::"+stockMargin+" revisedPtd:: "+retailMargin+ "rate:: "+rate+"]");
BigDecimal revisedPtr = rateBD.divide(
hundred.multiply(hundred.subtract(retailMarginBD)),
6,
RoundingMode.HALF_UP
);
BigDecimal revisedPts = rateBD.divide(
hundred.multiply(hundred.subtract(stockMarginBD)),
6,
RoundingMode.HALF_UP
);
BigDecimal revisedPtd = rateBD.divide(
hundred.multiply(hundred.subtract(distMarginBD)),
6,
RoundingMode.HALF_UP
);
BaseLogger.log("3", null, null,
"revisedPtr::" + revisedPtr +
" revisedPts::" + revisedPts +
" revisedPtd::" + revisedPtd);
BaseLogger.log("3", null, null, "revisedPtr::" + revisedPtr + " revisedPts::"+revisedPts+" revisedPtd:: "+revisedPtd+ "]");
processDynXmlString.append("<Detail2 dbID=':' domID='"+domId+"' objName=\"salesquot\" objContext=\"2\">");
processDynXmlString.append("<attribute pkNames=\"quot_no:line_no:\" selected=\"N\" updateFlag=\"A\" status=\"N\" />");
processDynXmlString.append("<line_no><![CDATA[").append(lineNo).append("]]></line_no>");
processDynXmlString.append("<item_code><![CDATA[").append(itemCode).append("]]></item_code>");
processDynXmlString.append("<quantity><![CDATA[").append(quantity).append("]]></quantity>");
processDynXmlString.append("<rate><![CDATA[").append(rate).append("]]></rate>");
processDynXmlString.append("<ptr><![CDATA[").append(revisedPtr).append("]]></ptr>");
processDynXmlString.append("<pts><![CDATA[").append(revisedPts).append("]]></pts>");
processDynXmlString.append("<ptd><![CDATA[").append(revisedPtd).append("]]></ptd>");
processDynXmlString.append("</Detail2>");
}
}
if (rfqDetRs != null) {
rfqDetRs.close();
rfqDetRs = null;
}
if (rfqDetPstmt != null) {
rfqDetPstmt.close();
rfqDetPstmt = null;
}
processDynXmlString.append("</Header0></group0></DocumentRoot>");
//Changes on 06-Feb-26 by Ajit [End]
// Now, processDynXmlString contains the dynamically generated XML with the values from your query
System.out.println(processDynXmlString.toString());
// String tranIDNew = commonDBAccessEJB.generateSeq("asset_assign_seq", 10, userInfo.getTransDB());
// BaseLogger.log("3", null, null, " generated tranID :: " + tranIDNew); // tran_id
// processDynXmlString.toString().replace("{{tranId}}", tranIdNew);
String salesQuotXml = processDynXmlString.toString();
BaseLogger.log("3", null, null, "userInfo::" + userInfo.toString() + "]");
BaseLogger.log("3", null, null, "salesQuotXml::" + salesQuotXml.toString() + "]");
MasterStatefulLocal masterStateful = (MasterStatefulLocal) initialContext
.lookup("ibase/MasterStatefulEJB/local");
processRequestResult = masterStateful.processRequest(userInfo, salesQuotXml, false, conn);
BaseLogger.log("3", null, null, "processRequest processRequestResultD" + processRequestResult + "]");
retString = processRequestResult;
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if ( conn != null )
{
if ( isLocalConn )
{
conn.close();
conn = null;
}
}
}
catch(Exception e)
{
}
}
BaseLogger.log("3", null, null, "returning retString [" + retString + "]");
return retString;
}
public static String formatDateTime(LocalDate tranDate, LocalTime tranTime) {
LocalDateTime tranDateTime = LocalDateTime.of(tranDate, tranTime);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = tranDateTime.format(formatter);
return formattedDateTime;
}
public static String dateFormatter(String inputDateString ) {
String result = "";
String inputFormat = "yyyy-MM-dd HH:mm:ss";
String outputFormat = "dd/MM/yy HH:mm:ss";
try {
// Parse input date string
SimpleDateFormat inputFormatter = new SimpleDateFormat(inputFormat);
Date date = inputFormatter.parse(inputDateString);
// Format the date in the desired output format
SimpleDateFormat outputFormatter = new SimpleDateFormat(outputFormat);
String outputDateString = outputFormatter.format(date);
System.out.println("Input Date: " + inputDateString);
System.out.println("Formatted Date: " + outputDateString);
result = outputDateString;
} catch (Exception e) {
BaseLogger.log("3", null, null, "Exception in dateFormatter. [" + E12GenericUtility.getStackTrace(e) + "]");
}
return result;
}
private String checkNull(String input)
{
if(input == null)
{
input = "";
}
return input;
}
}
\ 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