Commit 0f58002e authored by msingh's avatar msingh

Changes in SalesReturnConf.java for DDUK


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@99566 ce508802-f39f-4f6c-b175-0d175dae99d5
parent d1de0fbf
......@@ -9,32 +9,36 @@ import ibase.webitm.bean.wms.ShipmentStatus;
import ibase.webitm.ejb.*;
import ibase.webitm.ejb.dis.*;
import ibase.webitm.ejb.fin.*;
import java.io.File;
import java.rmi.RemoteException;
import java.util.Date;
import java.util.*;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.text.*;
import java.sql.*;
import javax.ejb.*;
import ibase.webitm.ejb.MasterStatefulLocal;
import javax.naming.InitialContext;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.w3c.dom.Document;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
@Stateless
public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConfLocal, SalesReturnConfRemote
{
......@@ -452,7 +456,7 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
pstmt = conn.prepareStatement(sql);
pstmt.setTimestamp(1, currDate);
pstmt.setString(2,"A");
// pstmt.setString(3,invoiceId);
//pstmt.setString(3,invoiceId);
pstmt.setString(3,tranIdCrn);
rowCnt = pstmt.executeUpdate();
System.out.println("receivables rowCnt------->>["+rowCnt+"]");
......@@ -2492,18 +2496,17 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
public void SendMailforSalesReturn(String invoiceId,String tranId,String tranType,String errorString,String xtraParams,Connection conn) throws Exception,SQLException
{
System.out.println("----------in sendingMail--------------------");
StringBuffer commInfo = new StringBuffer();
StringBuffer commInfoCSR = new StringBuffer();
ResultSet rs=null;
PreparedStatement pstmt=null;
String sql="",sql1="",sql2="",formatCode = "",formatCodeCSR = "",mailFlag = "",attachFlag="",attachPath = "", sendTo="", sendToCSR="",
copyTo="", copyToCSR="",bccTo="", bccToCSR="",subject="", subjectCSR="",bodyText="", bodyTextCSR="",emailAdd="",custName="",refundAmount="",
saleOrder="",currCode="",itemDescr="",loginSite="";
saleOrder="",currCode="",itemDescr="",loginSite="",headImagePath = "",footImagePath = "" ;
EMail email = new EMail();
EMail emailCSR = new EMail();
CommonWmsUtil commonWmsUtil = CommonWmsUtil.getInstance();
Document dom = null;
String emailType=null;
CommonWmsUtil commonutility = new CommonWmsUtil();
try
{
loginSite = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginSite");
......@@ -2514,6 +2517,7 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
formatCode = loginSite+'_'+tranType; // Sending mail for customer.
formatCodeCSR = loginSite+'_'+tranType+'_'+"CSR"; // Sending mail for CSR team.
System.out.println("formatCode=======["+formatCode+"]");
System.out.println("formatCode=======["+formatCodeCSR+"]");
if("Y".equalsIgnoreCase(mailFlag) && formatCode!= null && formatCodeCSR!= null && formatCode.length() > 0 && formatCodeCSR.length() > 0 )
......@@ -2575,23 +2579,17 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
bodyText = bodyText.replaceAll("ORDER_NUMBER", saleOrder);
bodyText = bodyText.replaceAll("REPLACEMENT_ITEM", itemDescr);
System.out.println("bodyText-------"+bodyText);
sendTo = sendTo.replaceAll("EMAIL", emailAdd);
headImagePath = commonutility.getDDSalesConfig("DDWMS_HEADER_IMAGE");
footImagePath = commonutility.getDDSalesConfig("DDWMS_FOOTER_IMAGE");
System.out.println("sendTo-------"+sendTo);
System.out.println("bodyText-------"+bodyText);
System.out.println("headImagePath-------"+headImagePath);
System.out.println("footImagePath-------"+footImagePath);
SendMail(sendTo,copyTo,bccTo,subject,bodyText,headImagePath,footImagePath);
commInfo.append("<ROOT>");
commInfo.append("<MAILINFO>");
commInfo.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
commInfo.append("<TO_ADD>").append("<![CDATA[" + sendTo + "]]>").append("</TO_ADD>");
commInfo.append("<CC_ADD>").append("<![CDATA[" + copyTo + "]]>").append("</CC_ADD>");
commInfo.append("<BCC_ADD>").append("<![CDATA[" + bccTo + "]]>").append("</BCC_ADD>");
commInfo.append("<SUBJECT>").append("<![CDATA[" + subject + "]]>").append("</SUBJECT>");
commInfo.append("<BODY_TEXT>").append("<![CDATA[" + bodyText + "]]>").append("</BODY_TEXT>");
commInfo.append("</MAILINFO>");
commInfo.append("</ROOT>");
System.out.println(" calling sendMail method()");
email.sendMail(commInfo.toString(), "ITM", null);
System.out.println(" ********Email send succesfully for Customer ***********");
System.out.println("----------customer relationship-----------");
......@@ -2622,19 +2620,7 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
System.out.println("bodyText-------"+bodyTextCSR);
System.out.println("sendTo-------"+sendToCSR);
commInfoCSR.append("<ROOT>");
commInfoCSR.append("<MAILINFO>");
commInfoCSR.append("<EMAIL_TYPE>").append("page").append("</EMAIL_TYPE>");
commInfoCSR.append("<TO_ADD>").append("<![CDATA[" + sendToCSR + "]]>").append("</TO_ADD>");
commInfoCSR.append("<CC_ADD>").append("<![CDATA[" + copyToCSR + "]]>").append("</CC_ADD>");
commInfoCSR.append("<BCC_ADD>").append("<![CDATA[" + bccToCSR + "]]>").append("</BCC_ADD>");
commInfoCSR.append("<SUBJECT>").append("<![CDATA[" + subjectCSR + "]]>").append("</SUBJECT>");
commInfoCSR.append("<BODY_TEXT>").append("<![CDATA[" + bodyTextCSR + "]]>").append("</BODY_TEXT>");
commInfoCSR.append("</MAILINFO>");
commInfoCSR.append("</ROOT>");
System.out.println(" calling sendMail method()");
emailCSR.sendMail(commInfoCSR.toString(), "ITM", null);
SendMail(sendToCSR,copyToCSR,bccToCSR,subjectCSR,bodyTextCSR,headImagePath,footImagePath);
System.out.println(" ********Email send succesfully for CSR***********");
}
......@@ -2661,4 +2647,71 @@ public class SalesReturnConf extends ActionHandlerEJB implements SalesReturnConf
}
//Change By Manish for send mail to customer on 15/12/2015 [End]
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
try
{
String username = CommonConstants.USERNAME;
String password = CommonConstants.PASSWORD;
return new PasswordAuthentication(username, password);
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
}
public void SendMail(String sendTo,String copyTo,String bccTo,String subject,String bodyText,String headImagePath,String footImagePath ) throws Exception,SQLException
{
boolean debug = false;
String fromAddress = CommonConstants.MAILFROM;
String host = CommonConstants.SMTPHOST;
Properties props = new Properties();
Authenticator auth = null;
if(CommonConstants.USERNAME != null && CommonConstants.PASSWORD != null)
{
props.put("mail.smtp.auth","true");
auth = new SMTPAuthenticator();
}
Session session= Session.getDefaultInstance(props,auth);
session.setDebug(debug);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(sendTo));
message.setSubject(subject);
MimeMultipart multipart = new MimeMultipart("related");
BodyPart messageBodyPart = new MimeBodyPart();
BodyPart messageBodyPart1 = new MimeBodyPart();
String htmlText = bodyText;
messageBodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(messageBodyPart);
messageBodyPart = new MimeBodyPart();
messageBodyPart1 = new MimeBodyPart();
DataSource fds = new FileDataSource(headImagePath);
messageBodyPart1.setDataHandler(new DataHandler(fds));
messageBodyPart1.setHeader("Content-ID", "<image>");
DataSource fds1 = new FileDataSource(footImagePath);
messageBodyPart.setDataHandler(new DataHandler(fds1));
messageBodyPart.setHeader("Content-ID", "<image1>");
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(messageBodyPart1);
message.setContent(multipart);
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
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