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

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

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import my.com.kfh.enterprise.services.IBEnterpriseServices;
import my.com.kfh.enterprise.services.IBEnterpriseServicesWorkspace;
import my.com.kfh.enterprise.services.IBUtils;
import my.com.kfh.enterprise.services.IBUtilsExtension;
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.IBGenericSIServices;
import my.com.kfh.enterprise.services.ib112_si.SIConstants;
import my.com.kfh.enterprise.services.ib112_si.SI_PAYMENT_MODE;
import my.com.kfh.enterprise.services.ib115_gold.IBGenericGoldServices;
import my.com.kfh.enterprise.services.ib115_gold.constant.GoldConstants;
import my.com.kfh.enterprise.services.ib115_gold.constant.SIConstantsExtension;
import my.com.kfh.enterprise.services.ib115_gold.gold_thirdparty.SMSServiceGold;
import my.com.kfh.enterprise.services.ib115_gold.gold_thirdparty.ThirdPartyGoldTransferTags;
import my.com.kfh.enterprise.services.integration.ESBAccountBalanceServices;
import my.com.kfh.enterprise.services.integration.ESBPhoenixWSServices;
import my.com.kfh.enterprise.services.integration.ESBProcessBean;
import my.com.kfh.enterprise.services.integration.ESBProcessBeanInterface;
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.agent.ESBXapi905Agent;
import my.com.kfh.esb.constant.EnumAccType;
import my.com.kfh.esb.constant.EnumApplType;
import my.com.kfh.esb.constant.EnumDepLoan;
import my.com.kfh.esb.constant.EnumPhoenixTranCode;
import my.com.kfh.esb.request.ESBRequestAccountBalanceBean;
import my.com.kfh.esb.request.ESBRequestPhoenixWSBean;
import my.com.kfh.esb.request.ESBRequestXapi905Bean;
import my.com.kfh.esb.response.ESBAccCreateDateBean;
import my.com.kfh.esb.response.ESBAccountBalanceBean;
import my.com.kfh.esb.response.ESBAccountDetailsBean;
import my.com.kfh.esb.response.ESBAccountEnquiryTC100Bean;
import my.com.kfh.esb.response.ESBMsgHeader;
import my.com.kfh.esb.response.ESBResponseXapi905Bean;
import my.com.kfh.sms.services.SMSConstants;
import my.com.kfh.sms.services.SMSServices;
import my.com.kfh.web.utils.BVI_DateTime;
import my.com.kfh.web.utils.DataUtils;
import my.com.kfh.web.utils.DataValidator;
import my.com.kfh.web.utils.DateTimeUtils;
import my.com.kfh.web.utils.FormatterUtils;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBDynaBeanManager;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBLoggerExtension;
import my.com.kfh.web.utils.IBSessionObjects;
import my.com.kfh.web.utils.IBTimer;
import my.com.kfh.web.utils.ResourcesUtils;
import my.com.kfh.web.utils.Constant.ServiceInfoExtend;
import my.com.kfh.web.utils.constant.ESBConstants;
import my.com.kfh.web.utils.constant.ServiceInfo;

import org.dom4j.Document;
import org.dom4j.Element;



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

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

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

		String m_sTacValue = "";
		BVI_DateTime m_oCurrentDateTime = null;
		String m_sAmount = "";
		String m_sLocalAmount = "";
		String m_sFromAccount = "";
		String m_sToAccount = "";
		String m_sStatus = "";
		String m_sFromAccNewBal = "";
		String m_sToAccNewBal = "";
		String m_sReferenceNo = "";
		String m_sPhx_Ref_no = "";
//		String m_sResponseCode = "";
		String m_sReason = "";
		StringBuffer m_sDetails = new StringBuffer();
		String m_sServiceCode = ServiceInfoExtend.GOLD_TRANSFER_OWN;
		String m_sServiceName = "Own Gold Account Transfer";
//		String m_sGOLD_DESC = "IB Gold Transfer - Own Gold Account";
		IBDynaBean m_oViewBean = null;
		IBDynaBean m_oServiceBean = null;
		String m_sFrmAccCrtDt = "";
		String m_sToAccCrtDt = "";
		String m_sRimNo=null;
		ESBAccountDetailsBean m_oFromGoldEnquiryBean=null;
		ESBAccountDetailsBean m_oToAccEnquiryBean=null;
		String m_sFromAccBranchCode=null;
		String m_sFromAccBranchName=null;
//		String m_sToAccBranchCode=null;
//		String m_sToAccBranchName=null;
		IBEnterpriseServices p_oEnterpriseServices=null;

		//si
		String m_sEffectiveDate = null;
		boolean m_boSIIndicator = false;
		String m_sPaymentFrequencyDisplay = null;
		String m_sPayFrequency = null;
		String m_sEffectiveDateDisplay = null;
		String m_sTerminationDate = null;
		String m_sTerminationDateDisplay = null;
		String m_sPaymentModeDisplay = null;
		String m_sPaymentMode = null;
		String m_sCustomerName = getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME);

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

		double m_dAvailableBal = 0.0;
		double m_dTotalTransferAmount = 0.0;
		boolean m_boIsFundSufficient = true;
		String isStaff="";

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

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

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

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

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

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

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

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

			m_sAmount = (String) getIBDynaBean ().get (IBOwnGoldTransferConstant.AMOUNT);
			m_sFromAccount = (String) getIBDynaBean ().get (IBOwnGoldTransferConstant.FROM_ACCOUNT);
			m_sToAccount = (String) getIBDynaBean ().get (IBOwnGoldTransferConstant.TO_ACCOUNT);
			isStaff = (ESBConstants.ACC_STAFF.equalsIgnoreCase(getESBServices().getInquiryStaffByAcctNo(m_sFromAccount).getStatus()))?"Y":"N";
//			Map m_oFromAccountsMap = (Map)m_oViewBean.get (IBOwnGoldTransferConstant.FROM_ACCOUNT_MAP);
//			m_oOwnAccInfoBean = (IBDynaBean) m_oFromAccountsMap.get (m_sFromAccount);
//			m_sFromAccIsoCurr = (String) m_oOwnAccInfoBean.get (CommonConstants.ISO_CURRENCY);

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

//			m_sLocalAmount = IBFundTransferDBUtils.getLocalAmount (this, m_sToAccIsoCurr, m_sAmount, m_oServiceBean);
//			m_sLocalAmount = FormatterUtils.formatGoldUnitDisplay (m_sAmount, true);
			m_sLocalAmount = m_sAmount; //m_sLocalAmount is same with transaction amount
			
			
			
			m_oViewBean.set (IBOwnGoldTransferConstant.TRANSACTION_DATE, DateTimeUtils.formatDayMonthYear (m_oCurrentDateTime));
			m_oViewBean.set (IBOwnGoldTransferConstant.TRANSACTION_TIME, m_oCurrentDateTime.getTime ());

			String m_sTransID = IBUtils.getTransactionId (getIBSessionObjects ().getDataManager ());
			
			
			
			p_oEnterpriseServices = new IBEnterpriseServicesWorkspace(getIBSessionObjects());
			m_sRimNo = (String)getIBSessionObjects ().getHttpSessionAttrObject (AccessConstants.RIM_NO);
			
			
			
			
			if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
			{
				ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
				if (!DataValidator.isEmptyString (m_oTCEnquiryBean.getAvailable_Bal ()))
				{
					m_dAvailableBal = Double.parseDouble (m_oTCEnquiryBean.getAvailable_Bal ());
				}

				m_dTotalTransferAmount = Double.parseDouble (m_sAmount);

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

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

//					String m_sDescription = m_sGOLD_DESC;
					
					m_oFromGoldEnquiryBean = getESBServices ().getAccountDetails (m_sFromAccount);
					m_oToAccEnquiryBean=getESBServices ().getAccountDetails (m_sToAccount);
										
					if(!DataValidator.isEmptyString(m_sFromAccount))
						m_sFromAccBranchCode=super.getBranchCodeByAccNo(m_sFromAccount); 			
					if (!DataValidator.isEmptyString (m_sFromAccBranchCode))
					{
						m_sFromAccBranchName=IBUtilsExtension.getGoldBranchNameByBranchCode(p_oEnterpriseServices, m_sFromAccBranchCode);
					}
					
//					m_oOwnTransfer = getESBServices ().ownFundTransfer (m_sFromAccount, m_sToAccount, m_sDescription, m_sAmount, m_sEffectiveDate);
					
					Map<String,ESBProcessBeanInterface> tranSet=new HashMap<String,ESBProcessBeanInterface>();
					
					
					ESBRequestXapi905Bean tranSetFirst=new ESBRequestXapi905Bean(m_oFromGoldEnquiryBean,
							EnumApplType.CK, EnumAccType.CK_GOLD, m_oToAccEnquiryBean.getAccountNo(),
							m_sAmount, m_sEffectiveDate, m_sServiceName, EnumPhoenixTranCode.TRANSFER_WITHDRAWAL ,
							m_sFromAccBranchCode, EnumDepLoan.DEP_DP,"",m_sRimNo);
					
					
					ESBXapi905Agent agent1=new ESBXapi905Agent(tranSetFirst);
					
					tranSet.put("1", agent1);

					Map<String, Document> responseMap=getEsbServiceFactory().implementService(tranSet);
				
					/////////
					
					ESBResponseXapi905Bean responseBean905=null;
					boolean isSuccess=false;
					ESBMsgHeader msgResponse=new ESBMsgHeader();
					
					
					for (String mapKey : responseMap.keySet()) {
						Document doc=responseMap.get(mapKey);
						if(doc != null){
							// *** start querying the response code from DOCMENT of transet ***
							Element root = doc.getRootElement ();
							msgResponse = new ESBProcessBean().processResponseCode(root);
							Element msgHeader = root.element ("MsgHeader");
							m_sPhx_Ref_no = (msgHeader.elementText ("ReferenceNo"));
							String code=mapKey.substring(mapKey.length()-2, mapKey.length());
							String key=mapKey.substring(0, mapKey.length()-2);	
							
							if(code.equalsIgnoreCase(GoldConstants.ESB_TRANS_SUCCESS) 
									&& ESBConstants.IB_SUCCESS_RC.equalsIgnoreCase(msgResponse.getResponseCode())){
								if(key.equalsIgnoreCase("1")){
									agent1.setDocument(doc);
									responseBean905=agent1.getResponsebean();
								}
								isSuccess=true;
							}else{
								//"*** failed response code **
								isSuccess=false;
								msgResponse.setResponseCode (ESBProcessBean.ESB_FAIL_CODE);
								msgResponse.setErrorMessage (ResourcesUtils.getServiceExceptionErrorKey ("esb.error.phx.PHX-",msgResponse.getResponseCode ()));
								break;
							}
						}else {
							//*** Document is null
							msgResponse.setResponseCode (ESBProcessBean.ESB_FAIL_CODE);
							msgResponse.setErrorMessage (ResourcesUtils.getServiceExceptionErrorKey ("esb.error.phx.PHX-",msgResponse.getResponseCode ()));						
							isSuccess=false;
							break;
						}						
						//!!! Response Code query ended !!!			
					}
					
					
					
					//////////
					if(responseBean905!=null){
//						m_sResponseCode = responseBean905.getResponseCode ();
						m_sReferenceNo = responseBean905.getTransactionReference();
//					m_sFromAccNewBal = m_oOwnTransfer.getFromAccountBalance ();
//					m_sToAccNewBal = m_oOwnTransfer.getToAccountBalance ();
					}
					
					if(isSuccess){
						//---- start getting outcome ----
						ESBRequestAccountBalanceBean m_oBeanReq = new ESBRequestAccountBalanceBean ();
						ESBAccountBalanceServices m_oService = new ESBAccountBalanceServices ();
						ESBAccountBalanceBean m_oBeanResp = null;
						
						// From Account Balance
						m_oBeanReq.setAccountNo (m_oFromGoldEnquiryBean.getAccountNo()); // get gold account no
						m_oBeanReq.setRimNo (m_sRimNo); // get gold account rim no
						m_oBeanResp = m_oService.retrieve (m_oBeanReq);
						responseBean905.setFromAccountNewBalance (m_oBeanResp.getCurrentBalance());// get new gram balance
						m_sFromAccNewBal = m_oBeanResp.getAvailableBalance();
						
						// To Account Balance
						m_oBeanReq.setAccountNo (m_oToAccEnquiryBean.getAccountNo());// get transfer to acc no
						m_oBeanReq.setRimNo (m_sRimNo); // get saving account rim no
						m_oBeanResp = m_oService.retrieve (m_oBeanReq);
//						responseBean904.setFromAccountNewBalance (m_oBeanResp.getCurrentBalance ());// get new account balance
						m_sToAccNewBal = m_oBeanResp.getAvailableBalance();
						
						//Account Creation Date
						ESBPhoenixWSServices mService = new ESBPhoenixWSServices();
						ESBRequestPhoenixWSBean m_oRequest = new ESBRequestPhoenixWSBean();

						// From Account Creation Date
						m_oRequest.setAcctNo (m_oFromGoldEnquiryBean.getAccountNo());// get gold account create date
						ESBAccCreateDateBean m_oAccCreateDateBean = mService.getAccCreateDate (m_oRequest);
//						responseBean905.setFromAccountCreateDate(m_oAccCreateDateBean.getDtAccOpen ());
						m_sFrmAccCrtDt = m_oAccCreateDateBean.getDtAccOpen ();
						
						// To Account creation Date
						m_oRequest.setAcctNo (m_oToAccEnquiryBean.getAccountNo()); //get saving account create date
						m_oAccCreateDateBean = mService.getAccCreateDate (m_oRequest);
//						responseBean904.setToAccountCreateDate(m_oAccCreateDateBean.getDtAccOpen ());
						m_sToAccCrtDt = m_oAccCreateDateBean.getDtAccOpen ();
						
//						TRANSACTION_SUCCESSFUL=true;
						//++successful area ++
//						if(responseBean905 != null && responseBean904!= null){
//							m_sNewGramBalance=responseBean905.getFromAccountNewBalance();//assign latest gram balance
//							m_sReferenceNo=refNoForPoenix;// assign reference no
////							costOfGold=responseBean905.getLocalEquivalentAmt();//assign the cost of gold in RM
//							actualAmount = FormatterUtils.formatMoneyDisplay(costOfGold, CurrencyCode.MALAYSIA_RINGGIT, true);
//						}
						m_boIsResultSuccessful = true;
						m_sStatus = ResourcesUtils.getSuccessful ();

						if(!DataValidator.isEmptyString (m_sFromAccNewBal))
						{
							m_dAmount = Double.parseDouble (m_sFromAccNewBal);
							if(m_dAmount != 0.00)
							{
								m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_FROM_ACC_NEW_BAL, Boolean.valueOf(true));
							}
						}

						if(!DataValidator.isEmptyString (m_sToAccNewBal))
						{
							m_dAmount = Double.parseDouble (m_sToAccNewBal);
							if(m_dAmount != 0.00)
							{
								m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_TO_ACC_NEW_BAL, Boolean.valueOf(true));
							}
						}
						m_oViewBean.set (IBOwnGoldTransferConstant.FROM_ACC_NEW_BAL, FormatterUtils.formatGoldUnitDisplay (m_sFromAccNewBal, true));
						m_oViewBean.set (IBOwnGoldTransferConstant.TO_ACC_NEW_BAL, FormatterUtils.formatGoldUnitDisplay (m_sToAccNewBal, true));
					
					}else{
						m_boIsResultSuccessful = false;
						m_sReason=msgResponse.getErrorMessage();
						m_sStatus=ResourcesUtils.getUnsuccessful();
					}
					
					
//					if (ESBConstants.IB_SUCCESS_RC.equalsIgnoreCase (m_sResponseCode))
//					{
//						m_boIsResultSuccessful = true;
//						m_sStatus = ResourcesUtils.getSuccessful ();
//						if(!DataValidator.isEmptyString (m_sFromAccNewBal))
//						{
//							m_dAmount = Double.parseDouble (m_sFromAccNewBal);
//							if(m_dAmount != 0.00)
//							{
//								m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_FROM_ACC_NEW_BAL, Boolean.valueOf(true));
//							}
//						}
//
//						if(!DataValidator.isEmptyString (m_sToAccNewBal))
//						{
//							m_dAmount = Double.parseDouble (m_sToAccNewBal);
//							if(m_dAmount != 0.00)
//							{
//								m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_TO_ACC_NEW_BAL, Boolean.valueOf(true));
//							}
//						}
//						m_oViewBean.set (IBOwnGoldTransferConstant.FROM_ACC_NEW_BAL,  m_sLocalAmount = FormatterUtils.formatGoldUnitDisplay (m_sFromAccNewBal, true));
//						m_oViewBean.set (IBOwnGoldTransferConstant.TO_ACC_NEW_BAL, FormatterUtils.formatGoldUnitDisplay (m_sToAccNewBal, true));
//					}
//					else //handle the negative testing,status=UNSUCCESSFUL
//					{
//						m_boIsResultSuccessful = false;
//						m_sStatus = ResourcesUtils.getUnsuccessful ();
//						m_sReason = m_oOwnTransfer.getErrorMessage ();
//					}
//					m_sFrmAccCrtDt = m_oOwnTransfer.getFromAccountCreateDate();
//					m_sToAccCrtDt = m_oOwnTransfer.getToAccountCreateDate();
				}
			}//end esb
			else
			{
				m_boIsResultSuccessful = true;
				m_sStatus = ResourcesUtils.getAccepted ();
				m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_FROM_ACC_NEW_BAL, Boolean.valueOf(false));
				m_oViewBean.set(IBOwnGoldTransferConstant.TO_DIS_TO_ACC_NEW_BAL, Boolean.valueOf(false));
			}

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

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

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

				m_oViewBean.set (CommonConstants.RECEIPT_MAP, m_oReceiptDetails);

				String m_sReceiptLink = IBUtils.getReceiptLink (IBOwnGoldTransferConstant.OWN_GOLD_TRANSFER_FORM, IBOwnGoldTransferConstant.OWN_GOLD_TRANSFER_BEAN);
				m_oViewBean.set (CommonConstants.RECEIPT_LINK, m_sReceiptLink);

			}

			if(!DataValidator.isEmptyString (m_sReferenceNo))
			{
				String m_sRefNoLabel = ResourcesUtils.getApplicationResourceMessage ("general.reference.number.short"); //(Ref No : )
				m_sDetails.append (IBOwnGoldTransferConstant.OWN_ACCOUNT).append ("<br>").append ("(").append (m_sRefNoLabel).append (":").append (m_sReferenceNo).append (")");
			}
			else
			{
				m_sDetails.append (IBOwnGoldTransferConstant.OWN_ACCOUNT);
			}
			
//			 SMS Notification START
			String m_sCustomerSMSMessage = "-";
			String m_sBeneficiarySMSMessage = "-";
			
			String m_sCustomerAmount = FormatterUtils.formatGoldUnitDisplay (m_sAmount, true);
			String m_sBeneficiaryAmount = FormatterUtils.formatGoldUnitDisplay (m_sAmount, true);
			
			String m_sTransactionTypeForSMSMessage = ResourcesUtils.getApplicationResourceMessage(ThirdPartyGoldTransferTags.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_OWN_GOLD);
			String beneName = getIBSessionObjects().getVisitor().getName();
			m_sCustomerSMSMessage = SMSServices.generateCustomerOtherSMSMessage(
					m_sTransactionTypeForSMSMessage, 
					m_sCustomerAmount, 
					m_sStatus,
					m_oCurrentDateTime,
					beneName.length()>14?beneName.substring(0, 14):beneName);
		
//			SMSServices.sendCustomerSMS(this, 
			SMSServiceGold.sendCustomerSMS2(this,
					m_oViewBean, 
					m_sFromAccount, 
					m_sStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransID,
					m_sAmount, 
					getIBSessionObjects().getVisitor().getId(), 
					m_sCustomerSMSMessage, 
					m_oCurrentDateTime);
			
			m_sBeneficiarySMSMessage = SMSServices.generateBeneficiaryOtherSMSMessage(
					m_oViewBean, 
					m_sTransactionTypeForSMSMessage, 
					m_sToAccount, 
					m_sBeneficiaryAmount, 
					m_oCurrentDateTime); 
			
//			SMSServices.sendBeneficiarySMS(this, 
			SMSServiceGold.sendBeneficiarySMS2(this, 
					getIBDynaBean(),
					m_oViewBean, 
					m_sFromAccount, 
					m_sStatus, 
					getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
					m_sServiceName, 
					m_sTransID,
					getIBSessionObjects().getVisitor().getId(), 
					m_sBeneficiarySMSMessage, 
					m_oCurrentDateTime);
			
			
			ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sFromAccount);
			
			m_oViewBean.set (IBOwnGoldTransferConstant.FROM_ACC_NEW_BAL, FormatterUtils.formatGoldUnitDisplay (m_oTCEnquiryBean.getAvailable_Bal(), true));
			
			// UAT START
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_BENE_SMS_SENT, SMSServices.isSMSLogged(this, m_oViewBean.get(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentDateTime.getDateDDMMMYYYYHMS()));
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_CUSTOMER_SMS_SENT, SMSServices.isSMSLogged(this, m_oViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentDateTime.getDateDDMMMYYYYHMS()));
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_BENE_SMS_MESSAGE, m_sBeneficiarySMSMessage);
			m_oViewBean.set(SMSConstants.VBEAN_SMS_UAT_CUSTOMER_SMS_MESSAGE, m_sCustomerSMSMessage);
			// UAT END

			// SMS Notification END

			getIBDynaBean ().set (IBOwnGoldTransferConstant.OWN_GOLD_TRANSFER_BEAN, m_oViewBean);

			//Log into IB_INTRA_GOLD_TRANSFER
			IBLoggerExtension.logTransferGold (this,
					m_sTransID,
					m_sServiceName,
					m_oCurrentDateTime,
					m_sFromAccount,
					m_sFromAccIsoCurr,
					m_sToAccount,
					m_sToAccIsoCurr,
					m_sLocalAmount,
					m_sAmount,
					"",
					m_sStatus,
					m_sReason,
					DateTimeUtils.convertStringToBVIDateTime (m_sEffectiveDate, "yyyyMMdd"),
					getIBSessionObjects ().getRemoteIPAddress (),
					m_sDetails.toString (),
					m_sReferenceNo,//m_sReferenceNo is Auth Code from Pheonix
					m_sServiceCode,
					"","",
					m_sFrmAccCrtDt,
					m_sToAccCrtDt,
					"","",String.valueOf (DataUtils.convertBooleanToInt (m_boSIIndicator)),
					m_sRimNo,m_sCustomerName
					);
			
			//Log into IB_GOLD_HISTORY
			IBLoggerExtension.logGoldHistoryFromTransfer(this, 
					m_sTransID, 
					m_oCurrentDateTime, 
					GoldConstants.TRNX_TYPE_TRANSFER, 
					m_sRimNo, 
					m_sCustomerName, 
					m_sFromAccount, 
					m_sToAccount, 
					"", //gold price
					"0" ,//total gold price 
					m_sAmount, 
					m_sFromAccBranchCode, 
					m_sFromAccBranchName, 
					m_sStatus, 
					getIBSessionObjects ().getRemoteIPAddress (), 
					m_sServiceCode,
					isStaff,
					DateTimeUtils.convertStringToBVIDateTime (m_sEffectiveDate, "yyyyMMdd"),		
					"",//email
					String.valueOf (DataUtils.convertBooleanToInt (m_boSIIndicator)));
		

//			//Log into IB_TRANSACTION_HISTORY
			IBLogger.logInetTranHistory (this,
					m_sTransID,
					m_sServiceName,
					m_sFromAccount,
					m_sFromAccIsoCurr,
					m_sToAccount,
					m_sToAccIsoCurr,
					m_sAmount,
					m_sDetails.toString (),
					m_sStatus,
					"","",
					m_sEffectiveDate,
					getIBSessionObjects ().getRemoteIPAddress (),
					"",
					true,
					m_sPhx_Ref_no,//to PHX_REFFERENCE_NO, m_sHostRefNo is Auth_code,if fail is null (should change to refference no
					"",
					"","",
					getIBSessionObjects ().getIBSessionId (),
					"","","",
					m_sFrmAccCrtDt,
					m_sToAccCrtDt,
					m_sReason,
					m_sPaymentMode,
					m_sPayFrequency,
					m_sTerminationDate,"",""
					);

			if (m_boSIIndicator && m_boIsResultSuccessful)
			{
				IBLogger.logSIDetail (
						this,
						m_sTransID,
						m_sTransID,
						SIConstantsExtension.TRANSCODE_OWN_GOLD_TRANSFER,
						m_sServiceName,
						m_sPaymentMode,
						m_sPayFrequency,
						m_sEffectiveDate,
						m_sTerminationDate,
						"", // No service code for own transfer, cos no transfer limit
						m_boDeleteSIIndicator
						);
			}

			getIBSessionObjects ().setAccountEnquiryBean (null);
		}
		catch (Exception e)
		{e.printStackTrace();
			if (e instanceof IBGenericException)
			{
				throw (IBGenericException) e;
			}

			throw IBErrorHandler.createServiceException(
					IBServiceException.GENERAL_SERVICE_ERROR, true,
					new String[] {CommonErrorCode.GENERIC_CODE, "", "", "", IBErrorHandler.generateErrorMessage(e)}, c_oClass);
		}

		IBLogger.logBSFNMethodLeavingMessage (c_oClass, m_sMethodName, m_oTimer);

	}

}
