package my.com.kfh.enterprise.services.ib115_gold.gold_thirdparty;

/**
 * PROGRAMMER: Goh Kee Kun
 * COMPANY: Pixakraft
 * DATE CREATED: 15-Oct-2012
 */

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

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.ib112_si.SIConstants;
import my.com.kfh.enterprise.services.ib115_gold.constant.GoldConstants;
import my.com.kfh.enterprise.services.ib115_gold.constant.SIConstantsExtension;
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.sms.services.SMSConstants;
import my.com.kfh.sms.services.SMSServices;
import my.com.kfh.web.utils.BVI_DateTime;
import my.com.kfh.web.utils.DataValidator;
import my.com.kfh.web.utils.FormatterUtils;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBLoggerExtension;
import my.com.kfh.web.utils.ResourcesUtils;
import my.com.kfh.web.utils.Constant.ServiceInfoExtend;
import my.com.kfh.web.utils.constant.ServiceInfo;

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

public class SMSServiceGold{

	private static Class c_oClass = SMSServices.class;
	private static String c_sSMSNotificationID;
	
	//Gold transfer send sms to customer with IB_SMS_NOTIFICATION and SMS_TABLE same trnx_id
	public static void sendCustomerSMS2(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) throws IBGenericException
	{			
		sendCustomerSMSExtendGold(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, 
				"0",//p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_SMS_CHARGE_RATE).toString(), charge rate is 0
				SMSConstants.SMS_TARGET_CUSTOMER, 
				p_lUserId, 
				p_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), 
				p_sSMSMessage, 
				SMSConstants.SMS_NOTIFICATION_TYPE, 
				p_oDateTime);
	}
	
	//Gold transfer send sms to customer with IB_SMS_NOTIFICATION and SMS_TABLE same trnx_id
	public static void sendBeneficiarySMS2(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) throws IBGenericException
	{				
		sendBeneficiarySMS2(p_oEnterpriseServices, 
				((Boolean) p_oViewBean.get(SMSConstants.VBEAN_SMS_IS_BENE_SMS_ALLOWED)).booleanValue(),
				p_sFromAccount,
				p_sTransactionStatus, 
				p_sPayMode, 
				p_sTransactionType, 
				p_sTransactionID, 
				"0",//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);
	}
	
	/**
	 * 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 sendBeneficiarySMS2(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) throws IBGenericException
	{				
		String m_sSMSGLReferenceNumber = "";
		
		try
		{	
			if(SMSServices.canSMSToBeneficiary(p_bIsSMSAllowed, p_sPayMode, p_sMobileNumber))
			{
				if (SMSServices.isTransactionSuccessful(p_sTransactionStatus))
				{
					m_sSMSGLReferenceNumber = SMSServices.isBeneficiarySMSCharged(p_sFromAccount, p_sSMSCharges, p_oEnterpriseServices);
				}
				
				sendSMS2(p_oEnterpriseServices, 
						p_sTransactionStatus, 
						p_sTransactionType, 
						p_sTransactionID, 
						m_sSMSGLReferenceNumber,
						p_sSMSCharges, 
						p_sSMSTarget, 
						p_lUserId, 
						p_sMobileNumber, 
						p_sSMSMessage, 
						p_sSMSType, 
						p_oDateTime);
			}
		}
		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 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 sendCustomerSMSExtendGold(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) throws IBGenericException
	{				
		String m_sSMSGLReferenceNumber = "";
		
		try
		{	
			if(SMSServices.canSMSToCustomer(p_bIsSMSAllowed, p_sPayMode, p_sLocalAmount, p_sMobileNumber))
			{
				if (SMSServices.isTransactionSuccessful(p_sTransactionStatus))
				{
					m_sSMSGLReferenceNumber = SMSServices.isCustomerSMSCharged(p_sFromAccount, p_sSMSCharges, p_oEnterpriseServices);
				}
				
				sendSMS2(p_oEnterpriseServices, 
						p_sTransactionStatus, 
						p_sTransactionType, 
						p_sTransactionID, 
						m_sSMSGLReferenceNumber,
						p_sSMSCharges, 
						p_sSMSTarget, 
						p_lUserId, 
						p_sMobileNumber, 
						p_sSMSMessage, 
						p_sSMSType, 
						p_oDateTime);
			}
		}
		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);
		}
	}
	
/**
	 * // NO USE, SI ServiceInfo doesn't cater to all possible transaction with SMS Notification
	 * <Method description>
	 * @throws IBGenericException 
	 *
	 */
	public static void sendCustomerSMSForSIExtendGold (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 beneName
			
		) throws IBGenericException
	{
		Map m_oServiceInfo = null;
		Map m_oCustomerInfo = null;
		
		String m_sSMSGLReferenceNumber = "";
		String m_sCustomerSMSCharges = "";
		String m_sCustomerSMSMessage = "";
		
		try
		{
			if (SMSServices.isTransactionSuccessful (p_sTransactionStatus))
			{
				m_oServiceInfo = getServiceInfoForSIExtendGold (p_oEnterpriseServices, p_sSITransactionCode);
				m_oCustomerInfo = getCustomerProfileForSIExtendGold (p_oEnterpriseServices, p_sUserId);
				
				m_sCustomerSMSCharges = (String) m_oServiceInfo.get (ServiceInfo.BEAN_ATT_SMS_CHARGES);
				
				m_sCustomerSMSCharges = SMSServices.getValidSMSChargeRate(m_sCustomerSMSCharges);
				m_sCustomerSMSCharges=SMSConstants.EMPTY_CHARGE_RATE;//no sms charge on Gold transfer
				if(SMSServices.canSMSToCustomer(((Boolean) m_oServiceInfo.get (ServiceInfo.BEAN_ATT_SMS_SERVICE_BIT)).booleanValue(), p_sAmount, (String) m_oCustomerInfo.get (AccessConstants.COL_MOBILE_NUMBER)))
				{		
					m_sSMSGLReferenceNumber = SMSServices.isCustomerSMSCharged(p_sFromAccount, m_sCustomerSMSCharges, p_oEnterpriseServices);
					String amount;
					if(p_sServiceCode.equals("GOLD") || p_sServiceCode.equals(ThirdPartyGoldTransferTags.GOLDSIFAVT) || p_sServiceCode.equals(ThirdPartyGoldTransferTags.GOLDSIOPNT)){
						amount = formatGoldValue(p_sAmount, "");
					}else{
						amount = SMSServices.formatAmountValue(p_sAmount, "");
					}
					m_sCustomerSMSMessage = SMSServices.generateCustomerOtherSMSMessage (
//							getSMSMessageTransactionServiceNameForSIExtendGold (p_sSITransactionCode), 
							getSMSNotificationLoggingTransactionServiceNameForSIExtendGold(p_sSITransactionCode), 
							amount,
							p_sTransactionStatus, 
							p_oTransactionDateTime,
							beneName);
					
					sendSMS2 (p_oEnterpriseServices, 
							p_sTransactionStatus, 
							getSMSNotificationLoggingTransactionServiceNameForSIExtendGold(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);
				}
			}
		}
		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);
		}
	}
	
	/**
	 * 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 sendSMS2(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) throws IBGenericException
	{
		int m_iNumInsertedRecords = 0;
		
		try
		{			
			setSMSNotificationId(storeSMSNotificationId(p_oEnterpriseServices.getIBSessionObjects().getDataManager()));
			
			// 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))
			{
				//set SMSServices notificationId from here
				SMSServices.setSMSNotificationId(getSMSNotificationId());
				m_iNumInsertedRecords = SMSServices.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(SMSServices.isTransactionSuccessful (p_sTransactionStatus))
				{
					try
					{
						IBLoggerExtension.logSMSActivityWithTrnx_Id(p_oEnterpriseServices,
								p_sMobileNumber,
								SMSServices.formatSMSMessage(p_sSMSMessage),
								p_sSMSType,
								ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_STATUS_1),
								"",
								"",
								getSMSNotificationId(),
								p_oDateTime,
								p_oDateTime,
								p_sTransactionID);
					}
					catch (Exception e)
					{
						SMSServices.deleteFromSMSNofiticationTable (p_oEnterpriseServices, getSMSNotificationId());
					}
				}
			}	
		}
		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);
		}
	}
	
	/**
	 * 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();
	}
	
	public static String getSMSNotificationId()
	{
		 return c_sSMSNotificationID;
	}
	
	public static void setSMSNotificationId (String m_sId)
	{
		c_sSMSNotificationID = m_sId;
	}
	
	/**
	 * Format amount transacted for use for SMS message.  If ISO Currency is empty, 
	 * defaults to Gold Currency (XAU)
	 * 
	 * @param p_sAmount
	 * @param p_sISOCurrency
	 * @return
	 * @throws IBGenericException
	 */
	public static String formatGoldValue (String p_sAmount, String p_sISOCurrency) throws IBGenericException
	{
		try
		{
			if (DataValidator.isEmptyString(p_sISOCurrency))
			{
				p_sISOCurrency = GoldConstants.GOLD_CURRENCY;
			}
			
			return FormatterUtils.formatGoldUnitDisplay (p_sAmount, 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);
		}
	}
	
	/**
	 * 
	 * 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 getSMSNotificationLoggingTransactionServiceNameForSIExtendGold (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);
		}
		//start added by pixa 20121022
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_OWN_GOLD_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (ThirdPartyGoldTransferTags.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_OWN_GOLD_SI);
		}
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_INTRA_GOLD_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (ThirdPartyGoldTransferTags.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_THIRD_GOLD_SI);
		}
		//end added by pixa 20121022
		return m_sTransactionServiceName;
	}
	
	/**
	 * 
	 * 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 getSMSMessageTransactionServiceNameForSIExtendGold (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);
		}
		//start added by pixa 20121022
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_OWN_GOLD_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (ThirdPartyGoldTransferTags.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_OWN_GOLD);
		}
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_INTRA_GOLD_TRANSFER))
		{
			m_sTransactionServiceName = ResourcesUtils.getApplicationResourceMessage (ThirdPartyGoldTransferTags.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_THIRD_GOLD);
		}
		//end added by pixa 20121022
		
		return m_sTransactionServiceName;
	}
	
	/**
	 * 
	 * Get Service Info for SI transactions
	 *
	 * @param p_oIbSessionObjects
	 * @param p_sServiceCode
	 * @return
	 */
	public static Map getServiceInfoForSIExtendGold (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 = '" + getServiceInfoCodeForSIExtendGold(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;
	}
	
	/**
	 * 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 the appropriate Service Info code for SI based on Transaction Service code
	 *
	 * @param p_oTransactionService
	 * @return
	 */
	public static String getServiceInfoCodeForSIExtendGold (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;
		}
		//start added by pixa 20121022
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_OWN_GOLD_TRANSFER))
		{
			m_sServiceInfoCode = ServiceInfoExtend.GOLD_TRANSFER_OWN;
		}
		else if (p_oTransactionService.equals (SIConstantsExtension.TRANSCODE_INTRA_GOLD_TRANSFER))
		{
			m_sServiceInfoCode = ThirdPartyGoldTransferTags.GOLDOPNTRA;
		}
		//end added by Pixa 20121022
		return m_sServiceInfoCode;
	}
	
	/**
	 * 
	 * Get customer profile for SI transaction
	 *
	 * @param p_oIbSessionObjects
	 * @param p_sServiceCode
	 * @return
	 */
	public static Map getCustomerProfileForSIExtendGold (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;
	}
	
	/**
	 * 
	 * 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;
	}
	
}