package my.com.kfh.enterprise.services.ib117_jomPay;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import my.com.kfh.enterprise.services.IBEnterpriseServicesWorkspace;
import my.com.kfh.enterprise.services.IBUtils;
import my.com.kfh.enterprise.services.common.CommonConstants;
import my.com.kfh.enterprise.services.ib101_access.AccessConstants;
import my.com.kfh.enterprise.services.ib112_si.SIConstants;
import my.com.kfh.enterprise.services.ib112_si.SI_PAYMENT_MODE;
import my.com.kfh.enterprise.services.integration.ESBIntegrationConfig;
import my.com.kfh.error.exception.IBGenericException;
import my.com.kfh.error.exception.IBServiceException;
import my.com.kfh.error.handler.CommonErrorCode;
import my.com.kfh.error.handler.IBErrorHandler;
import my.com.kfh.esb.response.ESBAccountEnquiryTC100Bean;
import my.com.kfh.esb.response.ESBCompanyProfileBean;
import my.com.kfh.hibernate.tables.IBJomPay;
import my.com.kfh.hibernate.tables.onlineMobile.JomPay;
import my.com.kfh.hibernate.tables.onlineMobile.MobileTransaction;
import my.com.kfh.hibernate.utils.HibernateJomPayUtils;
import my.com.kfh.hibernate.utils.onlineMobile.HibernateOnlineMobileReportsUtils;
import my.com.kfh.sms.services.SMSConstants;
import my.com.kfh.sms.services.SMSServices;
import my.com.kfh.web.utils.BVI_DateTime;
import my.com.kfh.web.utils.DateTimeUtils;
import my.com.kfh.web.utils.FormatterUtils;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBSessionObjects;
import my.com.kfh.web.utils.IBTimer;
import my.com.kfh.web.utils.ResourcesUtils;
import my.com.kfh.web.utils.Constant.ServiceInfoExtend;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.kfh.nbps.webservice.NBPSWS1;
import com.kfh.nbps.webservice.NBPSWS1Service;
import com.kfh.nbps.webservice.NBPSWS1ServiceLocator;

public class IBRegisteredJomPayResultServices extends IBEnterpriseServicesWorkspace {
	
	private static Class c_oClass = IBRegisteredJomPayResultServices.class;
	
	//Xml Response
	String xmlResponse = null;
	String respStatus = null;
	String respErrCode = null;
	String respErrMsg = null;
	String respJomPayRefNo = null;
	String respDateTime = null;
	String respChannelRefNo = null;
	String respChargeReferenceNo = null;
	String respChargeRespCode = null;
	String respFundReferenceNo = null;
	String respFundRespCode = null;

	public IBRegisteredJomPayResultServices(IBSessionObjects m_oIBSessionObjects) {
		super(m_oIBSessionObjects);
	}

	public void execute() throws Exception {
		
		String m_sMethodName = "executeServices";
		IBTimer m_oTimer = IBLogger.logBSFNMethodEnteringMessage (c_oClass, m_sMethodName);
		
		try {
			// ViewBean
			Date dt = new Date();
			Map<Integer,IBDynaBean> selectedMap = new LinkedHashMap();
			Map<String, IBDynaBean> accountMap = new LinkedHashMap();
			IBDynaBean viewBean = null;
			IBDynaBean m_oRegisteredJomPayBean = null;
			IBDynaBean m_oAccountFrom = null;
			IBDynaBean m_oServiceBean = null;
			String m_sDate = null;
			String m_sTime = null;
			
			// DB
			Long m_sTrnxId 	= null;
			String m_sTrxnType = null;
			Date m_sTrxnDate = null;
			Long m_sUserId = null;
			Date m_sEffectiveDATE = null;
			String m_sBillerCode = null;
			String m_sBillerName = null;
			String m_sBillRefNo1 = null;
			String m_sBillRefNo2 = null;
			BigDecimal m_sAmount = null;
			String m_sStatus = null;
			String m_sFromAccNo = null;
			String m_sFromCurrency = null;
			String m_sMerchantAccNo = null;
			String m_sToCurrency = null;
			String m_sPhxReferenceNo = null;
			String m_sPhxrefRevNo = null;
			String m_sRespCode = null;
			String m_sRespMsg = null;
			String m_sServiceCode = null;
			String m_sInfo2 = null;
			String m_sInfo3 = null;
			String m_sContactNo = null;
			String m_sMerchantEmail = null;
			String m_sSiIndicator = null;
			String m_sRemoteIp = null;
			String m_sOther1 = null;
			String m_sOther2 = null;
			String m_sReason = null;
			String m_sEPayReference = null;
			String m_sRevertReference = null;
			String m_sPaymentMode = null;
			String m_sPayFrequency = null;
			String m_sTerminationDate = null;
			StringBuffer m_sbDesc = new StringBuffer ();
			boolean m_boIsResultSuccessful = false;
			
			//WebService
			String channel				=	null;
			String subChannel			=	null;
			String fromAccountNo 		=	null;			 	
			String toAccountNo  		=	null;
			String amount  				=	null;
			String chargeAmount  		=	null;
			String toName  				=	null;
			String fromName  			=	null;
			String rimNo  				=	null;
			String paymentDescription  	=	null;
			String phnxChargesDesc  	=	null;
			String phnxPrincipleDesc  	=	null;
			String channelRefNo			=	null;
			String paymentType  		=	null;
			String accountType  		=	null;
			String recipientRefNo   	=	null;
			String recipientRefNo2   	=	null;
			String billerCode   		=	null;
			String paymentChannel    	=	null;
			String payerType    		=	null;
			String chargesColAccount	=	null;
			String jomPayRefNo			=	null;
			
			BVI_DateTime m_oCurrentBVIDateTime = new BVI_DateTime();
			String m_sAccNewBal="";
			
			Map<String, String> m_oReceiptMap = new LinkedHashMap<String, String> ();
			String m_sReceiptLink = null;

			viewBean = (IBDynaBean) getIBDynaBean ().get (JomPayContants.jomPayRegisterView);
			m_oServiceBean = (IBDynaBean) viewBean.get(JomPayContants.jomPayServiceInfo);
			
			m_sDate = DateTimeUtils.formatDayMonthYear (dt);
			m_sTime = (DateTimeUtils.convertDateTime (dt)).getTime ();
			
			//Get Value from transaction
			selectedMap = (Map<Integer, IBDynaBean>) viewBean.get(JomPayContants.jomPayRegisterViewSelectedMap);
			accountMap = (Map) viewBean.get(JomPayContants.jomPayViewAccountMap);
			
			m_oAccountFrom = (IBDynaBean)accountMap.get(getIBDynaBean().get(JomPayContants.jomPayRegisterFormAccountIndex).toString());
			
			for(int i=0;i<selectedMap.size();i++)
			{
				IBJomPay ibJomPay = new IBJomPay();
				
				m_oRegisteredJomPayBean = (IBDynaBean) selectedMap.get(i);
				
//				m_sbDesc.append ((String) m_oServiceBean.get (ServiceInfo.BEAN_ATT_SERVICE_NAME));
				m_sbDesc.append (" - ");
				m_sbDesc.append(m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCodeName).toString());
				
				m_sTrnxId 	= new Long(m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewTransId).toString());//new Long(IBUtils.getTransactionId (getIBSessionObjects ().getDataManager ()));
				
				//Set before calling to host
				fromAccountNo		= 	m_oAccountFrom.get(JomPayContants.jomPayViewAccountNo).toString();
				
				ESBCompanyProfileBean profile = getESBServices().getProfileByAccRim(fromAccountNo, null);				
				
				//Setting input for WebService
				channel 			= 	JomPayContants.jomPayWSChannel;//HD
				subChannel 			= 	JomPayContants.jomPayWSSubChannel;//HD
				toAccountNo			=	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerAccount).toString();
				amount				= 	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewAmount).toString();
				chargeAmount		= 	"0";
				toName				= 	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCodeName).toString();
				fromName			= 	profile.getAccountName();//m_oAccountFrom.get(JomPayContants.jomPayViewAccountNickName).toString();
				rimNo				= 	(String)getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.RIM_NO);
				paymentDescription	=	"";
				phnxPrincipleDesc  	=	"IB JP:";
				phnxChargesDesc  	=	"";
				channelRefNo		=	String.valueOf(m_sTrnxId);
				paymentType			=	"01";
				accountType 		= 	m_oAccountFrom.get(JomPayContants.jomPayViewAccountApplType).toString().equalsIgnoreCase("SV")?"1":"2";
				recipientRefNo		=	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef1).toString();
				recipientRefNo2		=	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef2).toString();
				billerCode			=	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCode).toString();
				paymentChannel		=	JomPayContants.jomPayWSPaymentChannel;//HD//1.InternetBanking|2.ATM|3.MobileBanking|4.MyClearUSSD|5.OverTheCounter
				payerType			=	JomPayContants.jomPayWSPayerType;//HD
				chargesColAccount	=	null;
				jomPayRefNo			=	m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewJomPayRef).toString();
				
				phnxPrincipleDesc = phnxPrincipleDesc + (toName.length() > 20?toName.substring(0, 20):toName) + "," + recipientRefNo + "," + jomPayRefNo;
				
				//NBPS WebService Start
				xmlResponse = AddIBGNBPSEntry(channel,subChannel,fromAccountNo,toAccountNo,amount,chargeAmount,toName,fromName,rimNo,paymentDescription,phnxChargesDesc,phnxPrincipleDesc,channelRefNo,paymentType,accountType,recipientRefNo,recipientRefNo2,billerCode,paymentChannel,payerType,chargesColAccount,jomPayRefNo);
				readXmlResponse(xmlResponse);
				//NBPS WebService End
				
				if(respStatus.equalsIgnoreCase("0"))
				{
					m_boIsResultSuccessful = false;
					m_sStatus = "Unsuccessful";
					m_oRegisteredJomPayBean.set(JomPayContants.jomPayRegisterViewReason, ResourcesUtils.getApplicationResourceMessage("jomPay.host.error.message." + respErrCode));
				}
				else if(respStatus.equalsIgnoreCase("1"))
				{
					m_boIsResultSuccessful = true;
					m_sStatus = "Successful";
					ESBAccountEnquiryTC100Bean m_oTCEnquiryBeanNew = getESBServices ().getAccountDetailsTC100 (m_oAccountFrom.get("accountNo").toString());
					m_sAccNewBal = m_oTCEnquiryBeanNew.getAvailable_Bal();
				}
				
				m_oRegisteredJomPayBean.set(JomPayContants.jomPayRegisterViewStatus, m_sStatus);
				
				m_sTrxnType = "Registered JomPAY";
				m_sTrxnDate = dt;
				m_sUserId = this.getIBSessionObjects ().getVisitor ().getId ();
				m_sEffectiveDATE = dt;
				m_sBillerCode = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCode).toString();
				m_sBillerName = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCodeName).toString();
				m_sBillRefNo1 = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef1).toString();
				m_sBillRefNo2 = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef2).toString();
				m_sAmount = new BigDecimal(m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewAmount).toString());
				m_sStatus = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewStatus).toString();
				m_sFromAccNo = m_oAccountFrom.get(JomPayContants.jomPayViewAccountNo).toString();
				m_sFromCurrency = "MYR";
				m_sMerchantAccNo = m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerAccount).toString();
				m_sToCurrency = "MYR";
				m_sPhxReferenceNo = respFundReferenceNo;
				m_sPhxrefRevNo = "";
				m_sRespCode = respErrCode;
				m_sRespMsg = respErrMsg;
				m_sServiceCode = (String) m_oServiceBean.get (ServiceInfoExtend.BEAN_ATT_SERVICE_CODE);
				m_sInfo2 = "";
				m_sInfo3 = "";
				m_sContactNo = "";
				m_sMerchantEmail = null;
				m_sSiIndicator = "0";
				m_sRemoteIp = (String)getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.COL_REMOTE_IP);
				m_sOther1 = "";
				m_sOther2 = "";
				
				
				
				
				
				
//				 SMS Notification START
				String m_sCustomerSMSMessage = "-";
//				String m_sBeneficiarySMSMessage = "-";
				
				String m_sCustomerAmount = SMSServices.formatAmountValue(String.valueOf(m_sAmount), null);
//				String m_sBeneficiaryAmount = SMSServices.formatAmountValue(String.valueOf(m_sAmount), null);
				
				String m_sTransactionTypeForSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_JOMPAY);
				
				//compose sms
				m_sCustomerSMSMessage = SMSServices.generateCustomerSMSMessage(
						m_sTransactionTypeForSMSMessage, 
						m_sCustomerAmount, 
						m_sBillerName.length()>15?m_sBillerName.substring(0, 15):m_sBillerName,
						m_sStatus, 
						new Date(),
						FormatterUtils.formatMoneyDisplay (m_sAccNewBal, "", true));
				
				//send sms
				SMSServices.sendCustomerSMS(this, 
						viewBean, 
						m_sFromAccNo, 
						m_sStatus, 
						SI_PAYMENT_MODE.PAY_NOW.getCode (), 
						m_sTrxnType, 
						String.valueOf(m_sTrnxId),
						String.valueOf(m_sAmount), 
						getIBSessionObjects().getVisitor().getId(), 
						m_sCustomerSMSMessage, 
						m_oCurrentBVIDateTime,
						SMSConstants.DEBIT_IB_TYPE);
				
//				m_sBeneficiarySMSMessage = SMSServices.generateBeneficiaryOtherSMSMessage(
//						viewBean, 
//						m_sTransactionTypeForSMSMessage, 
//						"", 
//						m_sBeneficiaryAmount, 
//						m_oCurrentBVIDateTime);
//				
//				SMSServices.sendBeneficiarySMS(this, 
//						getIBDynaBean(),
//						viewBean, 
//						m_sFromAccNo, 
//						m_sStatus, 
//						getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
//						m_sTrnxTypeAll, 
//						String.valueOf(m_sTrnxId),
//						getIBSessionObjects().getVisitor().getId(),  
//						m_sBeneficiarySMSMessage, 
//						m_oCurrentBVIDateTime,
//						"");
				
				
//				m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.new.balance"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_FROM_ACCOUNT_BALANCE));
				
				// UAT START
//				viewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_BENE_SMS_SENT, SMSServices.isSMSLogged(this, viewBean.get(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentBVIDateTime.getDateDDMMMYYYYHMS()));
				viewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_CUSTOMER_SMS_SENT, SMSServices.isSMSLogged(this, viewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentBVIDateTime.getDateDDMMMYYYYHMS()));
//				viewBean.set(SMSConstants.VBEAN_SMS_UAT_BENE_SMS_MESSAGE, m_sBeneficiarySMSMessage);
				viewBean.set(SMSConstants.VBEAN_SMS_UAT_CUSTOMER_SMS_MESSAGE, m_sCustomerSMSMessage);
				// UAT END

				
				
				
				
				// Insert record into transaction history
				IBLogger.logInetTranHistory(
						this, 
						String.valueOf(m_sTrnxId), //(String)m_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_SERVICE_NAME),
						m_sTrxnType, 
						m_sFromAccNo, 
						"", 
						"", 
						"", 
						String.valueOf(m_sAmount), 
						m_sbDesc.toString (), 
						m_sStatus, 
						m_sMerchantAccNo, 
						"", 
						String.valueOf(m_sEffectiveDATE), 
						getIBSessionObjects ().getRemoteIPAddress (), 
						"", 
						m_boIsResultSuccessful, 
						m_sPhxReferenceNo, 
						"", // Other1
						"", // Other2
						m_sEPayReference, 
						getIBSessionObjects ().getIBSessionId (), 
						m_sRevertReference, 
						"", // PhxChargeRefNo
						"", // PhxChargeRevertRefNo
						"", // FromAccCreateDate
						"", // ToAccCreateDate
						m_sReason,
						m_sPaymentMode,
						m_sPayFrequency,
						m_sTerminationDate,"",""
						);
							
				ibJomPay.setTrxnId(m_sTrnxId);
				ibJomPay.setTrnxType(m_sTrxnType);
				ibJomPay.setTrnxDate(m_sTrxnDate);
				ibJomPay.setUserId(m_sUserId);
				ibJomPay.setEffectiveDate(m_sEffectiveDATE);
				ibJomPay.setBillerCode(m_sBillerCode);
				ibJomPay.setBillerName(m_sBillerName);
				ibJomPay.setBillRefNo1(m_sBillRefNo1);
				ibJomPay.setBillRefNo2(m_sBillRefNo2);
				ibJomPay.setAmount(m_sAmount);
				ibJomPay.setStatus(m_sStatus);
				ibJomPay.setFromAccNo(m_sFromAccNo);
				ibJomPay.setFromCurrency(m_sFromCurrency);
				ibJomPay.setMerchantAccNo(m_sMerchantAccNo);
				ibJomPay.setToCurrency(m_sToCurrency);
				ibJomPay.setPhxReferenceNo(m_sPhxReferenceNo);
				ibJomPay.setPhxrevRefNo(m_sPhxrefRevNo);
				ibJomPay.setRespCode(m_sRespCode);
				ibJomPay.setRespMsg(m_sRespMsg);
				ibJomPay.setServiceCode(m_sServiceCode);
				ibJomPay.setInfo2(m_sInfo2);
				ibJomPay.setInfo3(m_sInfo3);
				ibJomPay.setContactNo(m_sContactNo);
				ibJomPay.setMerchantEmail(m_sMerchantEmail);
				ibJomPay.setSiIndicator(m_sSiIndicator);
				ibJomPay.setRemoteIp(m_sRemoteIp);
				ibJomPay.setOther1(m_sOther1);
				ibJomPay.setOther2(m_sOther2);
				
				HibernateJomPayUtils.insertJomPay(ibJomPay);
				
				selectedMap.put(i, m_oRegisteredJomPayBean);
				
				//New Balance
				viewBean.set(JomPayContants.jomPayAmountBalance, FormatterUtils.formatMoneyDisplay (m_sAccNewBal, null, true));
				viewBean.set(JomPayContants.jomPayTransDate,m_sDate);
				viewBean.set(JomPayContants.jomPayTransTime,m_sTime);
				viewBean.set(JomPayContants.jomPayRegisterViewSelectedMap, selectedMap);
				
				// Start Create Receipt
				if(m_boIsResultSuccessful)
				{
					//Header
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("receipt.transaction.type"), m_sTrxnType);
					
					//Body
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.from"), m_oAccountFrom.get(JomPayContants.jomPayViewAccountNo).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.amount." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewAmountDisplay).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.biller.code." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillerCode).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.biller.holder.name." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillHolderName).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.ref1." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef1).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.account.ref2." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewBillRef2).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.result.status." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayRegisterViewStatus).toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.result.ib.reference." + (i+1)), m_sTrnxId.toString());
					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.result.jomPay.reference." + (i+1)), m_oRegisteredJomPayBean.get(JomPayContants.jomPayOpenViewJomPayRef).toString());
				}
			}
			
			if(m_oReceiptMap.size() > 0)
			{
				//Footer
				m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.result.transaction.date"), viewBean.get(JomPayContants.jomPayTransDate).toString());
				m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib117.result.transaction.time"), viewBean.get(JomPayContants.jomPayTransTime).toString());
				
				IBUtils.loopIntoReceiptDetails (this, m_oReceiptMap, DateTimeUtils.formatIBDateTimeToYMD(dt), m_sTrnxId.toString());
				viewBean.set (CommonConstants.RECEIPT_MAP, m_oReceiptMap);
				m_sReceiptLink = IBUtils.getReceiptLink (JomPayContants.jomPayRegisterForm, JomPayContants.jomPayRegisterView);
				viewBean.set (CommonConstants.RECEIPT_LINK, m_sReceiptLink);
			}
			
			getIBDynaBean().set(JomPayContants.jomPayRegisterView, viewBean);
			
//			#-- added by WS 20141007 start
            try{
            	String ChannelObj = "";
            	Date fromAccCreateDate = null;
            	Date effDate = null;
            	Date toAccCreateDate = null;
            	if(getIBSessionObjects().getHttpSessionAttrObject("ChannelObj") != null)
            	{
            		ChannelObj = getIBSessionObjects().getHttpSessionAttrObject("ChannelObj").toString();
            	}

            	if(ChannelObj.equals("mobileApp"))
	            { 			
           			effDate = m_sEffectiveDATE;
        			
        			MobileTransaction m_oMobileTransaction = new MobileTransaction();
        			m_oMobileTransaction.setDate(new Date());
        			m_oMobileTransaction.setRimNo(rimNo);
        			m_oMobileTransaction.setUsername(getIBSessionObjects ().getVisitor ().getName());
        			m_oMobileTransaction.setCustomerName(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME));
        			m_oMobileTransaction.setIbTransactionId(String.valueOf(m_sTrnxId));
        			m_oMobileTransaction.setTransactionType("2020");
        			m_oMobileTransaction.setFromAccount(m_sFromAccNo);
        			m_oMobileTransaction.setFromCy(m_sFromCurrency);
        			m_oMobileTransaction.setToAccount(m_sMerchantAccNo);
        			m_oMobileTransaction.setToCy(m_sToCurrency);
        			m_oMobileTransaction.setAmount(Double.valueOf(m_sAmount.doubleValue()));
        			m_oMobileTransaction.setStatus(m_sStatus);
        			m_oMobileTransaction.setEffectiveDate(effDate);
        			m_oMobileTransaction.setRemoteIp(getIBSessionObjects ().getRemoteIPAddress ());
        			m_oMobileTransaction.setPhoenixReference(m_sPhxReferenceNo);
        			m_oMobileTransaction.setEpayReference("");
        			m_oMobileTransaction.setPhoenixRevertReferenceNo(m_sPhxrefRevNo);
        			m_oMobileTransaction.setPhoenixChargesReferenceNo("");
        			m_oMobileTransaction.setPhoenixRevertChargesReferen("");
        			m_oMobileTransaction.setDetails("");
        			if(fromAccCreateDate != null)
        				m_oMobileTransaction.setFromAccountCreationDate(fromAccCreateDate);
        			if(toAccCreateDate != null)
        				m_oMobileTransaction.setToAccountCreationDate(toAccCreateDate);
        			m_oMobileTransaction.setType("IN");

        			//JomPay
        			JomPay m_jomPayTransfer = new JomPay();
    				m_jomPayTransfer.setTrnxType(m_sTrxnType);
    				m_jomPayTransfer.setTrnxDate(m_sTrxnDate);
    				m_jomPayTransfer.setUserId(m_sUserId);
    				m_jomPayTransfer.setEffectiveDate(m_sEffectiveDATE);
    				m_jomPayTransfer.setBillerCode(m_sBillerCode);
    				m_jomPayTransfer.setBillerName(m_sBillerName);
    				m_jomPayTransfer.setBillRefNo1(m_sBillRefNo1);
    				m_jomPayTransfer.setBillRefNo2(m_sBillRefNo2);
    				m_jomPayTransfer.setAmount(m_sAmount);
    				m_jomPayTransfer.setStatus(m_sStatus);
    				m_jomPayTransfer.setFromAccNo(m_sFromAccNo);
    				m_jomPayTransfer.setFromCurrency(m_sFromCurrency);
    				m_jomPayTransfer.setMerchantAccNo(m_sMerchantAccNo);
    				m_jomPayTransfer.setToCurrency(m_sToCurrency);
    				m_jomPayTransfer.setPhxReferenceNo(m_sPhxReferenceNo);
    				m_jomPayTransfer.setPhxrevRefNo(m_sPhxrefRevNo);
    				m_jomPayTransfer.setRespCode(m_sRespCode);
    				m_jomPayTransfer.setRespMsg(m_sRespMsg);
    				m_jomPayTransfer.setServiceCode(m_sServiceCode);
    				m_jomPayTransfer.setInfo2(m_sInfo2);
    				m_jomPayTransfer.setInfo3(m_sInfo3);
    				m_jomPayTransfer.setContactNo(m_sContactNo);
    				m_jomPayTransfer.setMerchantEmail(m_sMerchantEmail);
    				m_jomPayTransfer.setSiIndicator(m_sSiIndicator);
    				m_jomPayTransfer.setRemoteIp(m_sRemoteIp);
    				m_jomPayTransfer.setOther1(m_sOther1);
    				m_jomPayTransfer.setOther2(m_sOther2);
    				m_jomPayTransfer.setJomPayRef(jomPayRefNo);
        			HibernateOnlineMobileReportsUtils.insertJomPayTransferStore(m_oMobileTransaction, m_jomPayTransfer);
	            }
            }
        	catch (Exception e)
    		{
        		e.printStackTrace();
    		}
            //#-- aadded by WS 20141007 end
            
		} catch (Exception e) {
			e.printStackTrace();
			if (e instanceof IBGenericException)
			{
				throw (IBGenericException) e;
			}

			throw IBErrorHandler.createServiceException(
					IBServiceException.GENERAL_SERVICE_ERROR, true,
					new String[] {CommonErrorCode.GENERIC_CODE, "", "", "", IBErrorHandler.generateErrorMessage(e)}, c_oClass);
		}
		IBLogger.logBSFNMethodLeavingMessage (c_oClass, m_sMethodName, m_oTimer);
	}
	
	public static String AddIBGNBPSEntry(String channel,String subChannel,String fromAccountNo,String toAccountNo,String amount,
			 String chargeAmount,String toName,String fromName,String rimNo,String paymentDescription,
			 String phnxChargesDesc,String phnxPrincipleDesc,String channelRefNo,String paymentType,String accountTypeInd,
			 String recipientRefNo,String recipientRefNo2,String billerCode,String paymentChannel,String payerType,
			 String chargesCollectionAccount,String jomPayRefNo) throws Exception
	{	
		StringBuffer XMLEntry = new StringBuffer();
		
		XMLEntry.append("<Msg>");
		XMLEntry.append("<channel>").append(channel).append("</channel>");
		XMLEntry.append("<subChannel>").append(subChannel).append("</subChannel>");
		XMLEntry.append("<fromAccountNo>")		.append(fromAccountNo)		.append("</fromAccountNo>");
		XMLEntry.append("<toAccountNo>")		.append(toAccountNo)		.append("</toAccountNo>");
		XMLEntry.append("<amount>")				.append(amount)				.append("</amount>");
		XMLEntry.append("<chargeAmount>")		.append(chargeAmount)		.append("</chargeAmount>");
		XMLEntry.append("<toName><![CDATA[")	.append(toName)				.append("]]></toName>");
		XMLEntry.append("<fromName><![CDATA[")	.append(fromName)			.append("]]></fromName>");
		XMLEntry.append("<rimNo>")				.append(rimNo)				.append("</rimNo>");
		XMLEntry.append("<paymentDescription><![CDATA[").append(paymentDescription)	.append("]]></paymentDescription>");
		XMLEntry.append("<phnxChargesDesc><![CDATA[")	.append(phnxChargesDesc)	.append("]]></phnxChargesDesc>");
		XMLEntry.append("<phnxPrincipleDesc><![CDATA[")	.append(phnxPrincipleDesc)	.append("]]></phnxPrincipleDesc>");
		XMLEntry.append("<channelRefNo>")		.append(channelRefNo)			.append("</channelRefNo>");
		XMLEntry.append("<paymentType>")		.append(paymentType)		.append("</paymentType>");
		XMLEntry.append("<accountType>")		.append(accountTypeInd)		.append("</accountType>");
		XMLEntry.append("<recipientRefNo>")		.append(recipientRefNo)		.append("</recipientRefNo>");
		XMLEntry.append("<recipientRefNo2>")	.append(recipientRefNo2)	.append("</recipientRefNo2>");
		XMLEntry.append("<billerCode>")			.append(billerCode)			.append("</billerCode>");
		XMLEntry.append("<paymentChannel>")		.append(paymentChannel)		.append("</paymentChannel>");
		XMLEntry.append("<payerType>")			.append(payerType)			.append("</payerType>");
		XMLEntry.append("<chargesCollectionAccount>").append(chargesCollectionAccount).append("</chargesCollectionAccount>");
		XMLEntry.append("<jomPayRefNo>")		.append(jomPayRefNo).append("</jomPayRefNo>");
		
		XMLEntry.append("</Msg>");
		
		System.out.println(XMLEntry);
		
		Properties m_oProp = ESBIntegrationConfig.getInstance ().getprop ();
		NBPSWS1ServiceLocator m_oLocator = new NBPSWS1ServiceLocator();
		m_oLocator.setkfhwsEndpointAddress(m_oProp.getProperty ("esb.nbps.ws.path"));
		
		NBPSWS1Service m_oService = m_oLocator;
		NBPSWS1 m_oIBG = m_oService.getkfhws();
		String response = m_oIBG.channelToNBPS(XMLEntry.toString());
		
		System.out.println("request : " + XMLEntry.toString());
		System.out.println("response : "+response);
		return response;
	}
	
	public void readXmlResponse(String xmlResponseDoc)
	{
		Document document;
		try
		{
			document = DocumentHelper.parseText (xmlResponseDoc);
			Element root = document.getRootElement ();
			
			respStatus 				= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespStatus));
			respErrCode 			= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespErrCode));
			respErrMsg 				= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespErrMsg));
			respJomPayRefNo 		= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespJomPayRefNo));
			respDateTime 			= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespDateTime));
			respChannelRefNo 		= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespChannelRefNo));
			respChargeReferenceNo 	= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespChargeRefNo));
			respChargeRespCode 		= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespChargeRespCode));
			respFundReferenceNo 	= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespFundRefNo));
			respFundRespCode 		= IBJomPayUtils.replaceNull(root.elementText(JomPayContants.jomPayWSRespFundRespCode));
		}
		catch (DocumentException e) {
			e.printStackTrace();
		}
	}
}
