/**
 * 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.sms.services;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import my.com.kfh.enterprise.services.GenericESBServicesImpl;
import my.com.kfh.enterprise.services.IBEnterpriseServices;
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.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.ESBCompanyProfileBean;
import my.com.kfh.esb.response.ESBTransferToGLBean;
import my.com.kfh.web.utils.BVI_DateTime;
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.IBControllerAction;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBLogger;
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.LogTables;
import my.com.kfh.web.utils.constant.ServiceInfo;

import org.apache.commons.beanutils.DynaBean;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.broadvision.data.client.DataManager;
import com.broadvision.data.common.DataValue;
import com.broadvision.data.common.RowData;
import com.broadvision.data.common.TableData;

/**
 * <pre>
 * PROGRAMMER: Bernard Wong
 * CHANGE-NO:
 * TASK-NO:
 * DATE CREATED: Jun 10, 2010
 * TAG AS:
 * REASON(S):
 * MODIFICATION:
 * </pre>
 */

/**
 * <Class description>
 */
public abstract class SMSServices 
{
	private static Class c_oClass = SMSServices.class;
	
	private static String c_sSMSNotificationID;

	public SMSServices() 
	{
		super();
	}
	
	public static String getSMSNotificationId()
	{
		 return c_sSMSNotificationID;
	}
	
	public static void setSMSNotificationId (String m_sId)
	{
		c_sSMSNotificationID = m_sId;
	}

	/**
	 * Set view bean for details page
	 *
	 * @param p_oEnterpriseServices
	 * @param p_oViewBean
	 * @param p_oServiceInfoBean
	 * @return
	 * @throws IBGenericException
	 */
	public static IBDynaBean setupDetailsViewBean(IBEnterpriseServices p_oEnterpriseServices, IBDynaBean p_oViewBean, IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		Map m_oMobileLocalPrefixMap = new HashMap();

		boolean m_bBeneMobileAllowed 		= false;
		boolean m_bCustomerMobileAllowed 	= false;
		
		try
		{
			m_bBeneMobileAllowed = isBeneficiarySMSAllowed(p_oServiceInfoBean);
			m_bCustomerMobileAllowed = isCustomerSMSAllowed(p_oServiceInfoBean);

			m_oMobileLocalPrefixMap = ResourcesUtils.getBusinessOptionsResourceKey (SMSConstants.RESOURCE_MOBILE_LOCAL_PREFIX_OPTION);

			p_oViewBean.set(SMSConstants.VBEAN_SMS_MOBILE_LOCAL_PREFIX_MAP, m_oMobileLocalPrefixMap);
			p_oViewBean.set(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO, (String) p_oEnterpriseServices.getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.MOBILE_NO));
			p_oViewBean.set(SMSConstants.VBEAN_SMS_CUSTOMER_SMS_CHARGE_RATE, getCustomerSMSChargeRate(p_oServiceInfoBean));
			p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_SMS_CHARGE_RATE, getBeneficiarySMSChargeRate(p_oServiceInfoBean));
			p_oViewBean.set(SMSConstants.VBEAN_SMS_IS_CUSTOMER_SMS_ALLOWED, Boolean.valueOf(m_bCustomerMobileAllowed));
			p_oViewBean.set(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED, Boolean.valueOf(m_bBeneMobileAllowed));
			p_oViewBean.set(SMSConstants.VBEAN_SMS_CUSTOMER_NAME, formatCustomerName(p_oEnterpriseServices.getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_NAME)));
			
		}
		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);
		}

		return p_oViewBean;
	}

	/**
	 * Set up view bean for confirmation page
	 *
	 * @param p_oEnterpriseServices
	 * @param p_sLocalAmount
	 * @param p_oFormBean
	 * @param p_oViewBean
	 * @param p_oServiceInfoBean
	 * @return
	 * @throws IBGenericException
	 */
	public static IBDynaBean setupConfirmViewBean(IBEnterpriseServices p_oEnterpriseServices, String p_sLocalAmount, IBDynaBean p_oFormBean, IBDynaBean p_oViewBean, IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		return setupConfirmViewBean(p_oEnterpriseServices, p_sLocalAmount, CurrencyCode.MALAYSIA_RINGGIT,  p_oFormBean,  p_oViewBean,  p_oServiceInfoBean);
	}

	/**
	 * Set up view bean for confirmation page
	 *
	 * @param p_oEnterpriseServices
	 * @param p_sAmount
	 * @param p_sISOCurrency
	 * @param p_oFormBean
	 * @param p_oViewBean
	 * @param p_oServiceInfoBean
	 * @return
	 * @throws IBGenericException
	 */
	public static IBDynaBean setupConfirmViewBean(IBEnterpriseServices p_oEnterpriseServices, String p_sAmount, String p_sISOCurrency, IBDynaBean p_oFormBean, IBDynaBean p_oViewBean, IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		try
		{
			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue())
			{
				String m_sIsSmsToBene = (String)p_oFormBean.get (SMSConstants.FBEAN_SMS_SEND_BENE_SMS);
				
				if (CommonConstants.YES.equalsIgnoreCase (m_sIsSmsToBene))
				{
					String m_sBeneMobileNumber = getBeneficiaryMobileNumber (p_oFormBean);
					if(DataValidator.isEmptyString(m_sBeneMobileNumber))
					{
						p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO, "-");
					}
					else
					{
						p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO, m_sBeneMobileNumber);
					}	
				}
				else
				{
					p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO, "-");
				}				
			}

			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_CUSTOMER_SMS_ALLOWED)).booleanValue())
			{
				p_sAmount = IBFundTransferDBUtils.getLocalAmount (p_oEnterpriseServices, p_sISOCurrency, p_sAmount, p_oServiceInfoBean);

				p_oViewBean.set(SMSConstants.VBEAN_SMS_IS_ALERT_AMOUNT, isAboveOrEqualAlertAmount(p_sAmount));
			}
		}
		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);
		}

		return p_oViewBean;
	}
	
	
	public static IBDynaBean setupConfirmViewOwnBean(IBEnterpriseServices p_oEnterpriseServices, String p_sAmount, String p_sISOCurrency, IBDynaBean p_oFormBean, IBDynaBean p_oViewBean, IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		try
		{
			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue())
			{
				p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO, p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO));				
			}

			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_CUSTOMER_SMS_ALLOWED)).booleanValue())
			{
				p_sAmount = IBFundTransferDBUtils.getLocalAmount (p_oEnterpriseServices, p_sISOCurrency, p_sAmount, p_oServiceInfoBean);

				p_oViewBean.set(SMSConstants.VBEAN_SMS_IS_ALERT_AMOUNT, isAboveOrEqualAlertAmount(p_sAmount));
			}
		}
		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);
		}

		return p_oViewBean;
	}
	
	public static IBDynaBean setupConfirmView3rdBean(IBEnterpriseServices p_oEnterpriseServices, String p_sAmount, String p_sISOCurrency, IBDynaBean p_oFormBean, IBDynaBean p_oViewBean, IBDynaBean p_oServiceInfoBean, String p_sMobile) throws IBGenericException
	{
		try
		{
			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue())
			{
				p_oViewBean.set(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO, p_sMobile);				
			}

			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_CUSTOMER_SMS_ALLOWED)).booleanValue())
			{
				p_sAmount = IBFundTransferDBUtils.getLocalAmount (p_oEnterpriseServices, p_sISOCurrency, p_sAmount, p_oServiceInfoBean);

				p_oViewBean.set(SMSConstants.VBEAN_SMS_IS_ALERT_AMOUNT, isAboveOrEqualAlertAmount(p_sAmount));
			}
		}
		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);
		}

		return p_oViewBean;
	}

	/**
	 *  Get Beneficiary mobile number in full
	 *
	 * @param p_oFormBean
	 * @return
	 * @throws IBGenericException
	 */
	public static String getBeneficiaryMobileNumber(IBDynaBean p_oFormBean) throws IBGenericException
	{
		String m_sBeneMobileNo 				= null;
		String m_sBeneMobileLocation 	= null;

		try
		{
			m_sBeneMobileLocation = (String)p_oFormBean.get (SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCATION);
			if (SMSConstants.MOBILE_LOCATION_LOCAL.equalsIgnoreCase (m_sBeneMobileLocation))
			{
				m_sBeneMobileNo = p_oFormBean.get (SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL_PREFIX).toString ().concat (
						p_oFormBean.get (SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL).toString ());
				m_sBeneMobileNo = addLocalCountryCode (m_sBeneMobileNo);
			}
			else if (SMSConstants.MOBILE_LOCATION_INTERNATIONAL.equalsIgnoreCase (m_sBeneMobileLocation))
			{
				m_sBeneMobileNo = (String)p_oFormBean.get (SMSConstants.FBEAN_SMS_BENE_MOBILE_INTERNATIONAL);
			}
		}
		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);
		}

		return m_sBeneMobileNo;
	}
	
	/**
	 * Charge for SMS notification to Customer.  Charge amount credited to GL account.
	 *
	 * @param p_sFromAccountNo
	 * @param p_sChargeRate
	 * @param m_oIBSessionObjects
	 * @return
	 * @throws IBGenericException
	 */
	public static String isCustomerSMSCharged (String p_sFromAccountNo, String p_sChargeRate, IBEnterpriseServices p_oEnterpriseServices) throws IBGenericException
	{
		return isSMSCharged(p_sFromAccountNo, p_sChargeRate, p_oEnterpriseServices, SMSConstants.SMS_TARGET_CUSTOMER);
	}

	/**
	 * Charge for SMS notification to Beneficiary.  Charge amount credited to GL account.
	 *
	 * @param p_sFromAccountNo
	 * @param p_sChargeRate
	 * @param m_oIBSessionObjects
	 * @return
	 * @throws IBGenericException
	 */
	public static String isBeneficiarySMSCharged (String p_sFromAccountNo, String p_sChargeRate, IBEnterpriseServices p_oEnterpriseServices) throws IBGenericException
	{
		return isSMSCharged(p_sFromAccountNo, p_sChargeRate, p_oEnterpriseServices, SMSConstants.SMS_TARGET_BENEFICIARY);
	}
	
	/**
	 * Charge for SMS notification.  Charge amount credited to GL account.
	 *
	 * @param p_sFromAccountNo
	 * @param p_sChargeRate
	 * @param p_oIBSessionObjects
	 * @param p_sSMSTarget
	 * @return
	 * @throws IBGenericException
	 */
	public static String isSMSCharged (String p_sFromAccountNo, String p_sChargeRate, IBEnterpriseServices p_oEnterpriseServices,
			String p_sSMSTarget) throws IBGenericException
	{
		ESBTransferToGLBean m_oESBTransferToGLBean = null;

		GenericESBServicesImpl m_oESBService = null;

		String m_sReferenceNumber = null;
		String m_sChargeGLAccount = null;
//		String m_sGLAccountBranchCode = null;	

		try
		{
//			m_sGLAccountBranchCode = IBUtils.getBranchCodeByAccNo(p_sFromAccountNo);
			
//			if (!isSMSChargeRateNothing(p_sChargeRate))
//			{
//				if(!DataValidator.isEmptyString (m_sGLAccountBranchCode))
//				{
//					m_sChargeGLAccount = getGLAccount(m_sGLAccountBranchCode, p_oEnterpriseServices);
					m_sChargeGLAccount = getGLAccount(p_oEnterpriseServices);

//					m_sChargeGLAccount = ResourcesUtils.getGLAccountResource (SMSConstants.GL_ACCOUNT_SMS.concat (m_sGLAccountBranchCode));
//					m_sChargeGLAccount = ResourcesUtils.getGLAccountResource (SMSConstants.GL_ACCOUNT_SMS_001);
//				}
//				else
//				{
//					m_sChargeGLAccount = ResourcesUtils.getGLAccountResource (SMSConstants.GL_ACCOUNT_SMS.concat ("default"));
//				}
				
				if(!DataValidator.isEmptyString (m_sChargeGLAccount))
				{
					String m_sESBDesc = ESBConstants.SMS_NOTIFICATION_CHARGES;
					if (SMSConstants.SMS_TARGET_BENEFICIARY.equalsIgnoreCase (p_sSMSTarget))
					{
						m_sESBDesc = ESBConstants.SMS_NOTIFICATION_CHARGES_FOR_BENE;
					}
					
					m_oESBService = new GenericESBServicesImpl(p_oEnterpriseServices.getIBSessionObjects());
					
					if(Float.valueOf(p_sChargeRate) > 0)
					{
						m_oESBTransferToGLBean = m_oESBService.chargesTransfer (p_sFromAccountNo, m_sChargeGLAccount, p_sChargeRate,
								m_sESBDesc, null, "", "", "", "");
						
						if(ESBConstants.IB_SUCCESS_RC.equals (m_oESBTransferToGLBean.getResponseCode ()))
						{
							m_sReferenceNumber = m_oESBTransferToGLBean.getReferenceNo();
						}
					}
					else
					{
						m_sReferenceNumber = SMSConstants.NO_CHARGE_ATTEMPTED;
					}
				}
//			}
//			else
//			{
//				//Set reference number as a value to represent no charge done
//				m_sReferenceNumber = SMSConstants.NO_CHARGE_ATTEMPTED;
//			}
		}
		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);
		}

		return m_sReferenceNumber;
	}
	
	/**
	 * Check if SMS charges is successful
	 * 
	 * @param p_oESBTransferToGLBean
	 * @return
	 */
	public static boolean isSuccessfulCharged (ESBTransferToGLBean p_oESBTransferToGLBean)
	{
		boolean m_bIsSuccessful = false;

		if(ESBConstants.IB_SUCCESS_RC.equals (p_oESBTransferToGLBean.getResponseCode ()))
		{
			m_bIsSuccessful = true;
		}
		else
		{
			m_bIsSuccessful = false;
		}
		
		return m_bIsSuccessful;
	}
	
	
	public static void sendBeneficiarySMS(IBEnterpriseServices p_oEnterpriseServices, 
			IBDynaBean p_oFormBean, 
			IBDynaBean p_oViewBean, 
			String p_sFromAccount,
			String p_sTransactionStatus, 
			String p_sPayMode, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			long p_lUserId, 
			String p_sSMSMessage, 
			BVI_DateTime p_oDateTime,
			String p_sOther2) throws IBGenericException
	{				
		sendBeneficiarySMS(p_oEnterpriseServices, 
				((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue(),
				p_sFromAccount,
				p_sTransactionStatus, 
				p_sPayMode, 
				p_sTransactionType, 
				p_sTransactionID, 
				p_oViewBean.get(SMSConstants.VBEAN_SMS_BENE_SMS_CHARGE_RATE).toString(), 
				SMSConstants.SMS_TARGET_BENEFICIARY, 
				p_lUserId, 
				p_oFormBean.get(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCATION).toString(),
				p_oViewBean.get(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO).toString(), 
				p_sSMSMessage, 
				SMSConstants.SMS_NOTIFICATION_TYPE, 
				p_oDateTime,
				p_sOther2);
	}

	/**
	 * Checks if Beneficiary can receive SMS and if so, send SMS
	 * 
	 * @param p_oEnterpriseServices
	 * @param p_oViewBean
	 * @param p_sFromAccount
	 * @param p_sTransactionStatus
	 * @param p_sPayMode
	 * @param p_sTransactionType
	 * @param p_sTransactionID
	 * @param p_sLocalAmount
	 * @param p_sSMSCharges
	 * @param p_sSMSTarget
	 * @param p_lUserId
	 * @param p_sMobileNumber
	 * @param p_sSMSMessage
	 * @param p_sSMSType
	 * @param p_oDateTime
	 * @throws IBGenericException
	 */
	public static void sendBeneficiarySMS(IBEnterpriseServices p_oEnterpriseServices, 
			boolean p_bIsSMSAllowed, 
			String p_sFromAccount,
			String p_sTransactionStatus, 
			String p_sPayMode, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			String p_sSMSCharges, 
			String p_sSMSTarget, 
			long p_lUserId, 
			String p_sMobileNumberLocation,
			String p_sMobileNumber, 
			String p_sSMSMessage, 
			String p_sSMSType, 
			BVI_DateTime p_oDateTime,
			String p_sOther2) throws IBGenericException
	{				
		String m_sSMSGLReferenceNumber = "";
		
		try
		{	
			if(SMSServices.canSMSToBeneficiary(p_bIsSMSAllowed, p_sPayMode, p_sMobileNumber))
			{
				if (isTransactionSuccessful(p_sTransactionStatus))
				{
					m_sSMSGLReferenceNumber = SMSServices.isBeneficiarySMSCharged(p_sFromAccount, p_sSMSCharges, p_oEnterpriseServices);
				}
				
				sendSMS(p_oEnterpriseServices, 
						p_sTransactionStatus, 
						p_sTransactionType, 
						p_sTransactionID, 
						m_sSMSGLReferenceNumber,
						p_sSMSCharges, 
						p_sSMSTarget, 
						p_lUserId, 
						p_sMobileNumber, 
						p_sSMSMessage, 
						p_sSMSType, 
						p_oDateTime,
						p_sOther2);
			}
		}
		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);
		}
	}
	
	public static void sendCustomerSMS(IBEnterpriseServices p_oEnterpriseServices, 
			IBDynaBean p_oViewBean, 
			String p_sFromAccount,
			String p_sTransactionStatus, 
			String p_sPayMode, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			String p_sLocalAmount, 
			long p_lUserId,  
			String p_sSMSMessage, 
			BVI_DateTime p_oDateTime,
			String p_sOther2) throws IBGenericException
	{			
		sendCustomerSMS(p_oEnterpriseServices, 
				((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_CUSTOMER_SMS_ALLOWED)).booleanValue(), 
				p_sFromAccount,
				p_sTransactionStatus, 
				p_sPayMode, 
				p_sTransactionType, 
				p_sTransactionID, 
				p_sLocalAmount, 
				p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_SMS_CHARGE_RATE).toString(), 
				SMSConstants.SMS_TARGET_CUSTOMER, 
				p_lUserId, 
				p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), 
				p_sSMSMessage, 
				SMSConstants.SMS_NOTIFICATION_TYPE, 
				p_oDateTime,
				p_sOther2);
	}
	
	/**
	 * Checks if Customer can receive SMS and if so, send SMS
	 * 
	 * @param p_oEnterpriseServices
	 * @param p_oIsSMSAllowed
	 * @param p_sFromAccount
	 * @param p_sTransactionStatus
	 * @param p_sPayMode
	 * @param p_sTransactionType
	 * @param p_sTransactionID
	 * @param p_sLocalAmount
	 * @param p_sSMSCharges
	 * @param p_sSMSTarget
	 * @param p_lUserId
	 * @param p_sMobileNumber
	 * @param p_sSMSMessage
	 * @param p_sSMSType
	 * @param p_oDateTime
	 * @throws IBGenericException
	 */
	public static void sendCustomerSMS(IBEnterpriseServices p_oEnterpriseServices, 
			boolean p_bIsSMSAllowed, 
			String p_sFromAccount,
			String p_sTransactionStatus, 
			String p_sPayMode, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			String p_sLocalAmount, 
			String p_sSMSCharges, 
			String p_sSMSTarget, 
			long p_lUserId, 
			String p_sMobileNumber, 
			String p_sSMSMessage, 
			String p_sSMSType, 
			BVI_DateTime p_oDateTime,
			String p_sOther2) throws IBGenericException
	{				
		String m_sSMSGLReferenceNumber = "";
		
		try
		{	
			
			if(SMSServices.canSMSToCustomer(p_bIsSMSAllowed, p_sPayMode, p_sLocalAmount, p_sMobileNumber))
			{
				
				if (isTransactionSuccessful(p_sTransactionStatus))
				{
					m_sSMSGLReferenceNumber = SMSServices.isCustomerSMSCharged(p_sFromAccount, p_sSMSCharges, p_oEnterpriseServices);
				}
				
				sendSMS(p_oEnterpriseServices, 
						p_sTransactionStatus, 
						p_sTransactionType, 
						p_sTransactionID, 
						m_sSMSGLReferenceNumber,
						p_sSMSCharges, 
						p_sSMSTarget, 
						p_lUserId, 
						p_sMobileNumber, 
						p_sSMSMessage, 
						p_sSMSType, 
						p_oDateTime,
						p_sOther2);
			}
		}
		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);
		}
	}
	
	/**
	 * Send SMS notification
	 *
	 * @param p_oEnterpriseServices
	 * @param p_sTransactionStatus TODO
	 * @param p_sPayMode TODO
	 * @param p_sMobileNumber
	 * @param p_sSMSMessage
	 * @param p_sSMSType
	 * @param m_sFromAccount TODO
	 * @throws IBGenericException
	 */
	public static void sendSMS(IBEnterpriseServices p_oEnterpriseServices, 
			String p_sTransactionStatus, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			String p_sSMSGLReferenceNumber,
			String p_sSMSCharges, 
			String p_sSMSTarget, 
			long p_lUserId, 
			String p_sMobileNumber, 
			String p_sSMSMessage, 
			String p_sSMSType, 
			BVI_DateTime p_oDateTime,
			String p_sOther2) throws IBGenericException
	{
		int m_iNumInsertedRecords = 0;
		
		try
		{			
			setSMSNotificationId(storeSMSNotificationId(p_oEnterpriseServices.getIBSessionObjects().getDataManager()));
			
			System.out.println("getSMSNotificationId() : " + getSMSNotificationId());
			// p_sSMSGLReferenceNumber value mean different things:
			//	null	- Fail to charge
			//	0		- No charge made (RM0.00)
			//	Numeric - Successfully charged
			if (!DataValidator.isEmptyString(getSMSNotificationId())
					&& !getSMSNotificationId().equals("0")
					&& !DataValidator.isEmptyString(p_sSMSGLReferenceNumber))
			{
				m_iNumInsertedRecords = insertToSMSNotificationTable(p_oEnterpriseServices, 
						p_sTransactionStatus, 
						p_sTransactionType,
						p_sTransactionID,
						p_sMobileNumber, 
						p_sSMSGLReferenceNumber,
						p_sSMSCharges, 
						p_sSMSTarget, 
						p_lUserId, 
						p_oDateTime);
			}
			if (m_iNumInsertedRecords > 0)
			{			
				if(isTransactionSuccessful (p_sTransactionStatus))
				{
					try
					{
						IBLogger.logSMSActivity(p_oEnterpriseServices,
								p_sMobileNumber,
								formatSMSMessage(p_sSMSMessage),
								p_sSMSType,
								ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_STATUS_1),
								"",
								"",
								getSMSNotificationId(),
								p_oDateTime,
								p_oDateTime,
								p_sOther2);
					}
					catch (Exception e)
					{
						deleteFromSMSNofiticationTable (p_oEnterpriseServices, getSMSNotificationId());
					}
				}
			}	
		}
		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);
		}
	}

	/**
	 * Checks if Customer is allowed to receive SMS notification
	 *
	 * @param p_oViewBean Get customer SMS notification permission from ViewBean
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean isCustomerSMSAllowed (IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		boolean m_bIsCustomerMobileAllowed = false;

		try
		{
				m_bIsCustomerMobileAllowed = ((Boolean) p_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_SMS_SERVICE_BIT)).booleanValue();
		}
		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);
		}

		return m_bIsCustomerMobileAllowed;
	}


	/**
	 * Checks if Beneficiary is allowed to receive SMS notification
	 *
	 * @param p_oViewBean
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean isBeneficiarySMSAllowed (IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		boolean m_bIsBeneficiaryMobileAllowed = false;

		try
		{
			m_bIsBeneficiaryMobileAllowed = ((Boolean) p_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_BENE_SMS_SERVICE_BIT)).booleanValue();
		}
		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);
		}

		return m_bIsBeneficiaryMobileAllowed;
	}


	/**
	 * Get charge rate for sending SMS to Customer
	 *
	 * @param p_oViewBean
	 * @return
	 * @throws IBGenericException
	 */
	public static String getCustomerSMSChargeRate (IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		String  m_sCustomerMobileChargeRate = null;

		try
		{
			m_sCustomerMobileChargeRate = ((String) p_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_SMS_CHARGES));
			
			m_sCustomerMobileChargeRate = getValidSMSChargeRate (m_sCustomerMobileChargeRate);
			//m_sCustomerMobileChargeRate = FormatterUtils.formatMoney(m_sCustomerMobileChargeRate, CurrencyCode.MALAYSIA_RINGGIT3, false);		
		}
		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);
		}

		return m_sCustomerMobileChargeRate;
	}

	/**
	 * Get charge rate for sending SMS to Beneficiary
	 *
	 * @param p_oViewBean
	 * @return
	 * @throws IBGenericException
	 */
	public static String getBeneficiarySMSChargeRate (IBDynaBean p_oServiceInfoBean) throws IBGenericException
	{
		String  m_sBeneficiaryMobileChargeRate = null;

		try
		{
			m_sBeneficiaryMobileChargeRate = ((String) p_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_BENE_SMS_CHARGES));

			m_sBeneficiaryMobileChargeRate = getValidSMSChargeRate(m_sBeneficiaryMobileChargeRate);
			//m_sBeneficiaryMobileChargeRate = FormatterUtils.formatMoney(m_sBeneficiaryMobileChargeRate, CurrencyCode.MALAYSIA_RINGGIT3, false);
			
		}
		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);
		}

		return m_sBeneficiaryMobileChargeRate;
	}

	/**
	 * Check if SMS notification is logged into database.
	 *
	 * @param p_oEnterpriseServices
	 * @param p_sMobileNumber
	 * @param p_sServiceType
	 * @param p_oDate
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean isSMSLogged(IBEnterpriseServices p_oEnterpriseServices, String p_sMobileNumber, String p_sServiceType, String p_sDateTime) throws IBGenericException
	{
		boolean m_bIsSMSLogged = false;

		TableData m_oTableData = null;

		StringBuffer m_oSBSqlQuery = new StringBuffer();
		
		String m_sDateTimeFormat = "DD MON YYYY HH24:MI:SS";

		try
		{
/*			SELECT SMS_HP_NO 
			FROM SMS_TABLE 
			WHERE SMS_HP_NO = '60123456789' 
			AND SMS_SERVICE = 'SMS Notification' 
			AND SMS_RCDATESTAMP = to_date('11 Jun 2010 15:32:54','DD MON YYYY HH24:MI:SS') 
			AND SMS_SDDATESTAMP = to_date('11 Jun 2010 15:32:54','DD MON YYYY HH24:MI:SS')
*/
			
			m_oSBSqlQuery.append (CommonConstants.DB_SELECT).append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.SMS_HP_NO).append (" ");
			m_oSBSqlQuery.append (CommonConstants.DB_FROM);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.getTableName());
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (CommonConstants.DB_WHERE);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.SMS_HP_NO).append (" = ");
			m_oSBSqlQuery.append ("'").append(p_sMobileNumber);
			m_oSBSqlQuery.append ("' ");
			m_oSBSqlQuery.append (CommonConstants.DB_AND);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.SMS_SERVICE).append (" = ");
			m_oSBSqlQuery.append ("'").append(p_sServiceType);
			m_oSBSqlQuery.append ("' ");
			m_oSBSqlQuery.append (CommonConstants.DB_AND);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.SMS_RCDATESTAMP).append (" = ");
			m_oSBSqlQuery.append (CommonConstants.DB_TO_DATE);
			m_oSBSqlQuery.append("('").append(p_sDateTime);
			m_oSBSqlQuery.append("', '");
			m_oSBSqlQuery.append(m_sDateTimeFormat);
			m_oSBSqlQuery.append ("') ");
			m_oSBSqlQuery.append (CommonConstants.DB_AND);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.SMS_TABLE.SMS_SDDATESTAMP).append (" = ");
			m_oSBSqlQuery.append (CommonConstants.DB_TO_DATE);
			m_oSBSqlQuery.append("('").append(p_sDateTime);
			m_oSBSqlQuery.append("', '");
			m_oSBSqlQuery.append(m_sDateTimeFormat);
			m_oSBSqlQuery.append ("') ");

			m_oTableData = p_oEnterpriseServices.getBvDataServices ().getDataByBoundQuery (m_oSBSqlQuery.toString (), new ArrayList());

			if (m_oTableData.size() > 0)
			{
				m_bIsSMSLogged = true;
			}
		}
		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);
		}

		return m_bIsSMSLogged;
	}

	/**
	 * Check if SMS charges are zero
	 *
	 * @param p_sSMSChargeRate
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean isSMSChargeRateNothing (String p_sSMSChargeRate) throws IBGenericException
	{
		boolean m_bIsSMSChargeRateNothing = true;

		float p_fSMSChargeRate = 0;

		try
		{
			p_fSMSChargeRate = Float.valueOf(p_sSMSChargeRate).floatValue();

			if (p_fSMSChargeRate > 0)
			{
				m_bIsSMSChargeRateNothing = false;
			}
		}
		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);
		}

		return m_bIsSMSChargeRateNothing;
	}

	/**
	 * Return alert amount that determines if SMS is to be send to Customer.  Alert amount id assumed to be in
	 * Malaysia Ringgit (RM)
	 *
	 * @param p_oServiceInfoBean
	 * @return
	 * @throws IBGenericException
	 */
	public static float getAlertAmount () throws IBGenericException
	{
		float m_sSMSAlertAmount = 0;

		try
		{
			m_sSMSAlertAmount = Float.valueOf(ResourcesUtils.getBusinessOptionsResourceMessage(SMSConstants.RESOURCE_BUSINESS_SMS_ALERT_AMOUNT)).floatValue();
		}
		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);
		}

		return m_sSMSAlertAmount;
	}

	/**
	 * Checks if amount transfered hits the alert amount value
	 * 
	 * @param p_sAmount
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean isAboveOrEqualAlertAmount (String p_sAmount) throws IBGenericException
	{
		boolean m_bIsAboveOrEqualSMSAmount = false;

		float m_fAmount = 0;
		float m_fAlertAmount = 0;

		try
		{
			m_fAmount = Float.valueOf(p_sAmount).floatValue();

			m_fAlertAmount = getAlertAmount();

			if (m_fAlertAmount == 0 || m_fAmount >= m_fAlertAmount)
			{
				m_bIsAboveOrEqualSMSAmount = true;
			}
		}
		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);
		}

		return m_bIsAboveOrEqualSMSAmount;
	}

	/**
	 * Return Customer name that is 45 characters long (maximum) and in capitals.  Names that are too long
	 * are truncated
	 *
	 * @param p_sCustomerName
	 * @return
	 * @throws IBGenericException
	 */
	public static String formatCustomerName (String p_sCustomerName) throws IBGenericException
	{
		try
		{
			if (!DataValidator.isEmptyString (p_sCustomerName))
			{
				p_sCustomerName = p_sCustomerName.toUpperCase().trim();
			
				if(p_sCustomerName.length() >= 46)
				{
					p_sCustomerName = p_sCustomerName.substring(0, 45);
				}
			}
		}
		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);
		}

		return p_sCustomerName;
	}


	/**
	 * Return SMS message to be 153 characters long (maximum).  Messages that are too long are truncated
	 *
	 * @param p_sCustomerName
	 * @return
	 * @throws IBGenericException
	 */
	public static String formatSMSMessage (String p_sSMSMessage) throws IBGenericException
	{
		try
		{
			if (!DataValidator.isEmptyString (p_sSMSMessage))
			{
				p_sSMSMessage = p_sSMSMessage.trim();
				if(p_sSMSMessage.length() >= 154)
				{
					p_sSMSMessage = p_sSMSMessage.substring(0, 153);
				}
			}
		}
		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);
		}

		return p_sSMSMessage;
	}
	

	public static boolean canSMSToCustomer (boolean p_bIsSMSAllowed, String p_sAmount, String p_sMobileNo) throws IBGenericException
	{
		boolean m_bCanSMSToCustomer = false;

		try
		{
			if(p_bIsSMSAllowed)
			{
				if(!DataValidator.isEmptyString(p_sMobileNo) &&
						SMSServices.isAboveOrEqualAlertAmount(p_sAmount))
				{
					m_bCanSMSToCustomer = true;
				}
			}
		}
		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);
		}

		return m_bCanSMSToCustomer;
	}

	/**
	 * Checks if required data are valid for SMS to be sent to Customer/Sender
	 * @param p_sTransactionStatus TODO
	 * @param p_sAmount
	 * @param p_sMobileNo
	 *
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean canSMSToCustomer (boolean p_bIsSMSAllowed, String p_sPayMode, String p_sAmount, String p_sMobileNo) throws IBGenericException
	{
		boolean m_bCanSMSToCustomer = false;

		try
		{
			if(p_bIsSMSAllowed)
			{
				if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (p_sPayMode) || DataValidator.isEmptyString (p_sPayMode))
				{
					if(!DataValidator.isEmptyString(p_sMobileNo) &&
							SMSServices.isAboveOrEqualAlertAmount(p_sAmount))
					{
						m_bCanSMSToCustomer = true;
					}
				}
			}
		}
		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);
		}

		return m_bCanSMSToCustomer;
	}

	/**
	 * Checks if required data are valid for SMS to be sent to Beneficiary
	 * @param p_sTransactionStatus TODO
	 * @param p_oViewBean
	 *
	 * @return
	 * @throws IBGenericException
	 */
	public static boolean canSMSToBeneficiary (boolean p_bIsSMSAllowed, String p_sPayMode, String p_sMobileNo) throws IBGenericException
	{
		boolean m_bCanSMSToBeneficiary = false;

		try
		{
			if(p_bIsSMSAllowed)
			{
				if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (p_sPayMode) || DataValidator.isEmptyString (p_sPayMode))
				{
					if(!DataValidator.isEmptyString(p_sMobileNo) && !p_sMobileNo.equalsIgnoreCase("-"))
					{
						m_bCanSMSToBeneficiary = true;
					}
				}
			}
		}
		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);
		}

		return m_bCanSMSToBeneficiary;
	}
	
	/**
	 * Insert new record IB_SMS_NOTIFICATION table
	 * 
	 * @param p_oEnterpriseServices
	 * @param p_sTransactionStatus TODO
	 * @param p_sTransactionType
	 * @param p_sTransactionID
	 * @param p_sMobileNo TODO
	 * @param p_sSMSCharges
	 * @param p_sSMSTarget
	 * @param p_lUserId
	 * @param p_oDateTime
	 * @return
	 * @throws IBGenericException
	 */
	public static int insertToSMSNotificationTable (IBEnterpriseServices p_oEnterpriseServices, 
			String p_sTransactionStatus, 
			String p_sTransactionType, 
			String p_sTransactionID, 
			String p_sMobileNo, 
			String p_sSMSGLReferenceNumber,
			String p_sSMSCharges,
			String p_sSMSTarget, 
			long p_lUserId, 
			BVI_DateTime p_oDateTime)
	{
		int m_iNumInsertedRecords = 0;

		try
		{			
			RowData m_oRowData = new RowData ();
			
			m_oRowData.setLongValue (LogTables.IB_SMS_NOTIFICATION.SMS_NOTIFICATION_ID
					.toString (), Long.valueOf(getSMSNotificationId()).longValue());
			
			m_oRowData.setStringValue (LogTables.IB_SMS_NOTIFICATION.TRNX_ID.toString (), p_sTransactionID);
			
			m_oRowData.setStringValue (LogTables.IB_SMS_NOTIFICATION.TRNX_TYPE.toString (), p_sTransactionType);
			
			m_oRowData.setValue (LogTables.IB_SMS_NOTIFICATION.TRNX_DATE.toString (), new DataValue (p_oDateTime.getJavaDate ()));

			m_oRowData.setLongValue (LogTables.IB_SMS_NOTIFICATION.USER_ID.toString (), p_lUserId);
			
			m_oRowData.setStringValue (LogTables.IB_SMS_NOTIFICATION.MOBILE_NO.toString (), p_sMobileNo);
			
			m_oRowData.setStringValue (LogTables.IB_SMS_NOTIFICATION.TRNX_STATUS.toString (), p_sTransactionStatus);
			
			m_oRowData.setIntValue (LogTables.IB_SMS_NOTIFICATION.SMS_TARGET.toString (), Integer.valueOf(p_sSMSTarget).intValue());
			
			m_oRowData.setValue (LogTables.IB_SMS_NOTIFICATION.SMS_CHARGES.toString (), new DataValue (p_sSMSCharges));
			
			m_oRowData.setStringValue (LogTables.IB_SMS_NOTIFICATION.CHARGE_REF_NO.toString (), p_sSMSGLReferenceNumber);
			
			TableData m_oInsertTbl = new TableData ();
			m_oInsertTbl.appendRow (m_oRowData);

			m_iNumInsertedRecords = p_oEnterpriseServices.getBvDataServices ().insertDataSQL (
					LogTables.IB_SMS_NOTIFICATION.getTableName (), m_oInsertTbl);
		}
		catch (Exception e)
		{
			IBLogger.writeLog(e.getMessage());
			try
			{
				IBLogger.error (c_oClass,
						"Failed to log SMS Notification to IB_SMS_NOTIFICATION table. Error message["
								+ e + "]");
				IBLogger.error (c_oClass, "Log dump:-");
	
				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.SMS_NOTIFICATION_ID.toString ()
						+ "=" + getSMSNotificationId());

				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.TRNX_ID.toString ()
						+ "=" + p_sTransactionID);
				
				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.TRNX_TYPE.toString ()
						+ "=" + p_sTransactionType);

				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.TRNX_DATE.toString ()
						+ "=" + p_oDateTime.getDateDDMMMYYYYHMS ());

				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.USER_ID.toString ()
						+ "=" + p_lUserId);
				
				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.MOBILE_NO.toString ()
						+ "=" + p_sMobileNo);
				
				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.TRNX_STATUS.toString ()
						+ "=" + p_sTransactionStatus);				

				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.SMS_TARGET.toString ()
						+ "=" + p_sSMSTarget);
				
				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.SMS_CHARGES.toString ()
						+ "=" + p_sSMSCharges);

				IBLogger.error (c_oClass, LogTables.IB_SMS_NOTIFICATION.CHARGE_REF_NO.toString ()
						+ "=" + p_sSMSGLReferenceNumber);
			}
			catch (Exception e1)
			{
				//throw (IBGenericException) e1;
			}
		}

		return m_iNumInsertedRecords;
	}
	
	
	/**
	 * Get SMS Notification ID from database sequence
	 * 
	 * @param p_oDataManager
	 * @return
	 */
	private static String storeSMSNotificationId (DataManager p_oDataManager)
	{
		boolean m_boLogError = false;
		
		String m_sSMSNotificationID = "0";
		String m_sErrorCode = "";
		
		String m_sSqlQuery = "SELECT TO_CHAR(IB_SEQ_SMS_NOTIFICATION.NEXTVAL) id from dual ";

		try
		{
			TableData m_oSelectData = p_oDataManager.getDataByBoundQuery (null, m_sSqlQuery, new ArrayList ());
			m_sSMSNotificationID = m_oSelectData.getStringValue (0, "id");
			
			setSMSNotificationId(m_sSMSNotificationID);
		}
		catch (Exception e)
		{
			m_boLogError = true;
			m_sErrorCode = String.valueOf(e.getMessage ());
		}
		finally
		{
			if (m_boLogError)
			{
				IBLogger.error(c_oClass, "Error reason: ".concat(m_sErrorCode).concat(" was returned during Selection SMS Notification Id "));
			}
		}

		return getSMSNotificationId();
	}
	
	/**
	 * Validate SMS Notification form at Details form/page
	 * @param p_oViewBean TODO
	 * @param p_oMapping
	 * @param p_oRequest
	 * @param p_oActionErrors
	 * 
	 * @return
	 * @throws IBGenericException
	 */
	public static ActionErrors validateBeneficiaryMobileNoForm(IBControllerAction p_oControllerAction, 
			IBDynaBean p_oFormBean, 
			IBDynaBean p_oViewBean,
			ActionMapping p_oMapping,
			ActionForm p_oForm, 
			HttpServletRequest p_oRequest, ActionErrors p_oActionErrors) throws IBGenericException
	{
		ActionMapping m_oActionMapping = null;
		
		try
		{
			if(((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue())
			{
				m_oActionMapping = p_oControllerAction.createNewActionMapping (p_oMapping, SMSConstants.VALIDATE_BENE_MOBILE_FULL);
				p_oActionErrors.add(p_oForm.validate (m_oActionMapping, p_oRequest));
				
				if (SMSConstants.MOBILE_LOCATION_LOCAL.equals ((String)p_oFormBean.get (SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCATION)))
				{
					m_oActionMapping = p_oControllerAction.createNewActionMapping (p_oMapping, SMSConstants.VALIDATE_BENE_MOBILE_LOCAL);
					p_oActionErrors.add(p_oForm.validate (m_oActionMapping, p_oRequest));
				}
			}
		}
		catch (Exception e)
		{
			throw (IBGenericException) e;
		}
		return p_oActionErrors;
	}
	
	public static void deleteFromSMSNofiticationTable(IBEnterpriseServices p_oEnterpriseServices, String p_sSMSNotificationId) throws IBGenericException
	{
		StringBuffer m_oSBSqlQuery = new StringBuffer();

		try
		{	
			m_oSBSqlQuery.append (CommonConstants.DB_DELETE).append (" ");
			m_oSBSqlQuery.append (CommonConstants.DB_FROM);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.IB_SMS_NOTIFICATION.getTableName());
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (CommonConstants.DB_WHERE);
			m_oSBSqlQuery.append (" ");
			m_oSBSqlQuery.append (LogTables.IB_SMS_NOTIFICATION.SMS_NOTIFICATION_ID.toString()).append (" = ");
			m_oSBSqlQuery.append ("").append(p_sSMSNotificationId);
			m_oSBSqlQuery.append ("");

			p_oEnterpriseServices.getBvDataServices ().executeDBSql (m_oSBSqlQuery.toString ());
		}
		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);
		}
	}
	
	/**
	 * Generate SMS message for Customer
	 * 
	 * @param p_sTransactionService
	 * @param p_sAmount
	 * @param p_sStatus
	 * @param p_oTransactionDateTime
	 * @param p_oTransactionTime 
	 * @return
	 * @throws IBGenericException
	 */

	public static String generateCustomerSMSMessage(String p_sTransactionService, String p_sAmount, String beneName, String p_sStatus,Date p_oTransactionDateTime , String p_sFromAccBalance) throws IBGenericException
	{
		String m_sCustomerSMSMessage = "";
//		String m_sTransDate = null;
				
		try		
		{	
			
//			BVI_DateTime m_oBVIDateTime = DateTimeUtils.convertStringToBVIDateTime(p_oTransactionDateTime.toString());
//			m_sTransDate =  DateTimeUtils.convertBVIDateToString (m_oBVIDateTime);
			m_sCustomerSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_CUSTOMER_TEXT_MESSAGE,
					new String [] {p_sTransactionService,
					p_sAmount,
					beneName,
					p_sStatus.toLowerCase(),
					DateTimeUtils.convertDateToString(p_oTransactionDateTime,"ddMMMyy HH:mm:ss").toUpperCase(),
					p_sFromAccBalance});

		}
		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);
		}
		
		return m_sCustomerSMSMessage;
	}
	
	/**
	 * Generate SMS message for Customer
	 * 
	 * @param p_sTransactionService
	 * @param p_sAmount
	 * @param p_sStatus
	 * @param p_oTransactionDateTime
	 * @param p_oTransactionTime 
	 * @return
	 * @throws IBGenericException
	 */

	public static String generateCustomerOtherSMSMessage(String p_sTransactionService, String p_sAmount, String p_sStatus,BVI_DateTime p_oTransactionDateTime, String beneName ) throws IBGenericException
	{
		String m_sCustomerSMSMessage = "";
		String m_sTransDate = null;
				
		try		
		{	
			BVI_DateTime m_oBVIDateTime = DateTimeUtils.convertStringToBVIDateTime(p_oTransactionDateTime.toString());
			m_sTransDate =  DateTimeUtils.convertBVIDateToString (m_oBVIDateTime);
			
			m_sCustomerSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_CUSTOMER_TEXT_MESSAGE,
					new String [] {p_sTransactionService,
					p_sAmount,
					beneName,
					p_sStatus.toLowerCase(),
//					p_oTransactionDateTime.getDateDDMMMYYYYHMS()});
					DateTimeUtils.formatDayMonthYear (p_oTransactionDateTime),
					p_oTransactionDateTime.getTime ()});

		}
		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);
		}
		
		return m_sCustomerSMSMessage;
	}
	
	private static DynaBean getIBDynaBean() {
		// TODO Auto-generated method stub
		return null;
	}

	/**
	 * Generate SMS message for Beneficiary
	 * 
	 * @param p_oViewBean
	 * @param p_sTransactionService
	 * @param p_sBeneficiaryAccountNo
	 * @param p_sBeneificiaryAmount
	 * @param p_oTransactionDateTime
	 * @return
	 * @throws IBGenericException
	 */
	public static String generateBeneficiarySMSMessage(String p_sTransactionService, String p_sBeneificiaryAmount, Date p_oTransactionDateTime ,String p_sToAccBalance) throws IBGenericException
	{
		String m_sBeneficiarySMSMessage = "";

		try
		{	
			m_sBeneficiarySMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_BENEFICIARY_TEXT_MESSAGE,
					new String [] {p_sBeneificiaryAmount,
					p_sTransactionService,
					DateTimeUtils.convertDateToString(p_oTransactionDateTime,"ddMMMyy HH:mm:ss").toUpperCase(),
					p_sToAccBalance});
		


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

	/**
	 * Generate SMS message for Beneficiary
	 * 
	 * @param p_oViewBean
	 * @param p_sTransactionService
	 * @param p_sBeneficiaryAccountNo
	 * @param p_sBeneificiaryAmount
	 * @param p_oTransactionDateTime
	 * @return
	 * @throws IBGenericException
	 */
	public static String generateBeneficiaryOtherSMSMessage(IBDynaBean p_oViewBean, String p_sTransactionService, String p_sBeneficiaryAccountNo, String p_sBeneificiaryAmount, BVI_DateTime p_oTransactionDateTime) throws IBGenericException
	{
		String m_sBeneficiarySMSMessage = "";

		try
		{	
			m_sBeneficiarySMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_BENEFICIARY_OTHER_TEXT_MESSAGE,
					new String [] {p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_NAME).toString(),
					p_sTransactionService,
					p_sBeneficiaryAccountNo,
					p_sBeneificiaryAmount,
					p_oTransactionDateTime.getDateDDMMMYYYYHMS()});
		


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

	
	/**
	 * Added local country code (6 for Malaysia) to given Mobile Number.
	 * country code number.  If not local, return the Mobile Number unchanged.
	 * 
	 * @param p_sMobileNumber
	 * @return
	 * @throws IBGenericException
	 */
	public static String addLocalCountryCode (String p_sMobileNumber) throws IBGenericException
	{
		String m_sLocalMobileNumber = p_sMobileNumber;
		
		if (!DataValidator.isEmptyString (p_sMobileNumber))
		{
			m_sLocalMobileNumber = CommonConstants.DEFAULT_MOBILE_COUNTRY_CODE.concat (p_sMobileNumber);
		}
		
		return m_sLocalMobileNumber;
	}
	
	/**
	 * Format amount transacted for use for SMS message.  If ISO Currency is empty, 
	 * defaults to Malaysia Currency (RM)
	 * 
	 * @param p_sAmount
	 * @param p_sISOCurrency
	 * @return
	 * @throws IBGenericException
	 */
	public static String formatAmountValue (String p_sAmount, String p_sISOCurrency) throws IBGenericException
	{
		try
		{
			if (DataValidator.isEmptyString(p_sISOCurrency))
			{
				p_sISOCurrency = CurrencyCode.MALAYSIA_RINGGIT3;
			}
			
			return FormatterUtils.formatMoneyDisplay(p_sAmount, p_sISOCurrency, true);
		}
		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);
		}
	}
	
	/**
	 * Setup form bean for Beneficiary Mobile No.  Removes other mobile number from form bean if mobile
	 * number location is for another location (e.g user selects international, so local mobile number will
	 * be removed from the form bean).  This manual removal is required because of the disable fields
	 * not being seen by Struts.
	 * 
	 * @param p_oFormBean
	 * @return
	 * @throws IBGenericException
	 */
	public static IBDynaBean setupConfirmFormBean(IBDynaBean p_oFormBean) throws IBGenericException
	{
		String m_sBeneficiaryMobileLocation = "";
		String m_sIsSmsToBene = "";
		
		try
		{
			m_sIsSmsToBene = (String)p_oFormBean.get (SMSConstants.FBEAN_SMS_SEND_BENE_SMS);
			if (CommonConstants.YES.equalsIgnoreCase (m_sIsSmsToBene))
			{
				m_sBeneficiaryMobileLocation = p_oFormBean.get(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCATION).toString();
				
				if (SMSConstants.MOBILE_LOCATION_LOCAL.equals (m_sBeneficiaryMobileLocation))
				{
					p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_INTERNATIONAL, "");
				}
				else if (SMSConstants.MOBILE_LOCATION_INTERNATIONAL.equals (m_sBeneficiaryMobileLocation))
				{
					p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL_PREFIX, "");
					p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL, "");	
				}				
			}
			else
			{
				p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCATION, "");
				p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL_PREFIX, "");
				p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_LOCAL, "");
				p_oFormBean.set(SMSConstants.FBEAN_SMS_BENE_MOBILE_INTERNATIONAL, "");
			}
		}
		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);
		}
		
		return p_oFormBean;
	}
	
	/**
	 * Checks if transaction status is successful
	 *
	 * @param p_sTransactionStatus
	 * @return
	 */
	public static boolean isTransactionSuccessful(String p_sTransactionStatus)
	{
		boolean m_bIsSuccessful = false;
		

			if(!p_sTransactionStatus.equals(ResourcesUtils.getUnsuccessful()) && 
					!p_sTransactionStatus.equals(ResourcesUtils.getNotAccepted()))
				{
					m_bIsSuccessful = true;
				}

		
		return m_bIsSuccessful;
	}
	
	/**
	 * 
	 * Checks if Charge Rate from BVMC is valid
	 *
	 * @param p_sChargeRate
	 * @return
	 */
	public static boolean isChargeRateValid (String p_sChargeRate)
	{
		boolean m_bIsChargeRateValid = false;
		
		if (!DataValidator.isEmptyString (p_sChargeRate) && 
				DataValidator.isValidNumber(p_sChargeRate))
		{
			m_bIsChargeRateValid = true;
		}
		
		return m_bIsChargeRateValid;
	}
	
	/**
	 * // NO USE, SI ServiceInfo doesn't cater to all possible transaction with SMS Notification
	 * <Method description>
	 * @throws IBGenericException 
	 *
	 */
	public static void sendCustomerSMSForSI (IBEnterpriseServices p_oEnterpriseServices, 
			String p_sUserId, 
			String p_sServiceCode, 
			String p_sSITransactionCode,
			String p_sTransactionStatus,
			String p_sTransactionID,
			String p_sFromAccount,
			String p_sAmount,
			BVI_DateTime p_oTransactionDateTime,
			String p_sAccBalance,
			String beneName
			
		) throws IBGenericException
	{
		Map m_oServiceInfo = null;
		Map m_oCustomerInfo = null;
		
		String m_sSMSGLReferenceNumber = "";
		String m_sCustomerSMSCharges = "";
		String m_sCustomerSMSMessage = "";
		
		try
		{
			if (isTransactionSuccessful (p_sTransactionStatus))
			{
				m_oServiceInfo = getServiceInfoForSI (p_oEnterpriseServices, p_sSITransactionCode);
				m_oCustomerInfo = getCustomerProfileForSI (p_oEnterpriseServices, p_sUserId);
				
				m_sCustomerSMSCharges = (String) m_oServiceInfo.get (ServiceInfo.BEAN_ATT_SMS_CHARGES);
				
				m_sCustomerSMSCharges = getValidSMSChargeRate(m_sCustomerSMSCharges);
				
				if(canSMSToCustomer(((Boolean) m_oServiceInfo.get (ServiceInfo.BEAN_ATT_SMS_SERVICE_BIT)).booleanValue(), p_sAmount, (String) m_oCustomerInfo.get (AccessConstants.COL_MOBILE_NUMBER)))
				{		
					m_sSMSGLReferenceNumber = isCustomerSMSCharged(p_sFromAccount, m_sCustomerSMSCharges, p_oEnterpriseServices);
					
					m_sCustomerSMSMessage = generateCustomerSMSMessage (
							 getSMSMessageTransactionServiceNameForSI (p_sSITransactionCode), 
							formatAmountValue(p_sAmount, ""), 
							beneName,
							p_sTransactionStatus, 
							new Date(),
							p_sAccBalance);
					
					sendSMS (p_oEnterpriseServices, 
							p_sTransactionStatus, 
							getSMSNotificationLoggingTransactionServiceNameForSI(p_sSITransactionCode), 
							p_sTransactionID, 
							m_sSMSGLReferenceNumber,
							m_sCustomerSMSCharges, 
							SMSConstants.SMS_TARGET_CUSTOMER,
							Long.valueOf (p_sUserId).longValue (), 
							(String) m_oCustomerInfo.get (AccessConstants.COL_MOBILE_NUMBER), 
							m_sCustomerSMSMessage, 
							SMSConstants.SMS_NOTIFICATION_TYPE, 
							p_oTransactionDateTime,
							SMSConstants.DEBIT_IB_TYPE);
				}
			}
		}
		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);
		}
	}

	public static void sendBeneficiarySMSForSI (IBEnterpriseServices p_oEnterpriseServices, 
			String p_sUserId, 
			String p_sServiceCode, 
			String p_sSITransactionCode,
			String p_sTransactionStatus,
			String p_sTransactionID,
			String p_sToAccount,
			String p_sBeneMobileNumber,
			String p_sAmount,
			BVI_DateTime p_oTransactionDateTime,
			String p_sAccBalance
			
		) throws IBGenericException
	{
		Map m_oServiceInfo = null;
		
		String m_sSMSGLReferenceNumber = "0";
		String m_sCustomerSMSCharges = "";
		
		try
		{
			if (isTransactionSuccessful (p_sTransactionStatus))
			{
				m_oServiceInfo = getServiceInfoForSI (p_oEnterpriseServices, p_sSITransactionCode);
				
				if(canSMSToCustomer(((Boolean) m_oServiceInfo.get (ServiceInfo.BEAN_ATT_SMS_SERVICE_BIT)).booleanValue(), p_sAmount, p_sBeneMobileNumber))
				{		
					String m_sBeneficiarySMSMessage = SMSServices.generateBeneficiarySMSMessage (
							 getSMSMessageTransactionServiceNameForSI (p_sSITransactionCode), 
							formatAmountValue(p_sAmount, ""), 
							new Date(),
							p_sAccBalance);
					
					sendSMS (p_oEnterpriseServices, 
							p_sTransactionStatus, 
							getSMSNotificationLoggingTransactionServiceNameForSI(p_sSITransactionCode), 
							p_sTransactionID, 
							m_sSMSGLReferenceNumber,
							m_sCustomerSMSCharges, 
							SMSConstants.SMS_TARGET_BENEFICIARY,
							Long.valueOf (p_sUserId).longValue (), 
							p_sBeneMobileNumber, 
							m_sBeneficiarySMSMessage, 
							SMSConstants.SMS_NOTIFICATION_TYPE, 
							p_oTransactionDateTime,
							SMSConstants.CREDIT_IB_TYPE);
				}
			}
		}
		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);
		}
	}
	
	/**
	 * 
	 * Get customer profile for SI transaction
	 *
	 * @param p_oIbSessionObjects
	 * @param p_sServiceCode
	 * @return
	 */
	public static Map getCustomerProfileForSI (IBEnterpriseServices p_oEnterpriseServices, String p_sCustomerId) throws IBGenericException
	{
		TableData m_oTableData = null;
		Map m_oCustomerInfo = new HashMap ();

		try
		{			
			StringBuffer m_sbQuery = new StringBuffer ();
			m_sbQuery.append ("" +
					CommonConstants.DB_SELECT + " " + 
					AccessConstants.COL_MOBILE_NUMBER + " " +
					CommonConstants.DB_FROM + " " +
					AccessConstants.TBL_IB_USER_ACCESS_CREDENTIAL + " " +
					CommonConstants.DB_WHERE + " " +
					AccessConstants.COL_USER_ID + " = '" + p_sCustomerId + "'");
			
			m_oTableData = p_oEnterpriseServices.getBvDataServices ().getDataByBoundQuery (m_sbQuery.toString (), new ArrayList());
			
			m_oCustomerInfo.put (AccessConstants.COL_MOBILE_NUMBER, m_oTableData.getStringValue(0, AccessConstants.COL_MOBILE_NUMBER));
		}
		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);
		}

		return m_oCustomerInfo;
	}

	/**
	 * 
	 * Get Service Info for SI transactions
	 *
	 * @param p_oIbSessionObjects
	 * @param p_sServiceCode
	 * @return
	 */
	public static Map getServiceInfoForSI (IBEnterpriseServices p_oEnterpriseServices, String p_sSITransactionCode) throws IBGenericException
	{
		TableData m_oTableData = null;
		Map m_oServiceInfo = new HashMap ();

		try
		{		
			StringBuffer m_sbQuery = new StringBuffer ();
			m_sbQuery.append ("" +
					CommonConstants.DB_SELECT + " " + 
					"ROWNUM" + ", " +
					ServiceInfo.TABLE_ATT_SMS_SERVICE_BIT + ", " +
					ServiceInfo.TABLE_ATT_SMS_CHARGES + " " +
					CommonConstants.DB_FROM + " " +
					"IB_SERVICE_INFO " +
					CommonConstants.DB_WHERE + " " +
					"SERVICE_CODE = '" + getServiceInfoCodeForSI(p_sSITransactionCode) + "' " +
					CommonConstants.DB_AND + " " +
					"ROWNUM = 1" );
			
			m_oTableData = p_oEnterpriseServices.getBvDataServices ().getDataByBoundQuery (m_sbQuery.toString (), new ArrayList());

			m_oServiceInfo.put (ServiceInfo.BEAN_ATT_SMS_SERVICE_BIT, isTrue (String.valueOf(m_oTableData.getIntValue(0, ServiceInfo.TABLE_ATT_SMS_SERVICE_BIT))));
			m_oServiceInfo.put (ServiceInfo.BEAN_ATT_SMS_CHARGES, m_oTableData.getStringValue(0, ServiceInfo.TABLE_ATT_SMS_CHARGES));
		}
		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);
		}

		return m_oServiceInfo;
	}
	
	/**
	 * 
	 * Get valid value for charge rates.  If invalid, returns no charges.
	 *
	 * @param p_sChargeRate
	 * @return
	 */
	public static String getValidSMSChargeRate (String p_sChargeRate)
	{
		if(isChargeRateValid(p_sChargeRate))
		{
			p_sChargeRate = FormatterUtils.formatMoney2Dec(p_sChargeRate);
		}
		else
		{
			p_sChargeRate = SMSConstants.EMPTY_CHARGE_RATE;
		}
		
		return p_sChargeRate;
	}
	
	/**
	 * 
	 * Get the correct transaction name value to be used for SMS messages based on SI Transaction Service code.
	 *
	 * @param p_oTransactionService
	 * @return
	 */
	public static String getSMSMessageTransactionServiceNameForSI (String p_oTransactionService)
	{
		String m_sTransactionServiceName = "";
		
		if (p_oTransactionService.equals (SIConstants.TRANSCODE_BILL_PAYMENT))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_BILL);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_FTT_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_FOREIGN);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTER_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_INTERBANK);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTRA_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_THIRD);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_OWN_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_OWN);
		} 
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_JOMPAY))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_JOMPAY);
		}
		
		return m_sTransactionServiceName;
	}
	
	/**
	 * 
	 * Get the correct transaction name value to be used for SMS Notification table based on SI Transaction Service code.
	 *
	 * @param p_oTransactionService
	 * @return
	 */
	public static String getSMSNotificationLoggingTransactionServiceNameForSI (String p_oTransactionService)
	{
		String m_sTransactionServiceName = "";
		
		if (p_oTransactionService.equals (SIConstants.TRANSCODE_BILL_PAYMENT))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_BILL);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_FTT_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_FOREIGN);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTER_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_INTERBANK);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTRA_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_THIRD);
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_OWN_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_OWN);
		}
		else if(p_oTransactionService.equals (SIConstants.TRANSCODE_JOMPAY))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (SMSConstants.RESOURCE_SI_SERVICE_JOMPAY);
		}
		
		return m_sTransactionServiceName;
	}
	
	/**
	 * 
	 * Get the appropriate Service Info code for SI based on Transaction Service code
	 *
	 * @param p_oTransactionService
	 * @return
	 */
	public static String getServiceInfoCodeForSI (String p_oTransactionService)
	{
		String m_sServiceInfoCode = "";
		
		if (p_oTransactionService.equals (SIConstants.TRANSCODE_BILL_PAYMENT))
		{
			m_sServiceInfoCode = ServiceInfo.BILL_PAYMENT_FAV_PAYMENT;
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_FTT_TRANSFER))
		{
			m_sServiceInfoCode = ServiceInfo.FUND_TRANSFER_FTT_REG;
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTER_TRANSFER))
		{
			m_sServiceInfoCode = ServiceInfo.FUND_TRANSFER_INTER_FAV;
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_INTRA_TRANSFER))
		{
			m_sServiceInfoCode = ServiceInfo.FUND_TRANSFER_INTRA_FAV;
		}
		else if (p_oTransactionService.equals (SIConstants.TRANSCODE_OWN_TRANSFER))
		{
			m_sServiceInfoCode = ServiceInfo.FUND_TRANSFER_OWN;
		} 
		else if(p_oTransactionService.equals (SIConstants.TRANSCODE_JOMPAY)) 
		{
			m_sServiceInfoCode = ServiceInfo.OPEN_JOMPAY;
		}
		
		return m_sServiceInfoCode;
	}
	
	/**
	 * Returns boolean value of BV database values for boolean (0 - True, 1 - False)
	 * 
	 * @param p_sString
	 * @return
	 */
	public static boolean isTrue (String p_sString)
	{
		if (CommonConstants.BV_INT_YES.equalsIgnoreCase (p_sString))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	/**
	 * Get GL Account number based on branch code from BVMC
	 * 
	 * @param p_oEnterpriseServices
	 * @param p_sBranchCode
	 * @return
	 * @throws IBGenericException
	 */
	public static String getGLAccount (IBEnterpriseServices p_oEnterpriseServices) throws IBGenericException
	{
		StringBuffer m_sbQuery = new StringBuffer();
		TableData m_oTableData = null;
		String m_sGLAccountNumber = null;
//		String m_sSMSCode = "SMS";
		String m_sSMSCode = "SMS";

		try
		{
			m_sbQuery.append ("" +
				CommonConstants.DB_SELECT + " " + 
				"ACCOUNT_NO " +
				CommonConstants.DB_FROM + " " +
				"IB_COLLECTION_ACCOUNT " +
				CommonConstants.DB_WHERE + " " +
//				"ACCCOUNT_CODE = '" + m_sSMSCode.concat(p_sBranchCode) + "' "
				"ACCCOUNT_CODE = '" + m_sSMSCode + "' "
			);

			m_oTableData = p_oEnterpriseServices.getBvDataServices().getDataByBoundQuery (m_sbQuery.toString (), new ArrayList());

			if (m_oTableData != null)
			{
				if (m_oTableData.size () > 0)
				{
					m_sGLAccountNumber = m_oTableData.getStringValue(0, "ACCOUNT_NO");
				}
			}
		}
		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);
		}

		return m_sGLAccountNumber;
	}
		
	
/*	public static void main (String[] args) throws IBGenericException
	{
		String m_sgetSMSNotificationId = "1";
		String p_sSMSGLReferenceNumber = "wee";
		
		System.out.println("getSMSNotificationId(): " + getSMSNotificationId());
		
		if (!DataValidator.isEmptyString(m_sgetSMSNotificationId) 
				&& !m_sgetSMSNotificationId.equals("0")
				&& !DataValidator.isEmptyString(p_sSMSGLReferenceNumber))
		{
			System.out.println("Here!");
		}
	}*/
}
