/**
 * Copyright (c) 2010 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.interbank;

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.IBUtilsOnlineAcc;
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.others.IBStdDailyLimitBaseServices;
import my.com.kfh.enterprise.services.ib104_fundtransfer.thirdparty.IBFundTransferDBUtils;
import my.com.kfh.enterprise.services.ib104_fundtransfer.thirdparty.ThirdPartyTransferTags;
import my.com.kfh.enterprise.services.ib106_utility.UtilityConstants;
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.enterprise.services.ib114_online_contest.ContestContants;
import my.com.kfh.enterprise.services.ib116_online_acc.constant.OnlineAccConstants;
import my.com.kfh.enterprise.services.integration.ESBAccountBalanceServices;
import my.com.kfh.enterprise.services.integration.ESBPhoenixWSServices;
import my.com.kfh.error.exception.IBBusinessException;
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.request.ESBRequestAccountBalanceBean;
import my.com.kfh.esb.request.ESBRequestPhoenixWSBean;
import my.com.kfh.esb.response.ESBAccCreateDateBean;
import my.com.kfh.esb.response.ESBAccountBalanceBean;
import my.com.kfh.esb.response.ESBAccountEnquiryTC100Bean;
import my.com.kfh.esb.response.ESBCompanyProfileBean;
import my.com.kfh.hibernate.tables.onlineMobile.InterbankGiroTransfer;
import my.com.kfh.hibernate.tables.onlineMobile.MobileTransaction;
import my.com.kfh.hibernate.utils.HibernateOnlineAccUtils;
import my.com.kfh.hibernate.utils.onlineMobile.HibernateOnlineMobileReportsUtils;
import my.com.kfh.integration.OnlineAccPromoBean;
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.GSTUtils;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBDynaBeanManager;
import my.com.kfh.web.utils.IBLoadProperty;
import my.com.kfh.web.utils.IBLogWriter;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBOfacBlackList;
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.SettingsUtils;
import my.com.kfh.web.utils.constant.BeneficiaryIDType;
import my.com.kfh.web.utils.constant.CurrencyCode;
import my.com.kfh.web.utils.constant.ESBConstants;
import my.com.kfh.web.utils.constant.IBGConstants;
import my.com.kfh.web.utils.constant.ServiceInfo;
import my.com.kfh.web.utils.constant.TransactionType;
import net.penril.bean.IBGEntryRespBean;

/**
 * <pre>
 * PROGRAMMER: Latipah bt Abdul Rashid
 * CHANGE-NO:
 * TASK-NO:
 * DATE CREATED: Dec 13, 2008
 * TAG AS:
 * REASON(S):
 * MODIFICATION:
 * </pre>
 */

/**
 * Send transfer details to host to perform open Interbank transfer.
 */
public class IBInterbankTransferResultsServices extends IBEnterpriseServicesWorkspace
{
	private static Class c_oClass = IBInterbankTransferResultsServices.class;

    private static String VIEWBEAN = InterbankConstants.INTERBANK_TRANSFER_VIEW;

    /**
     * Class constructor specifying session object.
     *
     * @param m_oIBSessionObjects session object containing all information stored in HTTP session and BVHTTP session
     */
	public IBInterbankTransferResultsServices (IBSessionObjects m_oIBSessionObjects)
	{
		super (m_oIBSessionObjects);
	}

    /**
     * Verify TAC and verify amount against maximum limit for transfer.<BR>
     * Perform transfer to host.<BR>
     * If transaction is successful, create transfer receipt and if schedule date is today, send email to recipient.<BR>
     * Then, logs transaction details.
     *
     * @throws IBGenericException
     */
    public void processTransferResult () throws IBGenericException
    {
        String m_sMethodName = "processTransferResult";
        IBTimer m_oTimer = IBLogger.logBSFNMethodEnteringMessage (c_oClass, m_sMethodName);

        IBDynaBean m_oViewBean = null;

        IBDynaBean m_oServiceInfoBean = null;
        String m_sServiceName = TransactionType.FUND_TRANSFER_INTER;
        String m_sServiceMaxLimit = "";
        String m_sServiceCode = "";
        String m_sServiceCharges = null;
        String gstCharges = null;

        BVI_DateTime m_oCurrentBVIDateTime = null;
        IBGEntryRespBean m_oIBGEntryRespBean = new IBGEntryRespBean ();
        String m_sTransStatus = ResourcesUtils.getUnsuccessful ();
        String m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
        String m_sTransStatusMsg = "";
        String m_sFromAccount = "";
        String m_sFromAccountCreateDate = "";
        String m_sBeneBankCode = "";
        String m_sBeneBankDis = "";
        String m_sBeneAccountNo = "";
        String m_sBeneHolderName = "";
        String m_sBeneID = "";
        String m_sAmount = "0";
        String m_sAmountDis = "";
        String m_sUserTransactionRefNo = "";
        String m_sTransactionDesc ="";
        String m_sHostRefNo = "";
        String m_sNewBalance = "";
        String m_sTransId = "";
        String m_sFormattedTransId = "";
        String m_sSuccessMsg = "";
        String m_sEffectiveDate = "";
        boolean m_boEnableVerification = false;
        String m_sBankRouteNo = "";
        String m_sResidency = "";
        String m_sElementCode = "";
        String m_sSegmentCode = "";
        String m_sRimNo = "";
        String m_sIbgTransID = "";
        String m_sChargesRefNo = "";
        String m_sActualStatus = "";
        String gstChargesRefNo = "";

		boolean m_boSIIndicator = false;
		String m_sPaymentFrequencyDisplay = null;
		String m_sPaymentFrequency = null;
		String m_sTerminationDate = null;
		String m_sTerminationDateDisplay = null;
		String m_sEffectiveDateDisplay = null;
		String m_sEmail = "";

		String m_sBeneIdType = null;
		String m_sBeneIdTypeDisplay = null;
		String m_sBeneIdNewIC = null;
		String m_sBeneIdOldIC = null;
		String m_sBeneIdBusReg = null;
		String m_sBeneIdOtherId = null;

        String m_sFromIsoCurrency = CurrencyCode.MALAYSIA_RINGGIT; //defaulted to MYR
        String m_sToIsoCurrency = CurrencyCode.MALAYSIA_RINGGIT; //defaulted to MYR
//        String m_sServiceCodeStdLim = ServiceInfo.FUND_TRANSFER_STANDARD_DAILY_LIMIT;
        //to acct iso currency -> where to get??

        String m_sDateDis = "";
        String m_sTimeDis = "";
        boolean m_boIsResultSuccessful = Boolean.FALSE;
        boolean m_boIsDisplayNewBalance = Boolean.FALSE;
        Float m_fUserLimit = null;
        Map<String, String> m_oReceiptMap = new LinkedHashMap<String, String> ();
        StringBuffer m_sbLogDetails = new StringBuffer ();

        double m_dCharges = 0.0;
        double m_dAvailableBal = 0.0;
        double m_dTransferAmount = 0.0;
		double m_dTotalTransferAmount = 0.0;
		boolean m_boIsFundSufficient = true;
		boolean m_bContestFlag = false;
		double m_dGSTCharges = 0.0;

		String m_sSIServiceMaxLimit = null;
		IBDynaBean m_oSIServiceInfoBean = null;
		boolean m_boIsScheduler = false;
		String m_sSIServiceCode = null;
		String m_sIsStaffAccount = "";
		long m_sUserId = 0;
		Float userDailyLimit= null;
		Float specialDailyLimit= null;
		String residencyType = "";
		String senderName = "";
		String gstAbsorbedAmount = "";
		
		OnlineAccPromoBean onlineAccPromoBean = null;//#-- added by pixa 20121017 
		
        try
        {
            m_oViewBean = (IBDynaBean) getIBDynaBean ().get (VIEWBEAN) == null
                ? IBDynaBeanManager.createIBDynaBean (VIEWBEAN, getIBDynaBean ().getActionMapping ())
                        : (IBDynaBean) getIBDynaBean ().get (VIEWBEAN);
                
                m_sRimNo = (String)getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.RIM_NO);
        		m_sUserId = (long)getIBSessionObjects().getVisitor().getId();
        		userDailyLimit = IBUtils.getUserDailyLimit(this, m_sUserId);
        		ESBCompanyProfileBean residencyByRim = getESBServices ().getProfileByAccRim(null, m_sRimNo);
	    		residencyType = residencyByRim.getResidency();
    			specialDailyLimit = IBUtils.getSpecialDailyLimit(this, m_sUserId);
    			specialDailyLimit = IBStdDailyLimitBaseServices. getSystemDailyLimit(this, getIBDynaBean (), getIBSessionObjects (), residencyType , specialDailyLimit);
    			senderName = (String) m_oViewBean.get(InterbankConstants.SENDER_NAME);
    			gstAbsorbedAmount = (String) m_oViewBean.get(InterbankConstants.GST_CHARGES_WITHOUT_ROUNDING);
    			
    			
	    		
                
            if (m_oViewBean != null)
            {
                m_oServiceInfoBean = (IBDynaBean) m_oViewBean.get (ServiceInfo.SERVICE_INFO_BEAN);
            }

            if (InterbankConstants.TRANSFER_TYPE_OPEN.equalsIgnoreCase ((String) m_oViewBean.get (InterbankConstants.TRANSFER_TYPE)))
            {
            	m_sServiceCode = ServiceInfo.FUND_TRANSFER_INTER_OPEN;
            	m_sSIServiceCode = ServiceInfo.SI_INTER_OPEN_LIMIT;
            }
            else if (InterbankConstants.TRANSFER_TYPE_REG.equalsIgnoreCase ((String) m_oViewBean.get (InterbankConstants.TRANSFER_TYPE)))
            {
            	m_sServiceCode = ServiceInfo.FUND_TRANSFER_INTER_FAV;
            	m_sSIServiceCode = ServiceInfo.SI_INTER_FAV_LIMIT;
            }
            
            if (m_oServiceInfoBean != null)
            {
                /*
                 * UPASS Verify TAC
                 */
                if (((Boolean) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_TAC_REQUIRED)).booleanValue ())
                {
                    getIBAuthenticationServices ().userVerifyTac ((String)getIBDynaBean ().get (UtilityConstants.TAC_VALUE),getIBSessionObjects().getIBSessionId());
                }

                /*
                 * get max limit if not empty
                 */
                if (!DataValidator.isEmptyString ((String) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_MAX_LIMIT)))
                {
                	m_sServiceMaxLimit = (String) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_MAX_LIMIT);
                }

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

            m_oCurrentBVIDateTime = new BVI_DateTime();
            m_sDateDis = DateTimeUtils.formatDayMonthYear (m_oCurrentBVIDateTime);
            m_sTimeDis = m_oCurrentBVIDateTime.getTime ();

            m_sEffectiveDate = m_oCurrentBVIDateTime.getSimpleDate ();
            m_sEffectiveDateDisplay = m_sDateDis;

            m_sFromAccount = (String) getIBDynaBean ().get (InterbankConstants.FROM_ACCOUNT);
            
            m_sIsStaffAccount = (String) m_oViewBean.get(InterbankConstants.IS_STAFF_ACCOUNT);
            
            if(ESBConstants.ACC_NONSTAFF.equalsIgnoreCase(m_sIsStaffAccount))
            {

            	m_sServiceCharges = (String) m_oViewBean.get (InterbankConstants.SERVICE_CHARGES);
            	gstCharges = (String) m_oViewBean.get (InterbankConstants.GST_CHARGES);

            	
            	//#-- added by pixa 20121017 start --remember to include import at top
            	onlineAccPromoBean = IBUtilsOnlineAcc.getChargesIfIsOnlineAccount(this,m_sFromAccount, OnlineAccConstants.IBG);
            	if(onlineAccPromoBean !=null){
            		m_sServiceCharges = onlineAccPromoBean.getPromotionCharges();
            	}
            	//#-- added by pixa 20121017 end -- 
            }
			
			 if(DataValidator.isEmptyString(gstCharges))
            {
            	gstCharges = "0";
            }
            
            m_sAmount = (String) getIBDynaBean ().get (InterbankConstants.AMOUNT);
            m_sAmountDis = (String) m_oViewBean.get (InterbankConstants.AMOUNT_DIS);
            m_sBeneBankCode = (String) getIBDynaBean ().get (InterbankConstants.BENE_BANK);
            m_sBeneBankDis = (String) m_oViewBean.get (InterbankConstants.BENE_BANK_DIS);
            m_sBeneAccountNo = (String) getIBDynaBean ().get (InterbankConstants.BENE_ACCOUNT_NO);
            m_sBeneHolderName = (String) m_oViewBean.get (InterbankConstants.BENE_NAME);
//            m_sBeneID = (String) m_oViewBean.get (InterbankConstants.BENE_ID);
            m_sUserTransactionRefNo = (String) getIBDynaBean ().get (InterbankConstants.TRANSACTION_REF_NO);
            m_sTransactionDesc = (String) getIBDynaBean ().get (InterbankConstants.TRANSACTION_DESC);
            m_sFromIsoCurrency = (String) m_oViewBean.get (InterbankConstants.FROM_ISO_CURRENCY);
            m_boEnableVerification = ((Boolean) getIBDynaBean ().get (InterbankConstants.ENABLE_VERIFICATION)).booleanValue ();
            m_sBankRouteNo = (String) m_oViewBean.get (InterbankConstants.BANK_ROUTE_NUMBER);
            m_sBeneIdType = (String) getIBDynaBean ().get (InterbankConstants.BENE_ID_TYPE);
            m_sBeneIdTypeDisplay = BeneficiaryIDType.getDescription (m_sBeneIdType);
            m_sEmail = (String) getIBDynaBean ().get (InterbankConstants.BENEFICIARY_EMAIL);

            //ibg transform
    		m_sBeneIdNewIC = (String) getIBDynaBean() .get (InterbankConstants.NEW_IC);
    		m_sBeneIdOldIC = (String) getIBDynaBean() .get (InterbankConstants.OLD_IC);
    		m_sBeneIdBusReg = (String) getIBDynaBean() .get (InterbankConstants.BUSINESS_REG);
    		m_sBeneIdOtherId = (String) getIBDynaBean() .get (InterbankConstants.OTHER_ID);

            /*
             * get transaction ID
             */
            m_sTransId = IBUtils.getTransactionId (getIBSessionObjects ().getDataManager ());
            m_sFormattedTransId = FormatterUtils.formatTransID (m_sTransId);

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

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

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

            /*
             * check blacklisted beneficiary name
             */
            if (IBFundTransferDBUtils.isNameBlacklisted (this, m_sBeneHolderName))
			{
            	m_boIsResultSuccessful = Boolean.FALSE;
            	m_sActualStatus = IBOfacBlackList.BLACK_LISTED;

                m_sTransStatus = ResourcesUtils.getUnsuccessful ();
                m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
                m_sTransStatusMsg = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.INTERBANK_TRANSFER, InterbankConstants.ERR_BLACKLISTED_BENE_NAME);
			}
            else
            {
            	if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
                {
	    			/*
	    			 * check daily limit based on Interbank transfer (combine open and registered interbank - FUNOER+FUNFER against INTERLIM)
	    			 */
            		Map m_oBankLimitReturnMap = IBGenericInterbankServices.checkInterbankTransferDailyLimit (this,
    	            		getIBDynaBean (), getIBSessionObjects (), m_sAmount, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler , residencyType);
	    			/*
	                 * check daily limit based on service code (open interbank, registered interbank separately - FUNFER, FUNOER)
	                 */
	                m_fUserLimit = IBFundTransferDBUtils.getUserTransferLimit (getIBSessionObjects (), m_sServiceCode, m_boIsScheduler);

	                Map m_oUserLimitReturnMap = IBGenericInterbankServices.checkInterbankTransferDailyLimitByServiceCode (this,
		            		m_sAmount, m_sServiceMaxLimit, m_fUserLimit, m_sServiceCode, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler,
		            		residencyType, m_oBankLimitReturnMap);
	                
	              //check daily limit
	    			
	    			Map m_oStdBankingLimitReturnMap = IBStdDailyLimitBaseServices.checkBankDailyLimit(this, getIBDynaBean (), 
		            		getIBSessionObjects (), m_sAmount ,specialDailyLimit, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler, residencyType);
		            
		            Map m_oStdUserLimitReturnMap = IBStdDailyLimitBaseServices.checkUserDailyLimit(this, getIBDynaBean (), 
		            		getIBSessionObjects (), m_sAmount , userDailyLimit, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler);

		            if (!((Boolean) m_oUserLimitReturnMap.get (InterbankConstants.STATUS)).booleanValue ())
	                {
	                	m_boIsResultSuccessful = Boolean.FALSE;

	                    m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_CHANGE_MAX_AMOUNT,
	 	                		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oUserLimitReturnMap.get (InterbankConstants.MAX_LIMIT),
	 	                				CurrencyCode.MALAYSIA_RINGGIT, true) });
	                }
		            else if ((!((Boolean) m_oBankLimitReturnMap.get (InterbankConstants.STATUS)).booleanValue ())&&(0 <= specialDailyLimit.floatValue()))
	    			{
	    				m_boIsResultSuccessful = Boolean.FALSE;

	                    m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusMsg = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.INTERBANK_TRANSFER,
	                    		InterbankConstants.ERR_BANK_MAX_AMOUNT,
	                    		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oBankLimitReturnMap.get (InterbankConstants.MAX_LIMIT),
	                    				CurrencyCode.MALAYSIA_RINGGIT, true) });
	    			}
		            else if (!((Boolean) m_oStdUserLimitReturnMap.get (ThirdPartyTransferTags.STATUS)).booleanValue ())
	 	            {
	 	            	m_boIsResultSuccessful = false;

	 	                m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	 	               m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	 	                m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_USER_STD_LIMIT,
	 	                		new String [] { FormatterUtils.formatMoneyDisplay (String.valueOf(specialDailyLimit),
	 	                				CurrencyCode.MALAYSIA_RINGGIT, true) });
	 	            }
	    			else if ((!((Boolean) m_oStdBankingLimitReturnMap.get (InterbankConstants.STATUS)).booleanValue ()))
	 	            {
	 	            	m_boIsResultSuccessful = false;
	  
	 	                m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	 	               m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	 	                m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_BANK_STD_LIMIT,
	 	                		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oStdBankingLimitReturnMap.get (ThirdPartyTransferTags.MAX_LIMIT),
	 	                				CurrencyCode.MALAYSIA_RINGGIT, true) });	
	 	            }
	                else
	                {
    					ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
    					if (!DataValidator.isEmptyString (m_oTCEnquiryBean.getAvailable_Bal ()))
    					{
    						m_dAvailableBal = Double.parseDouble (m_oTCEnquiryBean.getAvailable_Bal ());
    					}

    					m_dTransferAmount = Double.parseDouble (m_sAmount);
    					if(!DataValidator.isEmptyString (m_sServiceCharges) && DataValidator.isValidNumber (m_sServiceCharges))
    					{
    						m_dCharges = Double.parseDouble (m_sServiceCharges);
    					}
    					if(!DataValidator.isEmptyString (gstCharges) && DataValidator.isValidNumber (gstCharges))
    					{
    						m_dGSTCharges = Double.parseDouble (gstCharges);
    					}

    					m_dTotalTransferAmount = m_dTransferAmount + m_dCharges + m_dGSTCharges;

    					if(m_dAvailableBal < m_dTotalTransferAmount)
    					{
    						m_boIsFundSufficient = false;
    						m_boIsResultSuccessful = false;
    						m_sTransStatus = ResourcesUtils.getUnsuccessful ();
    						m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
    						m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (SIConstants.RESOURCES_INSUFFICIENT_FUND);
    					}

    					if (m_boIsFundSufficient)
    					{
		                	m_sRimNo = (String) getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.RIM_NO);

		                	/*
		                	 * get Segment Code
		                	 * R = 0, N = 1
		                	 */
		                	ESBCompanyProfileBean m_oESBCompanyProfileBean = getESBServices ().getProfileByAccRim (null, m_sRimNo);
		                	m_sResidency = m_oESBCompanyProfileBean.getResidency ();

		                	m_sElementCode = IBGConstants.ELEMENT_CODE_RESIDENCY;
		                	if (!DataValidator.isEmptyString (m_sResidency) && m_sResidency.equalsIgnoreCase (InterbankConstants.NON_RESIDENCY_TYPE))
		    				{
		    					m_sElementCode = IBGConstants.ELEMENT_CODE_NON_RESIDENCY;
		    				}

		                	/*
		                	 * get Element Code
		                	 * enable = 5, disable = 1
		                	 */
		                	m_sSegmentCode = IBGConstants.SEGMENT_CODE_NON_VERIFICATION_BANK;
		    				if (m_boEnableVerification)
		    				{
		    					m_sSegmentCode = IBGConstants.SEGMENT_CODE_VERIFICATION_BANK;
		    				}

		    				/*
		    				 * set the Bene ID Type to the correct field
		    				 */
		    				if (BeneficiaryIDType.isNewIC (m_sBeneIdType))
		    				{
		    					m_sBeneIdNewIC = m_sBeneID;
		    				}
		    				else if (BeneficiaryIDType.isOldIC (m_sBeneIdType))
		    				{
		    					m_sBeneIdOldIC = m_sBeneID;
		    				}
		    				else if (BeneficiaryIDType.isBusinessRegistrationNo (m_sBeneIdType))
		    				{
		    					m_sBeneIdBusReg = m_sBeneID;
		    				}
		    				else if (BeneficiaryIDType.isOtherID (m_sBeneIdType))
		    				{
		    					m_sBeneIdOtherId = m_sBeneID;
		    				}

		    				String transferGstCharges = "N";
		    				if(!DataValidator.isEmptyString(gstCharges)){
		    						transferGstCharges = "Y";
		    				}
		    				m_oIBGEntryRespBean = getIBGServices ().insertIBGEntry (
		    						m_sFromAccount,
		    						getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME),
		    						m_sBeneAccountNo,
		    						m_sBeneHolderName,
		    						m_sServiceCharges,
		    						m_sAmount,
		    						m_sEffectiveDate,
		    						IBGConstants.CHANNEL_ID_INTERNET_BANKING,
		    						IBGConstants.SUB_CHANNEL_ID_IB,
		    						m_sSegmentCode,
		    						m_sElementCode,
		    						m_sBeneID,
		    						m_sTransId,
		    						m_sBankRouteNo,
		    						m_sPaymentMode,
		    						m_sUserTransactionRefNo,
		    						m_sTransactionDesc,
		    						m_sRimNo,
		    						IBUtils.getBranchCodeByAccNo (m_sFromAccount),
		    						m_sBeneIdNewIC,
		    						m_sBeneIdOldIC,
		    						m_sBeneIdBusReg,
		    						m_sBeneIdOtherId,
		    						null, null, null, null,
		    						gstCharges
		    						);
		    				m_sIbgTransID = m_oIBGEntryRespBean.getOid ();

		    				if (IBGConstants.IBG_RC_SUCCESS.equals (m_oIBGEntryRespBean.getRespCode ())
		    						|| IBGConstants.IBG_FUTURE_RC_SUCCESS.equals (m_oIBGEntryRespBean.getRespCode ()))
		    				{
		    					m_boIsResultSuccessful = Boolean.TRUE;
		    					m_sHostRefNo = m_oIBGEntryRespBean.getFundReferenceNo ();
		        				m_sChargesRefNo = m_oIBGEntryRespBean.getChargeReferenceNo ();
		        				gstChargesRefNo = m_oIBGEntryRespBean.getGstChargeReferenceNo();

		    					if (!m_boSIIndicator)
		    					{
		    						m_boIsDisplayNewBalance = true;

		        					// TC: 132 - Account Balance
		        					ESBRequestAccountBalanceBean m_oBeanReq = new ESBRequestAccountBalanceBean ();
		        					ESBAccountBalanceServices m_oESBAccountBalanceServices = new ESBAccountBalanceServices ();
		        					ESBAccountBalanceBean m_oBeanResp = null;
		        					// From Account Balance
		        					m_oBeanReq.setAccountNo (m_sFromAccount);
		        					m_oBeanReq.setRimNo (m_sRimNo);
		        					m_oBeanResp = m_oESBAccountBalanceServices.retrieve (m_oBeanReq);
		        					m_sNewBalance = FormatterUtils.formatMoneyDisplay (
		        							DataValidator.isEmptyString (m_oBeanResp.getAvailableBalance ()) ? "0"
		        									: m_oBeanResp.getAvailableBalance ().trim (),
		        									m_sFromIsoCurrency, true);
		    					}

		    					// Account Creation Date
		    					ESBPhoenixWSServices m_oESBPhoenixWSServices = new ESBPhoenixWSServices();
		    					ESBRequestPhoenixWSBean m_oRequest = new ESBRequestPhoenixWSBean();
		    					// From Account Creation Date
		    					m_oRequest.setAcctNo (m_sFromAccount);
		    					ESBAccCreateDateBean m_oAccCreateDateBean = m_oESBPhoenixWSServices.getAccCreateDate (m_oRequest);
		    					m_sFromAccountCreateDate = m_oAccCreateDateBean.getDtAccOpen();
		    				}
		    				else
		    				{
		    					m_boIsResultSuccessful = Boolean.FALSE;
		    					m_sTransStatus = ResourcesUtils.getUnsuccessful ();
		    					m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
		    					m_sTransStatusMsg = m_oIBGEntryRespBean.getRespMsg ();
		    				}
    					}
	                }
                }
    			else	// create SI transaction
				{
    				m_sServiceCode = m_sSIServiceCode;
    				m_oSIServiceInfoBean = IBUtils.getServiceInfoBean (m_sServiceCode, getIBDynaBean (), getIBSessionObjects (), false);
    	            m_sSIServiceMaxLimit = (String) m_oSIServiceInfoBean.get (ServiceInfo.BEAN_ATT_MAX_LIMIT);

    				/*
	    			 * check daily limit based on Interbank transfer (combine open and registered interbank - SIFUNOER+SIFUNFER against SIINTERLIM)
	    			 */
            		Map m_oSIBankLimitReturnMap = IBGenericInterbankServices.checkInterbankTransferDailyLimit (this,
    	            		getIBDynaBean (), getIBSessionObjects (), m_sAmount, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler , residencyType);
	    			/*
	                 * check daily limit based on service code (open interbank, registered interbank separately - SIFUNFER, SIFUNOER)
	                 */
	                m_fUserLimit = IBFundTransferDBUtils.getUserTransferLimit (getIBSessionObjects (), m_sServiceCode, m_boIsScheduler);

	                Map m_oSIUserLimitReturnMap = IBGenericInterbankServices.checkInterbankTransferDailyLimitByServiceCode (this,
		            		m_sAmount, m_sSIServiceMaxLimit, m_fUserLimit, m_sServiceCode, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler,
		            		residencyType, m_oSIBankLimitReturnMap);
	                
		            //check daily limit
	    			
	    			Map m_oStdBankingLimitReturnMap = IBStdDailyLimitBaseServices.checkBankDailyLimit(this, getIBDynaBean (), 
		            		getIBSessionObjects (), m_sAmount ,specialDailyLimit, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler, residencyType);
		            
		            Map m_oStdUserLimitReturnMap = IBStdDailyLimitBaseServices.checkUserDailyLimit(this, getIBDynaBean (), 
		            		getIBSessionObjects (), m_sAmount , userDailyLimit, m_sEffectiveDate, m_boSIIndicator, m_boIsScheduler);
		            
		            if (!((Boolean) m_oSIUserLimitReturnMap.get (InterbankConstants.STATUS)).booleanValue ())
	                {
	                	m_boIsResultSuccessful = Boolean.FALSE;

	                    m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_CHANGE_MAX_AMOUNT,
	 	                		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oSIUserLimitReturnMap.get (SIConstants.MAX_LIMIT),
	 	                				CurrencyCode.MALAYSIA_RINGGIT, true) });
	                }
		            else if ((!((Boolean) m_oSIBankLimitReturnMap.get (InterbankConstants.STATUS)).booleanValue ())&&(0 <= specialDailyLimit.floatValue()))
	    			{
	    				m_boIsResultSuccessful = Boolean.FALSE;

	                    m_sTransStatus = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
	                    m_sTransStatusMsg = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.SI, SIConstants.ERR_BANK_MAX_LIMIT,
								new String [] { FormatterUtils.formatMoneyDisplay ( (String)m_oSIBankLimitReturnMap.get (SIConstants.MAX_LIMIT),
										null, true) });
	    			}
		            else if (!((Boolean) m_oStdUserLimitReturnMap.get (ThirdPartyTransferTags.STATUS)).booleanValue ())
		            {
		            	m_boIsResultSuccessful = false;

		                m_sTransStatus = ResourcesUtils.getUnsuccessful ();
		                m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
		                m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_USER_STD_LIMIT,
	 	                		new String [] { FormatterUtils.formatMoneyDisplay (String.valueOf(specialDailyLimit) ,
	 	                				CurrencyCode.MALAYSIA_RINGGIT, true) });
		                
//		                m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_USER_STD_LIMIT,
//		                		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oStdUserLimitReturnMap.get (ThirdPartyTransferTags.MAX_LIMIT),
//		                				CurrencyCode.MALAYSIA_RINGGIT, true) });
		            }
	    			else if ((!((Boolean) m_oStdBankingLimitReturnMap.get (ThirdPartyTransferTags.STATUS)).booleanValue ()))
		            {
		            	m_boIsResultSuccessful = false;
	 
		                m_sTransStatus = ResourcesUtils.getUnsuccessful ();
		                m_sTransStatusDisplay = ResourcesUtils.getUnsuccessful ();
		                m_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (ThirdPartyTransferTags.ERR_BANK_STD_LIMIT,
		                		new String [] { FormatterUtils.formatMoneyDisplay ((String) m_oStdBankingLimitReturnMap.get (ThirdPartyTransferTags.MAX_LIMIT),
		                				CurrencyCode.MALAYSIA_RINGGIT, true) });	
		            }
	                else
	                {
	                	//SI created. Will pending on scheduler.
						m_boIsResultSuccessful = Boolean.TRUE;
	                }
				}
            }

            if (m_boIsResultSuccessful)
            {
            	m_sTransStatus = ResourcesUtils.getAccepted ();
            	m_sTransStatusDisplay = ResourcesUtils.getApplicationResourceMessage ("general.status.accepted.for.processing");
            	if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
                {
	            	/*
	            	 * email transfer notification to beneficiary
	            	 */
	            	if (!DataValidator.isEmptyString (m_sEmail))
	                {
	    				String m_sSubject = ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.email.subject");
	                	String m_sCustomerName = getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME);

	                	StringBuffer m_sbEmailMsg = new StringBuffer ();
	                	m_sbEmailMsg.append (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.email.greetCustomer", new String [] {m_sSubject, m_sBeneHolderName} ));
	                	m_sbEmailMsg.append (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.email.note1",
	                			new String [] {m_sCustomerName,
	                				DateTimeUtils.formatDayMonthYear (m_oCurrentBVIDateTime).concat (" ").concat (m_oCurrentBVIDateTime.getTime()) } ));

	                	IBLogWriter m_oTableCreater = new IBLogWriter();
	           			m_sbEmailMsg.append (m_oTableCreater.RowCreater ("S", ResourcesUtils.getApplicationResourceMessage ("general.status"), m_sTransStatusDisplay, null, null)).append("\n");
	                	m_sbEmailMsg.append (m_oTableCreater.RowCreater ("C", ResourcesUtils.getApplicationResourceMessage ("general.amount"), m_sAmountDis, null, null)).append("\n");
	                	m_sbEmailMsg.append (m_oTableCreater.RowCreater ("C", ResourcesUtils.getApplicationResourceMessage ("general.reference.number"), FormatterUtils.formatTransID (m_sFormattedTransId), null, null)).append("\n");
	                	if(!DataValidator.isEmptyString (m_sHostRefNo))
	    				{
	                		m_sbEmailMsg.append (m_oTableCreater.RowCreater ("C", ResourcesUtils.getApplicationResourceMessage ("general.reference"), m_sHostRefNo, null, null)).append("\n");
	    				}
						m_sbEmailMsg.append (m_oTableCreater.RowCreater ("C", ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.bank"), m_sBeneBankDis, null, null)).append("\n");
	                	m_sbEmailMsg.append (m_oTableCreater.RowCreater ("C", ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.recipient.ref"),
								DataValidator.isEmptyString (m_sTransactionDesc) ? "-" : m_sTransactionDesc, null, null)).append("\n");
	                	m_sbEmailMsg.append (m_oTableCreater.RowCreater ("E", ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.payment.desc"),
	                			DataValidator.isEmptyString (m_sUserTransactionRefNo) ? "-" : m_sUserTransactionRefNo , null, null)).append("\n");		

	                	m_sbEmailMsg.append (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.email.note2"));
	                	m_sbEmailMsg.append (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.email.disclaimer"));

	                	IBUtils.sendEmail (this, null, m_sEmail, m_sSubject, m_sbEmailMsg.toString (), m_sTransStatus, null);
	                }
	            	
	            	//Checking Contest module
	                String m_sContestAmount = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_AMOUNT);
	                if(m_boIsResultSuccessful)
	                {
	    				if(Double.parseDouble (m_sAmount)>Double.parseDouble (m_sContestAmount)
	    						|| Double.parseDouble (m_sAmount)== Double.parseDouble (m_sContestAmount))
	    				{
	    					//check whether Contest is ON/OFF
	    					String m_sContestFlag = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_FLAG);
	    					
	    					if(m_sContestFlag.equalsIgnoreCase(ContestContants.ONLINE_CONTEST_ON))
	    					{
	    						//Check Date start & end date
	    						Date m_oTodayDate = new Date();
	    						String m_sStartDate = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_START_DATE);
	    						String m_sEndDate = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_END_DATE);
	    						
	    						SimpleDateFormat m_oSDF = new SimpleDateFormat("dd/MM/yyyy");
	    						
	    						Date m_oStartDate = m_oSDF.parse(m_sStartDate);
	    						Date m_EndDate = m_oSDF.parse(m_sEndDate);
	    						
	    						if(m_oTodayDate.compareTo(m_oStartDate) > 0 && m_oTodayDate.compareTo(m_EndDate) < 0)
	    						{
	    							m_bContestFlag = true;
	    						}
	    					}
	    				}
	                }
	    			m_oViewBean.set (ContestContants.IS_CONTEST_ON, m_bContestFlag);
	    			getIBDynaBean().set("trnxId", m_sTransId);
	    			getIBDynaBean().set("trnxType", m_sServiceName);
                }

                /*
                 * receipt
                 */
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("receipt.transaction.type"), m_sServiceName);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.sender.name"), senderName);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.holder.name"), m_sBeneHolderName);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.status"), m_sTransStatusDisplay);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.amount"), m_sAmountDis);
                if(!"-".equalsIgnoreCase((String)m_oViewBean.get(InterbankConstants.SERVICE_CHARGES_DISP)))
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.charges"), (String)m_oViewBean.get(InterbankConstants.SERVICE_CHARGES_DISP));
                
                if(!"-".equalsIgnoreCase((String)m_oViewBean.get(InterbankConstants.GST_CHARGES_DIS)))
                {
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.gst.charges"), (String)m_oViewBean.get(InterbankConstants.GST_CHARGES_DIS));
                }

                if (!DataValidator.isEmptyString (m_sTransactionDesc))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.recipient.ref"), m_sTransactionDesc);
				}
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.bank"), m_sBeneBankDis);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.acct.no"), m_sBeneAccountNo);
//                if (!DataValidator.isEmptyString (m_sBeneID))
//				{
//                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.id"), m_sBeneID);
//				}
//                if (!DataValidator.isEmptyString (m_sBeneIdTypeDisplay))
//				{
//					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.bene.id.type"), m_sBeneIdTypeDisplay);
//				}
                if (!DataValidator.isEmptyString (m_sBeneIdNewIC))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.new.ic"), m_sBeneIdNewIC);
				}
                if (!DataValidator.isEmptyString (m_sBeneIdOldIC))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.old.ic"), m_sBeneIdOldIC);
				}
                if (!DataValidator.isEmptyString (m_sBeneIdBusReg))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.business.reg"), m_sBeneIdBusReg);
				}
                if (!DataValidator.isEmptyString (m_sBeneIdOtherId))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.other.id"), m_sBeneIdOtherId);
				}
                if (!DataValidator.isEmptyString (m_sUserTransactionRefNo))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.payment.desc"), m_sUserTransactionRefNo);
				}
                if (!DataValidator.isEmptyString (m_sEmail))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.email"), m_sEmail);
				}

                if (!DataValidator.isEmptyString (m_sPaymentModeDisplay))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("ib112.si.payment.mode"), m_sPaymentModeDisplay);
				}
				if (!DataValidator.isEmptyString (m_sPaymentFrequencyDisplay))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.payment.frequency"), m_sPaymentFrequencyDisplay);
				}
				if (!DataValidator.isEmptyString (m_sEffectiveDateDisplay))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.start.date"), m_sEffectiveDateDisplay);
				}
				if (!DataValidator.isEmptyString (m_sTerminationDateDisplay))
				{
					m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.terminate.date"), m_sTerminationDateDisplay);
				}

                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.reference.number"), m_sFormattedTransId);
                if(!DataValidator.isEmptyString (m_sHostRefNo))
				{
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.reference"), m_sHostRefNo);
				}
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.transaction.date"), m_sDateDis);
                m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.transaction.time"), m_sTimeDis);

               //Add KFH GST ID No
                if(!"-".equalsIgnoreCase((String)m_oViewBean.get(InterbankConstants.GST_CHARGES_DIS)))
                	m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.gst.id.no"), IBLoadProperty.getValue("gst.id.no") );

                /*
                 * log into IB_RECEIPT_DETAIL
                 */
                IBUtils.loopIntoReceiptDetails (this, m_oReceiptMap, m_oCurrentBVIDateTime.getSimpleDate (), m_sTransId);

                m_oViewBean.set (CommonConstants.RECEIPT_MAP, m_oReceiptMap);

                String m_sReceiptLink = IBUtils.getReceiptLink (InterbankConstants.INTERBANK_TRANSFER_FORM, VIEWBEAN);
                m_oViewBean.set (CommonConstants.RECEIPT_LINK, m_sReceiptLink);
            }

			m_sbLogDetails.append (ResourcesUtils.getApplicationResourceMessage ("ib104.interbank.transfer.to"));
			m_sbLogDetails.append (" ").append (m_sBeneHolderName);
			m_sbLogDetails.append (" (").append (m_sBeneBankDis).append (": ").append (m_sBeneAccountNo).append (")");
            if (!DataValidator.isEmptyString (m_sHostRefNo))
			{
            	m_sbLogDetails.append ("<br>")
	            	.append ("(")
		        	.append (ResourcesUtils.getApplicationResourceMessage ("general.reference.number.short")).append (": ").append (m_sHostRefNo)
		        	.append (")");
			}

            /*
             * log into IB_INTER_TRANSFER.
             * This is done after set data into viewbean and formbean and pass the formbean to IBLogger.
             */
            IBLogger.logInterTransferActivity (
            		this, m_sTransId, m_sServiceName,
            		m_oCurrentBVIDateTime, m_sFromAccount, m_sBeneAccountNo,
            		m_sFromIsoCurrency,
            		m_sToIsoCurrency, //p_sToAccCurrency,
            		m_sFromAccountCreateDate,
            		m_sAmount, m_sAmount,
            		"IBG", //p_sPaymentType
                 	m_sUserTransactionRefNo, //p_sPaymentDetails
            		m_sTransactionDesc, //TODO: p_sPaymentReference
            		m_sbLogDetails.toString (), m_sTransStatus, m_sTransStatusMsg,
            		"", // p_sGLAccountNo can found at IBG Core
            		m_sBeneHolderName, m_sBeneID,
            		m_sBeneBankDis, m_sBeneBankCode,
            		m_sUserTransactionRefNo, //TODO: p_sBeneficiaryTransRefNo
            		m_sEffectiveDate, m_sServiceCode,
            		m_sHostRefNo, m_sServiceCharges, m_sChargesRefNo,
            		m_sActualStatus, m_sIbgTransID, m_sBankRouteNo,
            		String.valueOf (DataUtils.convertBooleanToInt (m_boEnableVerification)),
            		String.valueOf (DataUtils.convertBooleanToInt (m_boSIIndicator)),
            		m_sBeneIdType,
            		"", "", m_sEmail,
            		m_sBeneIdNewIC,
					m_sBeneIdOldIC,
					m_sBeneIdBusReg,
					m_sBeneIdOtherId,
					gstCharges,
					gstChargesRefNo, 
					senderName);

            if (m_boSIIndicator && m_boIsResultSuccessful)
            {
            	IBLogger.logSIDetail (this, m_sTransId, m_sTransId, SIConstants.TRANSCODE_INTER_TRANSFER, m_sServiceName, m_sPaymentMode,
            			m_sPaymentFrequency, m_sEffectiveDate, m_sTerminationDate, m_sServiceCode, false);
            }

			String gstAbsorbed = GSTUtils.isGSTAmountAbsorbed(gstAbsorbedAmount);
			
            //#-- added by pixa 20121017 start
            if ( (!m_boSIIndicator) && m_boIsResultSuccessful && onlineAccPromoBean !=null){
    	    	HibernateOnlineAccUtils.saveIBOnlineAccPromoTrnx(onlineAccPromoBean);
    	    }
            //#-- added by pixa 20121017 end
            
            /*
             * log into IB_TRANSACTION_HISTORY
             * receipt indicator is based whether have receipt or not, based on result status.
             */
			IBLogger.logInetTranHistory (this,
					m_sTransId,
					m_sServiceName,
					m_sFromAccount,
					m_sFromIsoCurrency,
					m_sBeneAccountNo,
					m_sToIsoCurrency,
					m_sAmount,
					m_sbLogDetails.toString (),
					m_sTransStatus,
					null, null,
					m_sEffectiveDate,
					getIBSessionObjects ().getRemoteIPAddress (),
					"",
					m_boIsResultSuccessful,
					m_sHostRefNo,
					null, // Other1
					null, null,
					getIBSessionObjects ().getIBSessionId (),
					null, null, null, m_sFromAccountCreateDate, null,
					m_sTransStatusMsg,
					m_sPaymentMode,
					m_sPaymentFrequency,
					m_sTerminationDate,
					// Penril: Additional fields for GST report
					m_sServiceCharges,
					gstCharges,
					gstAbsorbed,
					gstAbsorbedAmount,
					getIBSessionObjects().getGSTGLAccount(),
					m_sBeneHolderName,
					m_sBeneBankDis,
					m_sChargesRefNo,
					String.valueOf(getIBSessionObjects().getVisitor().getId()),
					m_sIsStaffAccount);
					// End Penril: Additional fields for GST report);

            m_oViewBean.set (InterbankConstants.TRANS_ID, m_sFormattedTransId);
            m_oViewBean.set (InterbankConstants.HOST_REFERENCE_NO, m_sHostRefNo);
            m_oViewBean.set (InterbankConstants.IS_RESULT_SUCCESSFUL, m_boIsResultSuccessful);
            m_oViewBean.set (InterbankConstants.IS_DISPLAY_NEW_BALANCE, m_boIsDisplayNewBalance);
            m_oViewBean.set (InterbankConstants.STATUS, m_sTransStatusDisplay);
            m_oViewBean.set (InterbankConstants.REASON, m_sTransStatusMsg);
            m_oViewBean.set (InterbankConstants.SUCCESS_MSG, m_sSuccessMsg);
            m_oViewBean.set (InterbankConstants.FROM_ACCT_NEW_BAL, m_sNewBalance);
            m_oViewBean.set (InterbankConstants.TRANS_DATE, m_sDateDis);
            m_oViewBean.set (InterbankConstants.TRANS_TIME, m_sTimeDis);
            
//			 SMS Notification START
			String m_sCustomerSMSMessage = "-";
			String m_sBeneficiarySMSMessage = "-";
			
			String m_sCustomerAmount = SMSServices.formatAmountValue(m_sAmount, m_sFromIsoCurrency);
			String m_sBeneficiaryAmount = SMSServices.formatAmountValue(m_sAmount, m_sToIsoCurrency);

			String m_sTransactionTypeForSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_INTERBANK);
			
			m_sCustomerSMSMessage = SMSServices.generateCustomerSMSMessage(
					m_sTransactionTypeForSMSMessage,
					m_sCustomerAmount,
					m_sBeneHolderName.length()>18?m_sBeneHolderName.substring(0, 18):m_sBeneHolderName,
					m_sTransStatus,
					new Date(),
					m_sNewBalance);
			
			SMSServices.sendCustomerSMS(this, 
					m_oViewBean, 
					m_sFromAccount, 
					m_sTransStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransId,
					m_sAmount,  
					getIBSessionObjects().getVisitor().getId(), 
					m_sCustomerSMSMessage, 
					m_oCurrentBVIDateTime,
					SMSConstants.DEBIT_IB_TYPE);
			
			m_sBeneficiarySMSMessage = SMSServices.generateBeneficiaryOtherSMSMessage(
					m_oViewBean, 
					m_sTransactionTypeForSMSMessage, 
					m_sBeneAccountNo, 
					m_sBeneficiaryAmount, 
					m_oCurrentBVIDateTime);
			
			SMSServices.sendBeneficiarySMS(this, 
					getIBDynaBean(),
					m_oViewBean, 
					m_sFromAccount, 
					m_sTransStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransId, 
					getIBSessionObjects().getVisitor().getId(), 
					m_sBeneficiarySMSMessage, 
					m_oCurrentBVIDateTime,
					"");
			
			ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
			
			m_oViewBean.set (InterbankConstants.FROM_ACCT_NEW_BAL,  FormatterUtils.formatMoneyDisplay (
					DataValidator.isEmptyString (m_oTCEnquiryBean.getAvailable_Bal().trim()) ? "0"
							: m_oTCEnquiryBean.getAvailable_Bal().trim (),
							m_sFromIsoCurrency, 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_oCurrentBVIDateTime.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_oCurrentBVIDateTime.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 (VIEWBEAN, m_oViewBean);

            
           //#-- added by pixa(joo) 20130111 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"))
	            {
        			SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        			
        			try{
        				if(!DataValidator.isEmptyString ((String)m_sFromAccountCreateDate))
        					fromAccCreateDate = timestampFormat.parse(m_sFromAccountCreateDate);
        			}
                	catch (Exception e)
            		{
                		e.printStackTrace();
            		}
        			
        			try{
        				if(!DataValidator.isEmptyString ((String)m_sFromAccountCreateDate))
        					toAccCreateDate = timestampFormat.parse(m_sFromAccountCreateDate);
        			}
                	catch (Exception e)
            		{
                		e.printStackTrace();
            		}
        			
        			try{
        				if(!DataValidator.isEmptyString ((String)m_sEffectiveDate))
        				{
        					String effDateString = HibernateOnlineMobileReportsUtils.convertToDateFormat(m_sEffectiveDate);
                			effDate = dateFormat.parse(effDateString);
        				}
        			}
                	catch (Exception e)
            		{
                		e.printStackTrace();
            		}
        			
        			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("1042");
        			m_oMobileTransaction.setFromAccount(m_sFromAccount);
        			m_oMobileTransaction.setFromCy(m_sFromIsoCurrency);
        			m_oMobileTransaction.setToAccount(m_sBeneAccountNo);
        			m_oMobileTransaction.setToCy(m_sToIsoCurrency);
        			m_oMobileTransaction.setAmount(Double.valueOf(Double.parseDouble(m_sAmount)));
        			m_oMobileTransaction.setStatus(m_sTransStatus);
        			if(effDate != null)
        				m_oMobileTransaction.setEffectiveDate(effDate);
        			m_oMobileTransaction.setRemoteIp(getIBSessionObjects ().getRemoteIPAddress ());
        			m_oMobileTransaction.setPhoenixReference(m_sHostRefNo);
        			m_oMobileTransaction.setEpayReference("");
        			m_oMobileTransaction.setPhoenixRevertReferenceNo("");
        			m_oMobileTransaction.setPhoenixChargesReferenceNo(m_sChargesRefNo);
        			m_oMobileTransaction.setPhoenixRevertChargesReferen("");
        			m_oMobileTransaction.setDetails(m_sbLogDetails.toString ());
        			if(fromAccCreateDate != null)
        				m_oMobileTransaction.setFromAccountCreationDate(fromAccCreateDate);
        			if(toAccCreateDate != null)
        				m_oMobileTransaction.setToAccountCreationDate(toAccCreateDate);
        			m_oMobileTransaction.setType("IN");
        			//m_sToIsoCurrency
        			//m_sDescription
        			InterbankGiroTransfer m_oInterbankGIROTransfer = new InterbankGiroTransfer();
        			m_oInterbankGIROTransfer.setLocalAmount(Double.parseDouble(m_sAmount));
        			//m_oInterbankGIROTransfer.setRemark("");
        			m_oInterbankGIROTransfer.setServiceCode(m_sServiceCode);
        			m_oInterbankGIROTransfer.setRejectMessage(m_sTransStatusMsg);
        			m_oInterbankGIROTransfer.setAccountHolderName(m_sBeneHolderName);
        			m_oInterbankGIROTransfer.setBeneficiaryEmail(m_sEmail);
        			//woonsan 20140924
        			m_oInterbankGIROTransfer.setPaymentType("IBG");
        			m_oInterbankGIROTransfer.setIbgPaymentDetails(m_sTransactionDesc);
        			m_oInterbankGIROTransfer.setIbgPaymentReference(m_sUserTransactionRefNo);
        			m_oInterbankGIROTransfer.setIbgNewIcNo(m_sBeneIdNewIC);
        			m_oInterbankGIROTransfer.setIbgOldIcNo(m_sBeneIdOldIC);
        			m_oInterbankGIROTransfer.setIbgBussinessRegNo(m_sBeneIdBusReg);
        			m_oInterbankGIROTransfer.setIbgOtherIdNo(m_sBeneIdOtherId);
        			
        			HibernateOnlineMobileReportsUtils.insertInterbankGIROTransferStore(m_oMobileTransaction, m_oInterbankGIROTransfer);
        			//m_sTransactionDesc
	            }
            }
        	catch (Exception e)
    		{
        		e.printStackTrace();
    		}
            //#-- added by pixa(joo) 20130111 end
            
            
            /*
             * clear session after transfer,
             * so account enquiry will not display balance in session,
             * instead get from host in new session
             */
			getIBSessionObjects ().setAccountEnquiryBean (null);

        }
        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);
    }
    }
