/**
 * Copyright (c) 2009 Penril Datability (SEA) Sdn Bhd All rights reserved.
 *
 * This software is copyrighted. Under the copyright laws, this software
 * may not be copied, in whole or in part, without prior written consent
 * of Penril Datability (SEA) Sdn Bhd or its assignees. This software is
 * provided under the terms of a license between Penril Datability (SEA)
 * Sdn Bhd and the recipient, and its use is subject to the terms of that
 * license.
 */
package my.com.kfh.enterprise.services.ib104_fundtransfer.own;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

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.ib104_fundtransfer.thirdparty.IBFundTransferDBUtils;
import my.com.kfh.enterprise.services.ib112_si.IBGenericSIServices;
import my.com.kfh.enterprise.services.ib112_si.SIConstants;
import my.com.kfh.enterprise.services.ib112_si.SI_PAYMENT_MODE;
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.ESBFundTransferOwnBean;
import my.com.kfh.hibernate.tables.onlineMobile.MobileTransaction;
import my.com.kfh.hibernate.tables.onlineMobile.OwnAccountTransfer;
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.DataUtils;
import my.com.kfh.web.utils.DataValidator;
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.IBDynaBeanManager;
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.CurrencyCode;
import my.com.kfh.web.utils.constant.ESBConstants;
import my.com.kfh.web.utils.constant.ServiceInfo;
import my.com.kfh.web.utils.constant.TransactionType;

/**
 * <pre>
 * PROGRAMMER: Maliana Mustapha
 * CHANGE-NO:
 * TASK-NO:
 * DATE CREATED: Oct 23, 2008
 * TAG AS:
 * REASON(S):
 * MODIFICATION:
 * </pre>
 */

/**
 * This class handles the back end process of own account transfer results services.
 */
public class IBOwnTransferResultsServices extends IBEnterpriseServicesWorkspace
{
	private static Class c_oClass = IBOwnTransferResultsServices.class;

	/**
	 * Class constructor specifying session object.
	 *
	 * @param m_oIBSessionObjects Session object contains all information stored in HTTP session
	 */
	public IBOwnTransferResultsServices (IBSessionObjects m_oIBSessionObjects)
	{
		super (m_oIBSessionObjects);
	}

	/**
	 * <pre>
	 * To do Tac verification if the value for requiredTac from service info bean is
	 * equals to true.
	 * Generate the transaction id number, date and time to display to user.
	 * To process the account transfer by calling ESBFundTransferOwnBean object and get
	 * the response code ,status, reference number, new from account balance and new to account balance.
	 * To set all the transaction details for print receipt and insert the receipt details
	 * into table IB_RECEIPT_DETAILS.
	 * Log all transaction details into table IB_INTRA_TRANSFER and IB_TRANSACTION_HISTORY.
	 * Reset the IBSession object for account enquiry so that the changes can be applied.
	 * </pre>
	 *
	 * @throws IBGenericException
	 */
	public void processTransferResults () throws IBGenericException
	{
		String m_sMethodName = "processTransferResults";
		IBTimer m_oTimer = IBLogger.logBSFNMethodEnteringMessage (c_oClass, m_sMethodName);

		String m_sTacValue = "";
		BVI_DateTime m_oCurrentDateTime = null;
		String m_sAmount = "";
		String m_sLocalAmount = "";
		String m_sFromAccount = "";
		String m_sToAccount = "";
		String m_sStatus = "";
		String m_sFromAccNewBal = "";
		String m_sToAccNewBal = "";
		String m_sReferenceNo = "";
		String m_sResponseCode = "";
		String m_sReason = "";
		StringBuffer m_sDetails = new StringBuffer();
		String m_sServiceCode = ServiceInfo.FUND_TRANSFER_OWN;
		String m_sServiceName = TransactionType.FUND_TRANSFER_OWN;
		IBDynaBean m_oViewBean = null;
		IBDynaBean m_oServiceBean = null;
		String m_sFrmAccCrtDt = "";
		String m_sToAccCrtDt = "";

		//si
		String m_sEffectiveDate = null;
		boolean m_boSIIndicator = false;
		String m_sPaymentFrequencyDisplay = null;
		String m_sPayFrequency = null;
		String m_sEffectiveDateDisplay = null;
		String m_sTerminationDate = null;
		String m_sTerminationDateDisplay = null;
		String m_sPaymentModeDisplay = null;
		String m_sPaymentMode = null;

		IBDynaBean m_oOwnAccInfoBean = null;
		String m_sFromAccIsoCurr = CurrencyCode.MALAYSIA_RINGGIT;
		String m_sToAccIsoCurr = CurrencyCode.MALAYSIA_RINGGIT;
		double m_dAmount = 0.00;
		boolean m_boDeleteSIIndicator = false;
		boolean m_boIsResultSuccessful = false;

		double m_dAvailableBal = 0.0;
		double m_dTotalTransferAmount = 0.0;
		boolean m_boIsFundSufficient = true;

		try
		{
			m_oViewBean = (IBDynaBean) getIBDynaBean ().get (IBOwnTransferConstant.OWN_TRANSFER_BEAN);
			if(m_oViewBean == null)
			{
				m_oViewBean = IBDynaBeanManager.createIBDynaBean (IBOwnTransferConstant.OWN_TRANSFER_BEAN, getIBDynaBean ().getActionMapping ());
			}

			m_oCurrentDateTime = DateTimeUtils.getCurrentIBDateTimeObject ();
			m_sEffectiveDate = m_oCurrentDateTime.getSimpleDate ();

			m_sTacValue = (String) getIBDynaBean ().get (IBOwnTransferConstant.TAC_VALUE);
			m_oServiceBean = (IBDynaBean) m_oViewBean.get (ServiceInfo.SERVICE_INFO_BEAN);
			if(m_oServiceBean != null)
			{
				if(((Boolean) m_oServiceBean.get(ServiceInfo.BEAN_ATT_TAC_REQUIRED)).booleanValue ())
				{
					getIBAuthenticationServices ().userVerifyTac (m_sTacValue,getIBSessionObjects().getIBSessionId());
				}

				m_sServiceName = (String) m_oServiceBean.get(ServiceInfo.BEAN_ATT_SERVICE_NAME);
				m_sServiceCode = (String) m_oServiceBean.get (ServiceInfo.BEAN_ATT_SERVICE_CODE);
			}

			m_sPaymentMode = (String)getIBDynaBean ().get (SIConstants.PAY_MODE);
			m_sPaymentModeDisplay = (String)m_oViewBean.get (SIConstants.PAY_MODE_DISPLAY);
			m_sEffectiveDateDisplay = (String)m_oViewBean.get (SIConstants.EFFECTIVE_DATE_DISPLAY);

			if (!SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
			{
				m_boSIIndicator = true;
				m_sServiceName = IBGenericSIServices.getSITransType (m_sServiceName, m_sPaymentMode);

				m_sEffectiveDate = (String)m_oViewBean.get (SIConstants.EFFECTIVE_DATE_FORMAT);

				if (SI_PAYMENT_MODE.RECURRING_PAYMENT.getCode ().equals (m_sPaymentMode))
				{
					m_sPayFrequency = (String)getIBDynaBean ().get (SIConstants.PAY_FREQUENCY);
					m_sPaymentFrequencyDisplay = (String)m_oViewBean.get (SIConstants.PAY_FREQUENCY_DISPLAY);
					m_sTerminationDate = (String) m_oViewBean.get (SIConstants.TERMINATION_DATE_FORMAT);
					m_sTerminationDateDisplay = (String)m_oViewBean.get (SIConstants.TERMINATION_DATE_DISPLAY);
				}
			}

			m_sAmount = (String) getIBDynaBean ().get (IBOwnTransferConstant.AMOUNT);
			m_sFromAccount = (String) getIBDynaBean ().get (IBOwnTransferConstant.FROM_ACCOUNT);
			m_sToAccount = (String) getIBDynaBean ().get (IBOwnTransferConstant.TO_ACCOUNT);

			Map m_oFromAccountsMap = (Map)m_oViewBean.get (IBOwnTransferConstant.FROM_ACCOUNT_MAP);
			m_oOwnAccInfoBean = (IBDynaBean) m_oFromAccountsMap.get (m_sFromAccount);
			m_sFromAccIsoCurr = (String) m_oOwnAccInfoBean.get (CommonConstants.ISO_CURRENCY);

			Map m_oToAccountsMap = (Map)m_oViewBean.get (IBOwnTransferConstant.TO_ACCOUNT_MAP);
			m_oOwnAccInfoBean = (IBDynaBean) m_oToAccountsMap.get (m_sToAccount);
			m_sToAccIsoCurr = (String) m_oOwnAccInfoBean.get (CommonConstants.ISO_CURRENCY);

			m_sLocalAmount = IBFundTransferDBUtils.getLocalAmount (this, m_sToAccIsoCurr, m_sAmount, m_oServiceBean);

			m_oViewBean.set (IBOwnTransferConstant.TRANSACTION_DATE, DateTimeUtils.formatDayMonthYear (m_oCurrentDateTime));
			m_oViewBean.set (IBOwnTransferConstant.TRANSACTION_TIME, m_oCurrentDateTime.getTime ());

			String m_sTransID = IBUtils.getTransactionId (getIBSessionObjects ().getDataManager ());

			if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
			{
				ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
				if (!DataValidator.isEmptyString (m_oTCEnquiryBean.getAvailable_Bal ()))
				{
					m_dAvailableBal = Double.parseDouble (m_oTCEnquiryBean.getAvailable_Bal ());
				}

				m_dTotalTransferAmount = Double.parseDouble (m_sAmount);

				if(m_dAvailableBal < m_dTotalTransferAmount)
				{
					m_boIsFundSufficient = false;
					m_boIsResultSuccessful = false;
					m_sStatus = ResourcesUtils.getUnsuccessful ();
					m_sReason = ResourcesUtils.getApplicationResourceMessage (SIConstants.RESOURCES_INSUFFICIENT_FUND);
				}

				if (m_boIsFundSufficient)
				{
					ESBFundTransferOwnBean m_oOwnTransfer = new ESBFundTransferOwnBean();

					String m_sDescription = ESBConstants.FUND_TRANSFER_OWN;
					m_oOwnTransfer = getESBServices ().ownFundTransfer (m_sFromAccount, m_sToAccount, m_sDescription, m_sAmount, m_sEffectiveDate);

					m_sResponseCode = m_oOwnTransfer.getResponseCode ();
					m_sFromAccNewBal = m_oOwnTransfer.getFromAccountBalance ();
					m_sToAccNewBal = m_oOwnTransfer.getToAccountBalance ();
					m_sReferenceNo = m_oOwnTransfer.getReferenceNo ();

					if (ESBConstants.IB_SUCCESS_RC.equalsIgnoreCase (m_sResponseCode))
					{
						m_boIsResultSuccessful = true;
						m_sStatus = ResourcesUtils.getSuccessful ();
						if(!DataValidator.isEmptyString (m_sFromAccNewBal))
						{
							m_dAmount = Double.parseDouble (m_sFromAccNewBal);
							if(m_dAmount != 0.00)
							{
								m_oViewBean.set(IBOwnTransferConstant.TO_DIS_FROM_ACC_NEW_BAL, Boolean.valueOf(true));
							}
						}

						if(!DataValidator.isEmptyString (m_sToAccNewBal))
						{
							m_dAmount = Double.parseDouble (m_sToAccNewBal);
							if(m_dAmount != 0.00)
							{
								m_oViewBean.set(IBOwnTransferConstant.TO_DIS_TO_ACC_NEW_BAL, Boolean.valueOf(true));
							}
						}
						m_oViewBean.set (IBOwnTransferConstant.FROM_ACC_NEW_BAL,  FormatterUtils.formatMoneyDisplay (m_sFromAccNewBal, m_sFromAccIsoCurr, true));
						m_oViewBean.set (IBOwnTransferConstant.TO_ACC_NEW_BAL, FormatterUtils.formatMoneyDisplay (m_sToAccNewBal, m_sToAccIsoCurr, true));
					}
					else //handle the negative testing,status=UNSUCCESSFUL
					{
						m_boIsResultSuccessful = false;
						m_sStatus = ResourcesUtils.getUnsuccessful ();
						m_sReason = m_oOwnTransfer.getErrorMessage ();
					}
					m_sFrmAccCrtDt = m_oOwnTransfer.getFromAccountCreateDate();
					m_sToAccCrtDt = m_oOwnTransfer.getToAccountCreateDate();
				}
			}//end esb
			else
			{
				m_boIsResultSuccessful = true;
				m_sStatus = ResourcesUtils.getAccepted ();
				m_oViewBean.set(IBOwnTransferConstant.TO_DIS_FROM_ACC_NEW_BAL, Boolean.valueOf(false));
				m_oViewBean.set(IBOwnTransferConstant.TO_DIS_TO_ACC_NEW_BAL, Boolean.valueOf(false));
			}

			m_oViewBean.set (IBOwnTransferConstant.STATUS, m_sStatus);
			m_oViewBean.set (IBOwnTransferConstant.REASON, m_sReason);
			m_oViewBean.set (IBOwnTransferConstant.TRANS_ID, FormatterUtils.formatTransID (m_sTransID));
			m_oViewBean.set (IBOwnTransferConstant.REF_NUMBER, m_sReferenceNo);

			if(m_boIsResultSuccessful)
			{
				Map<String, String> m_oReceiptDetails = new LinkedHashMap <String, String> ();
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("receipt.transaction.type"), m_sServiceName);
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.status"), m_sStatus);
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.fromAccount"), m_sFromAccount);
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.toAccount"), m_sToAccount);
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.amount"), FormatterUtils.formatMoneyDisplay (m_sAmount, m_sFromAccIsoCurr, true));
				if (!DataValidator.isEmptyString (m_sPaymentModeDisplay))
				{
					m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("ib112.si.payment.mode"), m_sPaymentModeDisplay);
				}
				if (!DataValidator.isEmptyString (m_sPaymentFrequencyDisplay))
				{
					m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.payment.frequency"), m_sPaymentFrequencyDisplay);
				}
				if (!DataValidator.isEmptyString (m_sEffectiveDateDisplay))
				{
					m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.start.date"), m_sEffectiveDateDisplay);
				}
				if (!DataValidator.isEmptyString (m_sTerminationDateDisplay))
				{
					m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.terminate.date"), m_sTerminationDateDisplay);
				}
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.reference.number"), FormatterUtils.formatTransID (m_sTransID));
				if(!DataValidator.isEmptyString (m_sReferenceNo))
				{
					m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.reference"), m_sReferenceNo );
				}
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.transaction.date"), (String) m_oViewBean.get (IBOwnTransferConstant.TRANSACTION_DATE) );
				m_oReceiptDetails.put (ResourcesUtils.getApplicationResourceMessage ("general.transaction.time"), (String) m_oViewBean.get (IBOwnTransferConstant.TRANSACTION_TIME));

				//insert into table IB_RECEIPT_DETAILS
				IBUtils.loopIntoReceiptDetails (this, m_oReceiptDetails, m_oCurrentDateTime.getSimpleDate (), m_sTransID);

				m_oViewBean.set (CommonConstants.RECEIPT_MAP, m_oReceiptDetails);

				String m_sReceiptLink = IBUtils.getReceiptLink (IBOwnTransferConstant.OWN_TRANSFER_FORM, IBOwnTransferConstant.OWN_TRANSFER_BEAN);
				m_oViewBean.set (CommonConstants.RECEIPT_LINK, m_sReceiptLink);

			}

			if(!DataValidator.isEmptyString (m_sReferenceNo))
			{
				String m_sRefNoLabel = ResourcesUtils.getApplicationResourceMessage ("general.reference.number.short"); //(Ref No : )
				m_sDetails.append (IBOwnTransferConstant.OWN_ACCOUNT).append ("<br>").append ("(").append (m_sRefNoLabel).append (":").append (m_sReferenceNo).append (")");
			}
			else
			{
				m_sDetails.append (IBOwnTransferConstant.OWN_ACCOUNT);
			}
			
//			 SMS Notification START
			String m_sCustomerSMSMessage = "-";
			String m_sBeneficiarySMSMessage = "-";
			
			String m_sCustomerAmount = SMSServices.formatAmountValue(m_sAmount, m_sFromAccIsoCurr);
			String m_sBeneficiaryAmount = SMSServices.formatAmountValue(m_sAmount, m_sToAccIsoCurr);
			
			String m_sTransactionTypeForSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_OWN);
			
			String beneName = getIBSessionObjects().getVisitor().getName();
			m_sCustomerSMSMessage = SMSServices.generateCustomerSMSMessage(
					m_sTransactionTypeForSMSMessage, 
					m_sCustomerAmount, 
					beneName.length()>15?beneName.substring(0, 15):beneName,
					m_sStatus,
					new Date(),
					FormatterUtils.formatMoneyDisplay (m_sFromAccNewBal, m_sFromAccIsoCurr, true));
			
			SMSServices.sendCustomerSMS(this, 
					m_oViewBean, 
					m_sFromAccount, 
					m_sStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransID,
					m_sAmount, 
					getIBSessionObjects().getVisitor().getId(), 
					m_sCustomerSMSMessage, 
					m_oCurrentDateTime,
					SMSConstants.DEBIT_IB_TYPE);
			
			m_sBeneficiarySMSMessage = SMSServices.generateBeneficiarySMSMessage( 
					m_sTransactionTypeForSMSMessage, 
					m_sBeneficiaryAmount, 
					new Date(), 
					FormatterUtils.formatMoneyDisplay (m_sToAccNewBal, m_sToAccIsoCurr, true));
			
			SMSServices.sendBeneficiarySMS(this, 
					getIBDynaBean(),
					m_oViewBean, 
					m_sFromAccount, 
					m_sStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransID,
					getIBSessionObjects().getVisitor().getId(), 
					m_sBeneficiarySMSMessage, 
					m_oCurrentDateTime,
					SMSConstants.CREDIT_IB_TYPE);
			
			
			ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
			
			m_oViewBean.set (IBOwnTransferConstant.FROM_ACC_NEW_BAL,  FormatterUtils.formatMoneyDisplay (m_oTCEnquiryBean.getAvailable_Bal(), m_sFromAccIsoCurr, true));
			
			// UAT START
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_BENE_SMS_SENT, SMSServices.isSMSLogged(this, m_oViewBean.get(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentDateTime.getDateDDMMMYYYYHMS()));
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_CUSTOMER_SMS_SENT, SMSServices.isSMSLogged(this, m_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentDateTime.getDateDDMMMYYYYHMS()));
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_BENE_SMS_MESSAGE, m_sBeneficiarySMSMessage);
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_CUSTOMER_SMS_MESSAGE, m_sCustomerSMSMessage);
			// UAT END

			// SMS Notification END

			getIBDynaBean ().set (IBOwnTransferConstant.OWN_TRANSFER_BEAN, m_oViewBean);

			//Log into IB_INTRA_TRANSFER
			IBLogger.logTransfer (this,
					m_sTransID,
					m_sServiceName,
					m_oCurrentDateTime,
					m_sFromAccount,
					m_sFromAccIsoCurr,
					m_sToAccount,
					m_sToAccIsoCurr,
					m_sLocalAmount,
					m_sAmount,
					"", "",
					m_sStatus,
					m_sReason,
					DateTimeUtils.convertStringToBVIDateTime (m_sEffectiveDate, "yyyyMMdd"),
					getIBSessionObjects ().getRemoteIPAddress (),
					m_sDetails.toString (),
					m_sReferenceNo,
					m_sServiceCode,
					"",
					"",
					m_sFrmAccCrtDt,
					m_sToAccCrtDt,
					"","",String.valueOf (DataUtils.convertBooleanToInt (m_boSIIndicator)),
					"");

//			//Log into IB_TRANSACTION_HISTORY
			IBLogger.logInetTranHistory (this,
					m_sTransID,
					m_sServiceName,
					m_sFromAccount,
					m_sFromAccIsoCurr,
					m_sToAccount,
					m_sToAccIsoCurr,
					m_sAmount,
					m_sDetails.toString (),
					m_sStatus,
					"","",
					m_sEffectiveDate,
					getIBSessionObjects ().getRemoteIPAddress (),
					"",
					true,
					m_sReferenceNo,
					"",
					"","",
					getIBSessionObjects ().getIBSessionId (),
					"","","",
					m_sFrmAccCrtDt,
					m_sToAccCrtDt,
					m_sReason,
					m_sPaymentMode,
					m_sPayFrequency,
					m_sTerminationDate,
					"","","","","","","","","","");

			if (m_boSIIndicator && m_boIsResultSuccessful)
			{
				IBLogger.logSIDetail (
						this,
						m_sTransID,
						m_sTransID,
						SIConstants.TRANSCODE_OWN_TRANSFER,
						m_sServiceName,
						m_sPaymentMode,
						m_sPayFrequency,
						m_sEffectiveDate,
						m_sTerminationDate,
						"", // No service code for own transfer, cos no transfer limit
						m_boDeleteSIIndicator
						);
			}
			
			
			//#-- added by pixa(joo) 20130111 start
            try{
            	String ChannelObj = "";
            	if(getIBSessionObjects().getHttpSessionAttrObject("ChannelObj") != null)
            	{
            		ChannelObj = getIBSessionObjects().getHttpSessionAttrObject("ChannelObj").toString();
            	}
            	if(ChannelObj.equals("mobileApp"))
	            { 			
        			SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        			Date toAccCreateDate = timestampFormat.parse(m_sToAccCrtDt);
        			Date fromAccCreateDate = timestampFormat.parse(m_sFrmAccCrtDt);
        			String effDateString = HibernateOnlineMobileReportsUtils.convertToDateFormat(m_sEffectiveDate);
        			Date effDate = dateFormat.parse(effDateString);
        			
        			MobileTransaction m_oMobileTransaction = new MobileTransaction();
        			m_oMobileTransaction.setDate(new Date());
        			m_oMobileTransaction.setRimNo(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_RIM_NO));
        			m_oMobileTransaction.setUsername(getIBSessionObjects ().getVisitor ().getName());
        			m_oMobileTransaction.setCustomerName(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME));
        			m_oMobileTransaction.setIbTransactionId(m_sTransID);
        			m_oMobileTransaction.setTransactionType("1040");
        			m_oMobileTransaction.setFromAccount(m_sFromAccount);
        			m_oMobileTransaction.setFromCy(m_sFromAccIsoCurr);
        			m_oMobileTransaction.setToAccount(m_sToAccount);
        			m_oMobileTransaction.setToCy(m_sToAccIsoCurr);
        			m_oMobileTransaction.setAmount(Double.valueOf(Double.parseDouble(m_sAmount)));
        			m_oMobileTransaction.setStatus(m_sStatus);
        			m_oMobileTransaction.setEffectiveDate(effDate);
        			m_oMobileTransaction.setRemoteIp(getIBSessionObjects ().getRemoteIPAddress ());
        			m_oMobileTransaction.setPhoenixReference(m_sReferenceNo);
        			m_oMobileTransaction.setEpayReference("");
        			m_oMobileTransaction.setPhoenixRevertReferenceNo("");
        			m_oMobileTransaction.setPhoenixChargesReferenceNo("");
        			m_oMobileTransaction.setPhoenixRevertChargesReferen("");
        			m_oMobileTransaction.setDetails(m_sDetails.toString ());
        			m_oMobileTransaction.setFromAccountCreationDate(fromAccCreateDate);
        			m_oMobileTransaction.setToAccountCreationDate(toAccCreateDate);
        			m_oMobileTransaction.setType("IN");
        			m_oMobileTransaction.setPaymentMode(m_sPaymentMode);

        			//m_sDescription
        			OwnAccountTransfer m_oOwnAccTransfer = new OwnAccountTransfer();
        			m_oOwnAccTransfer.setRemark("");
        			m_oOwnAccTransfer.setServiceCode(m_sServiceCode);
        			m_oOwnAccTransfer.setRejectMessage(m_sReason);
        			m_oOwnAccTransfer.setAccountHolderName("");
        			m_oOwnAccTransfer.setBeneficiaryEmail("");
        			HibernateOnlineMobileReportsUtils.insertOwnAccTransferStore(m_oMobileTransaction, m_oOwnAccTransfer);
	            }
            }
        	catch (Exception e)
    		{
        		e.printStackTrace();
    		}
            //#-- added by pixa(joo) 20130111 end
            

			getIBSessionObjects ().setAccountEnquiryBean (null);
		}
		catch (Exception e)
		{
			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);
	}

}
