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

package my.com.kfh.enterprise.services.ib105_billpayment;

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

import my.com.kfh.enterprise.services.IBUtils;
import my.com.kfh.enterprise.services.IBUtilsOnlineAcc;
import my.com.kfh.enterprise.services.common.CommonConstants;
import my.com.kfh.enterprise.services.common.TransactionConstants;
import my.com.kfh.enterprise.services.ib101_access.AccessConstants;
import my.com.kfh.enterprise.services.ib105_billpayment.constant.BillPaymentContants;
import my.com.kfh.enterprise.services.ib112_si.IBGenericSIServices;
import my.com.kfh.enterprise.services.ib112_si.SIConstants;
import my.com.kfh.enterprise.services.ib112_si.SI_PAYMENT_MODE;
import my.com.kfh.enterprise.services.ib114_online_contest.ContestContants;
import my.com.kfh.enterprise.services.ib116_online_acc.constant.OnlineAccConstants;
import my.com.kfh.error.exception.IBBusinessException;
import my.com.kfh.error.exception.IBGenericException;
import my.com.kfh.error.exception.IBServiceException;
import my.com.kfh.error.handler.CommonErrorCode;
import my.com.kfh.error.handler.IBErrorHandler;
import my.com.kfh.esb.response.ESBAccountEnquiryTC100Bean;
import my.com.kfh.esb.response.ESBBillPaymentBean;
import my.com.kfh.hibernate.tables.onlineMobile.BillPayment;
import my.com.kfh.hibernate.tables.onlineMobile.MobileReload;
import my.com.kfh.hibernate.tables.onlineMobile.MobileTransaction;
import my.com.kfh.hibernate.utils.HibernateOnlineAccUtils;
import my.com.kfh.hibernate.utils.onlineMobile.HibernateOnlineMobileReportsUtils;
import my.com.kfh.integration.OnlineAccPromoBean;
import my.com.kfh.sms.services.SMSConstants;
import my.com.kfh.sms.services.SMSServices;
import my.com.kfh.web.utils.BVI_DateTime;
import my.com.kfh.web.utils.DataUtils;
import my.com.kfh.web.utils.DataValidator;
import my.com.kfh.web.utils.DateTimeUtils;
import my.com.kfh.web.utils.FormatterUtils;
import my.com.kfh.web.utils.GSTUtils;
import my.com.kfh.web.utils.IBDynaBean;
import my.com.kfh.web.utils.IBLoadProperty;
import my.com.kfh.web.utils.IBLogger;
import my.com.kfh.web.utils.IBSessionObjects;
import my.com.kfh.web.utils.IBTimer;
import my.com.kfh.web.utils.ResourcesUtils;
import my.com.kfh.web.utils.SettingsUtils;
import my.com.kfh.web.utils.constant.ESBConstants;
import my.com.kfh.web.utils.constant.ServiceInfo;

/**
 * <pre>
 * PROGRAMMER: Jelson Low
 * CHANGE-NO:
 * TASK-NO:
 * DATE CREATED: Dec 21, 2008
 * TAG AS:
 * REASON(S):
 * MODIFICATION:
 * </pre>
 */

/**
 * This class handles the back end process of IBPaymentResults.
 */
public class IBPaymentResultsServices extends IBGenericPaymentServices
{
	private static Class c_oClass = IBPaymentResultsServices.class;

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

	/**
	 *<pre>
	 * To set the bill payment into database.
	 * Set the service limit if the max limit exist.
	 * If 'tac required' field in the service is true, then verify the tac entered by user.
	 * Check the daily limit for making bill payment
	 * If the amount of bill payment for that day exceeds the limit amount, then return unsuccessful status and set the error message
	 * else
	 * set the online as false if the payment type is prepaid, bill account no is empty and online is true
	 * execute the ePayPayment method based on the specified arguments
	 * Set the error message and status based on the response code of phoenix, epay and revert
	 * If both phoenix and epay success, no revert and no error message.
	 * If phoenix successes but epay fails then do revert and return error message for epay.
	 * If phoenix fails then return error message for phoenix, epay and revert are not required.
	 * After the above condition and if the status is successful, then create receipt for the billpayment
	 * set the required values into the map and execute the loopIntoReceiptDetails.
	 * create a link for receipt and set the map and link into bean
	 * Set all required data into beans.
	 * Log all bill payment details into table IB_TRANSACTION_HISTORY, IB_BILL_PAYMENT and IB_MOBILE_RELOAD.
	 *</pre>
	 *
	 * @throws IBGenericException Exception thrown for generic purposes
	 */
	public void executeServices () throws IBGenericException
	{
		String m_sMethodName = "executeServices";
		IBTimer m_oTimer = IBLogger.logBSFNMethodEnteringMessage (c_oClass, m_sMethodName);

		String m_sAmount 		= null;
		String m_sAccountNo 	= null;
		String m_sBillAccountNo = null;
		String m_sProductCode 	= null;
		String m_sPaymentType 	= null;
		String m_sBillAccNoDisplay = null;

		String m_sServiceCode 		= null;
		String m_sServiceMaxLimit 	= "";
		String m_sTransStatusMsg 	= null;
		String m_sReason = null;

		String m_sPhoenixRc = null;
		String m_sEPayRc 	= null;
		String m_sRevertRc 	= null;

		// for logger
		String m_sMerchantAccNo = null;
		String m_sMerchantId	= null;
		String m_sOperatorId 	= null;
		String m_sTerminalId    = null;
		String m_sMercRespCode  = null;
		String m_sMercRespMsg = null;
		String m_sTransTraceId  = null;

		String m_sTrnxID 	= null;
		String m_sTrnxType 	= null;
		String m_sDate 		= null;
		String m_sTime 		= null;
		String m_sStatus 	= null;
		boolean m_boIsResultSuccessful = false;
		String m_sTrnxTypeAll = null;

		String m_sPinNo = null;
		String m_sPinExDate = null;
		String m_sBalance = null;

		String m_sPhoenixReference 	= null;
		String m_sRevertReference 	= null;
		String m_sEPayReference 	= null;

		String m_sRechargeCode = null;
		String m_sReceiptLink = null;

		String m_sPaymentDesc = ESBConstants.BILL_PAYMENT;
		String m_sPaymentDescCharges = m_sPaymentDesc+" " +CommonConstants.CHARGES_LABEL;
		String m_sPaymentDescRevertCharges = m_sPaymentDesc+" " +CommonConstants.CHARGES_LABEL+CommonConstants.REVERT_LABEL;

		String m_sPaymentDescGSTCharges = m_sPaymentDesc+":GST Charges";
		String m_sPaymentDescRevertGSTCharges = m_sPaymentDesc+":Revert GST Charges";

		// mobilityOne fields must be declared as empty string first
		String p_sProdSubCode = "";
		String p_sContactNo = "";
		String p_sInfo2 =  "";
		String p_sInfo3 = "";
		String p_sNum = "";

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

		Date m_oDate = null;
		BVI_DateTime m_oCurrentBVIDateTime = new BVI_DateTime();
		StringBuffer m_sbDesc = new StringBuffer ();

		IBDynaBean m_oBillPaymentViewBean 	= null;
		IBDynaBean m_oPayeeDetailsBean 		= null;
		IBDynaBean m_oServiceInfoBean 		= null;

		ESBBillPaymentBean m_oESBPay = new ESBBillPaymentBean();
		ESBBillPaymentBean m_oESBGSTPay = new ESBBillPaymentBean();

		boolean m_boDeleteSIIndicator = false;
		boolean m_bContestFlag = false;

		Map<String, String> m_oReceiptMap = new LinkedHashMap<String, String> ();

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

		//Other Payees
		String m_sChargesIndicator = null;
		String m_sChargesAmount = null;
		String m_sChargesAcctCode = null;
		String m_sTrnxPaymentMode = null;
		String m_sMerchantAcctCode = null;
		String m_sDesc = null;
		String gstCharges = null;
		String gstGLAccountCode = "";
		String payeeName = "";
		String details = "-";

		//#-- added by pixa 20121017 start
		OnlineAccPromoBean onlineAccPromoBean = null;
		//#-- added by pixa 20121017 end --

		try
		{
			m_oBillPaymentViewBean 	= (IBDynaBean) getIBDynaBean ().get (BillPaymentContants.BILL_PAYMENT_VIEW_BEAN);
			m_oPayeeDetailsBean 	= (IBDynaBean) m_oBillPaymentViewBean.get (BillPaymentContants.PAYEE_DETAILS_VIEW_BEAN);
			m_oServiceInfoBean 		= (IBDynaBean) m_oBillPaymentViewBean.get (ServiceInfo.SERVICE_INFO_BEAN);
			gstGLAccountCode		= IBLoadProperty.getValue("gst.gl.account.code");

			if(m_oServiceInfoBean != null)
			{
				if (((Boolean) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_TAC_REQUIRED)).booleanValue ())
				{
					getIBAuthenticationServices ().userVerifyTac ((String) getIBDynaBean ().get (BillPaymentContants.FBEAN_TAC_VALUE),getIBSessionObjects().getIBSessionId());
				}
			}

			m_sPaymentType = (String) m_oBillPaymentViewBean.get(BillPaymentContants.PAYMENT_TYPE);

			m_sTrnxID 	= IBUtils.getTransactionId (getIBSessionObjects ().getDataManager ());
			m_sTrnxType = (String) m_oBillPaymentViewBean.get (BillPaymentContants.PAYMENT_TYPE);
			m_sDesc = (String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_PAYMENT_DESC);

			/*
			 *  Set transaction type and service code based on payment type
			 */
			if(isOpenPayment(m_sPaymentType)){
				m_sTrnxType = BillPaymentContants.BILL_PAYMENT_OPEN_PAYMENT;
				m_sServiceCode = ServiceInfo.BILL_PAYMENT_OPEN_PAYMENT;
				m_sSIServiceCode = ServiceInfo.SI_BILL_PAYMENT_OPEN_LIMIT;
			}
			else if(isFavouritePayment(m_sPaymentType)){
				m_sTrnxType = BillPaymentContants.BILL_PAYMENT_FAV_PAYMENT;
				m_sServiceCode = ServiceInfo.BILL_PAYMENT_FAV_PAYMENT;
				m_sSIServiceCode = ServiceInfo.SI_BILL_PAYMENT_FAV_LIMIT;
			}
			else if(isPrepaidPayment(m_sPaymentType)){
				m_sPaymentDesc = ESBConstants.PREPAID_TOP_UP;
				m_sTrnxType = BillPaymentContants.BILL_PAYMENT_PREPAID_PAYMENT;
				m_sServiceCode = ServiceInfo.BILL_PAYMENT_PREPAID_PAYMENT;
			}

			m_sTrnxTypeAll = m_sTrnxType;

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

			m_oDate = new Date ();
			m_sDate = DateTimeUtils.formatDayMonthYear (m_oDate);
			m_sTime = (DateTimeUtils.convertDateTime (m_oDate)).getTime ();
			m_sbDesc.append ((String) m_oServiceInfoBean.get (ServiceInfo.BEAN_ATT_SERVICE_NAME));
			m_sbDesc.append (" - ");
			m_sbDesc.append ((String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_FULL_NAME));

			m_sAmount 			= (String) getIBDynaBean ().get (BillPaymentContants.FBEAN_AMOUNT);
			m_sBillAccountNo 	= (String) getIBDynaBean ().get (BillPaymentContants.FBEAN_BILL_ACCOUNT_NO);
			m_sAccountNo 		= (String) m_oBillPaymentViewBean.get (BillPaymentContants.VBEAN_ACCOUNT_NO);
			m_sProductCode 		= (String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_MERC_AUTH_CODE);
			boolean m_bOnline 	= ((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_ONLINE_PAYMENT)).booleanValue();
			p_sInfo2 = (String)getIBDynaBean ().get(BillPaymentContants.FBEAN_BILL_REF1_NO);
			p_sInfo3 = (String)getIBDynaBean ().get(BillPaymentContants.FBEAN_BILL_REF2_NO);
			payeeName = (String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_FULL_NAME);
			m_sChargesIndicator = (String) m_oPayeeDetailsBean.get(BillPaymentContants.VBEAN_ISCHARGES);
			m_sChargesAmount = (String) m_oPayeeDetailsBean.get(BillPaymentContants.VBEAN_CHARGES_AMOUNT);
			m_sChargesAcctCode = (String) m_oPayeeDetailsBean.get(BillPaymentContants.VBEAN_CHARGES_ACCT);
			m_sTrnxPaymentMode = (String) m_oPayeeDetailsBean.get(BillPaymentContants.VBEAN_PAYMENT_MODE);
			m_sMerchantAcctCode = (String) m_oPayeeDetailsBean.get(BillPaymentContants.VBEAN_MERCHANT_ACC_NO);
			gstCharges = (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_GST_CHARGES);


			if (SI_PAYMENT_MODE.PAY_NOW.getCode ().equals (m_sPaymentMode))
			{
				m_oEffectiveDate = m_oCurrentBVIDateTime.getJavaDate ();

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

				//Pixakraft Bank Negara changes 25th Mar 2013 start
				boolean exceedGlobalLimit = exceedGlobalDailyLimit(this, m_sAmount, m_sServiceCode);
				//Pixakraft Bank Negara changes 25th Mar 2013 end
				//checkDailyLimit();
				Map m_oReturnMap = checkDailyLimit(this, m_sAmount, m_sServiceMaxLimit, m_sServiceCode);
				if (!Boolean.valueOf ((String) m_oReturnMap.get (BillPaymentContants.STATUS)).booleanValue ())
				{
					m_boIsResultSuccessful = false;
					m_sStatus = ResourcesUtils.getUnsuccessful ();
					m_sTransStatusMsg = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.BILL_PAYMENT,
							BillPaymentContants.ERR_MAX_AMOUNT,
							new String [] { FormatterUtils.formatMoneyDisplay (m_sServiceMaxLimit, null, true) });
					m_sReason = m_sTransStatusMsg;
				}
				//Pixakraft Bank Negara changes 25th Mar 2013 start
				else if (exceedGlobalLimit && !isPrepaidPayment(m_sPaymentType)){
					m_boIsResultSuccessful = false;
					m_sStatus = ResourcesUtils.getUnsuccessful ();
					String globalDailyLimit = IBPaymentUtils.getGlobalLimit(BillPaymentContants.GLOBAL_BILLPAYMENT_DAILY_LIMIT);
					m_sTransStatusMsg = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.BILL_PAYMENT,
							BillPaymentContants.ERR_GLOBAL_MAX_AMOUNT,
							new String [] { FormatterUtils.formatMoneyDisplay (globalDailyLimit, null, true) });
					m_sReason = m_sTransStatusMsg;
				}
				//Pixakraft Bank Negara changes 25th Mar 2013 end
				else
				{
					if (BillPaymentContants.isMobilityOne(m_oPayeeDetailsBean))
					{
						//no hard code contact no for M2
						if (BillPaymentContants.isMobilityTwo(m_oPayeeDetailsBean))
						{
							System.out.println("...m2");
							p_sProdSubCode = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_MERC_AUTH_SUB_CODE);
						}
						else
						{
							System.out.println("...m1");
							p_sProdSubCode = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_MERC_AUTH_SUB_CODE);
							p_sContactNo = (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_CONTACT_NO);

						}
					}


					if(isPrepaidPayment(m_sPaymentType))
					{
						if(m_bOnline && DataValidator.isEmptyString(m_sBillAccountNo))
						{
							m_bOnline = false;
						}
					}

					ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sAccountNo);
					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_sTransStatusMsg = ResourcesUtils.getApplicationResourceMessage (SIConstants.RESOURCES_INSUFFICIENT_FUND);
						m_sReason = m_sTransStatusMsg;
					}

					if(!DataValidator.isEmptyString(m_sBillAccountNo)){
						details = m_sBillAccountNo;
					}
					if(!DataValidator.isEmptyString(p_sInfo2)){
						details = details + "," + p_sInfo2;
					}

					if (m_boIsFundSufficient)
					{
						if(BillPaymentContants.isEPay(m_oPayeeDetailsBean))
						{
							m_oESBPay =	getESBServices ().ePayPayment (m_sTrnxID, m_sAccountNo, m_sAmount, m_sPaymentDesc, null, m_sProductCode, m_sBillAccountNo, m_bOnline, m_oDate, "", payeeName, details);
						}
						else if (BillPaymentContants.isMobilityOne(m_oPayeeDetailsBean))
						{
							if (BillPaymentContants.isMobilityTwo(m_oPayeeDetailsBean))
							{
								System.out.println("M2");
								System.out.println("m_sBillAccountNo: " + m_sBillAccountNo); //m1 phone #
								System.out.println("p_sInfo2: " + p_sInfo2);
								System.out.println("p_sInfo3: " + p_sInfo3);
								System.out.println("p_sNum: " + p_sNum);
								m_oESBPay =	getESBServices ().m1Payment (m_sTrnxID, m_sAccountNo, m_sAmount, m_sPaymentDesc, null,
										//BVMC bill account no field, ref1 field, ref2 field
										m_sProductCode, p_sProdSubCode, m_sBillAccountNo, p_sInfo2, p_sInfo3, "", p_sNum, "", payeeName,  details);
							}
							else
							{
								System.out.println("M1");
								System.out.println("p_sContactNo: " + p_sContactNo);
								System.out.println("m_sBillAccountNo: " + m_sBillAccountNo);
								System.out.println("p_sInfo2: " + p_sInfo2);
								System.out.println("p_sInfo3: " + p_sInfo3);
								System.out.println("p_sNum: " + p_sNum);
								
								m_oESBPay =	getESBServices ().m1Payment (m_sTrnxID, m_sAccountNo, m_sAmount, m_sPaymentDesc, null,
										m_sProductCode, p_sProdSubCode, p_sContactNo, m_sBillAccountNo, p_sInfo2, p_sInfo3, p_sNum, "", payeeName, details);

							}
						}
						else
						{
							//changes indicator = "YES" - apply charges | "NO" - No charges
							if(CommonConstants.isTrue (m_sChargesIndicator)&&!DataValidator.isEmptyString(m_sChargesAmount) && Double.valueOf(m_sChargesAmount)>0)
							{
								//#-- added by pixa 20121017 start --remember to include import at top
								onlineAccPromoBean = IBUtilsOnlineAcc.getChargesIfIsOnlineAccount(this,m_sAccountNo, OnlineAccConstants.BILL);
								if(onlineAccPromoBean !=null){
									m_sChargesAmount = onlineAccPromoBean.getPromotionCharges();
								}
//								//#-- added by pixa 20121017 end --
								//charges
								m_oESBPay = getESBServices().CommonBillerPayment(this, m_sAccountNo, m_sChargesAmount, m_sChargesAcctCode, m_sTrnxPaymentMode, m_sPaymentDescCharges, null, "", payeeName, details);
								
								if(ESBConstants.IB_SUCCESS_RC.equals(m_oESBPay.getResponseCode()))
								{
									if(!DataValidator.isEmptyString(gstCharges) && !(gstCharges.equals("0.00")||gstCharges.equals("0.0")||gstCharges.equals("0")))
									{
										//GST charges
										m_oESBGSTPay = getESBServices().CommonBillerPayment(this, m_sAccountNo, gstCharges, gstGLAccountCode, m_sTrnxPaymentMode, m_sPaymentDescGSTCharges, null, "", payeeName, details);
									
										if((!DataValidator.isEmptyString(gstCharges) && ESBConstants.IB_SUCCESS_RC.equals(m_oESBGSTPay.getResponseCode()))
												|| DataValidator.isEmptyString(gstCharges))
										{
											//transfer
											m_oESBPay = getESBServices().CommonBillerPayment(this, m_sAccountNo, m_sAmount, m_sMerchantAcctCode, m_sTrnxPaymentMode, m_sPaymentDesc, null, "", payeeName, details);
		
											if(!ESBConstants.IB_SUCCESS_RC.equals(m_oESBPay.getResponseCode()))
											{
												//Revert charges if fund transfer is fail.
												m_oESBPay = getESBServices().RevertBillerCharges(this, m_sChargesAcctCode, m_sChargesAmount, m_sAccountNo, m_sPaymentDescRevertCharges, null, "", payeeName, details);
												
												//Revert gst charges if fund transfer is fail.
												m_oESBGSTPay = getESBServices().RevertBillerCharges(this, gstGLAccountCode, gstCharges, m_sAccountNo, m_sPaymentDescRevertGSTCharges, null, "", payeeName, details);
											}
										}
										else{
											//Revert charges if fund transfer is fail.
											if(!DataValidator.isEmptyString(gstCharges))
												m_oESBPay = getESBServices().RevertBillerCharges(this, m_sChargesAcctCode, m_sChargesAmount, m_sAccountNo, m_sPaymentDescRevertCharges, null, "", payeeName, details);
										}
									}
									else
									{
										//transfer
										m_oESBPay = getESBServices().CommonBillerPayment(this, m_sAccountNo, m_sAmount, m_sMerchantAcctCode, m_sTrnxPaymentMode, m_sPaymentDesc, null, "", payeeName, details);
	
										if(!ESBConstants.IB_SUCCESS_RC.equals(m_oESBPay.getResponseCode()))
										{
											//Revert charges if fund transfer is fail.
											m_oESBPay = getESBServices().RevertBillerCharges(this, m_sChargesAcctCode, m_sChargesAmount, m_sAccountNo, m_sPaymentDescRevertCharges, null, "", payeeName, details);
										}
									}
									
								}
							}
							else
							{
								m_oESBPay = getESBServices().CommonBillerPayment(this, m_sAccountNo, m_sAmount, m_sMerchantAcctCode, m_sTrnxPaymentMode, m_sPaymentDesc, null, "", payeeName, details);
							}
						}
						
					
				
				

				m_sBalance 			= m_oESBPay.getFromAccountBalance ();
				m_sPhoenixReference = m_oESBPay.getTransferReferenceNo ();
				m_sEPayReference 	= m_oESBPay.getTransRef();
				m_sRevertReference	= m_oESBPay.getRevertReferenceNo();
				m_sPhoenixRc 	= m_oESBPay.getTransferResponseCode();
				m_sEPayRc 		= m_oESBPay.getMerchantResponseCode();
				m_sRevertRc 	= m_oESBPay.getRevertResponseCode();
				m_sMerchantAccNo = m_oESBPay.getMerchantAccNo();
				m_sMerchantId = m_oESBPay.getMerchantId();
				m_sOperatorId = m_oESBPay.getOperatorId();
				m_sTerminalId = m_oESBPay.getTerminalId();
				m_sMercRespCode = m_oESBPay.getMercRespCode ();
				m_sMercRespMsg = m_oESBPay.getMercRespMsg ();
				m_sTransTraceId = m_oESBPay.getTransTraceId();

				// Phoenix Transaction
				if(ESBConstants.IB_SUCCESS_RC.equals(m_sPhoenixRc))
				{
					// EPay Transaction
					if(ESBConstants.IB_SUCCESS_RC.equals(m_sEPayRc))
					{
						if(isPrepaidPayment(m_sPaymentType))
						{
							if(!DataValidator.isEmptyString (m_oESBPay.getPin()))
							{
								m_sPinNo = m_oESBPay.getPin();

								if(!DataValidator.isEmptyString (m_oESBPay.getPinExpiryDate()))
								{
									m_sPinExDate = m_oESBPay.getPinExpiryDate();
								}
							}
						}
						m_boIsResultSuccessful = true;
						m_sStatus 	= ResourcesUtils.getSuccessful ();
					}
					else
					{
						//Epay error

						m_sTransStatusMsg = m_oESBPay.getMerchantErrorMessage();
						m_sReason = m_sTransStatusMsg;

						// Revert Transaction
						if(!ESBConstants.IB_SUCCESS_RC.equals(m_sRevertRc))
						{
							// In case error occurs while Reverting
							m_sTransStatusMsg = m_oESBPay.getRevertErrorMessage();
							m_sReason = m_sTransStatusMsg;
						}
						m_boIsResultSuccessful = false;
						m_sStatus = ResourcesUtils.getUnsuccessful ();
					}

					//is this for iCube purpose?
					if(!DataValidator.isEmptyString(m_oESBPay.getMerchantAccNo()))
					{
						if(!BillPaymentContants.isEPay(m_oPayeeDetailsBean)
								&& !BillPaymentContants.isMobilityOneNTwo(m_oPayeeDetailsBean))
						{
							m_boIsResultSuccessful = true;
							m_sStatus 	= ResourcesUtils.getSuccessful ();
						}
					}
				}
				else
				{
					m_sTransStatusMsg = m_oESBPay.getTransferErrorMessage();
					m_sReason = m_sTransStatusMsg;
					m_boIsResultSuccessful = false;
					m_sStatus = ResourcesUtils.getUnsuccessful ();
				}
			}
		}
		//Checking Contest module
		String m_sContestAmount = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_AMOUNT);
		if(m_boIsResultSuccessful)
		{
			if(Double.parseDouble (m_sAmount)>Double.parseDouble (m_sContestAmount) || Double.parseDouble (m_sAmount)== Double.parseDouble (m_sContestAmount))
			{
				//check whether Contest is ON/OFF
				String m_sContestFlag = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_FLAG);

				if(m_sContestFlag.equalsIgnoreCase(ContestContants.ONLINE_CONTEST_ON))
				{
					//Check Date start & end date
					Date m_oTodayDate = new Date();
					String m_sStartDate = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_START_DATE);
					String m_sEndDate = SettingsUtils.getSetting(ContestContants.ONLINE_CONTEST_END_DATE);

					SimpleDateFormat m_oSDF = new SimpleDateFormat("dd/MM/yyyy");

					Date m_oStartDate = m_oSDF.parse(m_sStartDate);
					Date m_EndDate = m_oSDF.parse(m_sEndDate);

					if(m_oTodayDate.compareTo(m_oStartDate) > 0 && m_oTodayDate.compareTo(m_EndDate) < 0)
					{
						m_bContestFlag = true;
					}
				}
			}
		}
		m_oBillPaymentViewBean.set (ContestContants.IS_CONTEST_ON, m_bContestFlag);
	}
	// SI
	else
	{
		// stored SI Service code into IB_BILL_PAYMENT.SERVICE_CODE
		m_sServiceCode = m_sSIServiceCode;

		m_sTrnxTypeAll = IBGenericSIServices.getSITransType (m_sTrnxType, m_sPaymentMode);
		m_boSIIndicator = true;

		m_sEffectiveDate = (String)m_oBillPaymentViewBean.get (SIConstants.EFFECTIVE_DATE_FORMAT);
		BVI_DateTime m_oBVEffectiveDate = new BVI_DateTime (m_sEffectiveDate);
		m_oEffectiveDate = m_oBVEffectiveDate.getJavaDate ();
		if (SI_PAYMENT_MODE.RECURRING_PAYMENT.getCode ().equals (m_sPaymentMode))
		{
			m_sPayFrequency = (String)getIBDynaBean ().get (SIConstants.PAY_FREQUENCY);
			m_sPaymentFrequencyDisplay = (String)m_oBillPaymentViewBean.get (SIConstants.PAY_FREQUENCY_DISPLAY);
			m_sTerminationDateDisplay = (String)m_oBillPaymentViewBean.get (SIConstants.TERMINATION_DATE_DISPLAY);
			m_sTerminationDate = (String)m_oBillPaymentViewBean.get (SIConstants.TERMINATION_DATE_FORMAT);
		}

		Map m_oSILimitMap = IBGenericSIServices.verifySIDailyLimitByBank (this, getIBDynaBean (), getIBSessionObjects (),
				m_sSIServiceCode, m_sAmount, m_sEffectiveDate, false);

		if (!((Boolean) m_oSILimitMap.get (SIConstants.TRANS_STATUS)).booleanValue ())
		{
			m_boIsResultSuccessful = false;
			m_sStatus = ResourcesUtils.getUnsuccessful ();
			m_sReason = ResourcesUtils.getBusinessExceptionErrorMessage (IBBusinessException.SI,
					SIConstants.ERR_BANK_MAX_LIMIT,
					new String [] { FormatterUtils.formatMoneyDisplay ( (String)m_oSILimitMap.get (SIConstants.MAX_LIMIT),
							null, true) });
		}
		else
		{
			m_boIsResultSuccessful = true;
			m_sStatus 	= ResourcesUtils.getAccepted ();
		}
	}

	m_oBillPaymentViewBean.set (TransactionConstants.IS_RESULT_SUCCESSFUL, m_boIsResultSuccessful);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_STATUS, m_sStatus);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_REFERENCE_NO, FormatterUtils.formatTransID (m_sTrnxID));
	getIBDynaBean().set(BillPaymentContants.VBEAN_REFERENCE_NO, m_sTrnxID);
	getIBDynaBean().set(BillPaymentContants.FBEAN_TRNX_TYPE, m_sTrnxTypeAll);

	if(!DataValidator.isEmptyString(m_sBalance))
	{
		m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_FROM_ACCOUNT_BALANCE,
				FormatterUtils.formatMoneyDisplay (m_sBalance, null, true));
	}

	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_TRANSACTION_DATE, m_sDate);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_TRANSACTION_TIME, m_sTime);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_RECHARGE_CODE, m_sRechargeCode);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_TRANS_STATUS_MSG, m_sReason);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_PRODUCT_CODE, m_sProductCode);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_PIN_NO, m_sPinNo);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_PIN_EXPIRY_DATE, m_sPinExDate);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_ESB_REFERENCE_NO, m_sPhoenixReference);
	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_REVERT_REFERENCE_NO, m_sRevertReference);

	//   Start Create Receipt
	if(m_boIsResultSuccessful)
	{
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("receipt.transaction.type"), m_sTrnxTypeAll);
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.from.account"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_ACCOUNT_DISPLAY));
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.amount"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_AMOUNT_DISPLAY));

		if(!"-".equalsIgnoreCase((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_CHARGES_DISPLAY)))
			m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.charges"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_CHARGES_DISPLAY));

		String gstChargesdis = (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_GST_CHARGES_DISPLAY);
		if(!"-".equalsIgnoreCase(gstChargesdis)){
			m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.gst.charges"), gstChargesdis);
		}
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.payee"), (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_FULL_NAME));

		if( isFavouritePayment(m_sPaymentType) &&
				!DataValidator.isEmptyString((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_BILL_HOLDER_NAME)))
		{
			m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.bill.account.holder"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_BILL_HOLDER_NAME));
		}

		if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_ACCT_REQ)).booleanValue ()
				&& !DataValidator.isEmptyString((String)getIBDynaBean().get(BillPaymentContants.FBEAN_BILL_ACCOUNT_NO)))
		{
			String m_sBillAccDisplay = null;

			if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_ACCT_DISP_NAME_REQ)).booleanValue())
			{
				m_sBillAccDisplay = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_ACCT_DISP_NAME);
			}
			else
			{
				m_sBillAccDisplay = ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.bill.account.no");
			}
			m_oReceiptMap.put(m_sBillAccDisplay, (String)getIBDynaBean().get(BillPaymentContants.FBEAN_BILL_ACCOUNT_NO));
		}
		//there is no harded Contact # for M2
		if (BillPaymentContants.isMobilityOne(m_oPayeeDetailsBean))
		{
			//no hard code contact no for M2
			if (BillPaymentContants.isMobilityTwo(m_oPayeeDetailsBean))
			{
				System.out.println("...m2");//no contact no
				p_sProdSubCode = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_MERC_AUTH_SUB_CODE);
			}
			else
			{
				System.out.println("...m1");
				p_sProdSubCode = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_MERC_AUTH_SUB_CODE);
				m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.contact.no"), (String)getIBDynaBean().get(BillPaymentContants.FBEAN_CONTACT_NO));
				p_sContactNo = (String)getIBDynaBean().get(BillPaymentContants.VBEAN_CONTACT_NO);

			}
		}

		if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF1_REQ)).booleanValue()
				&& ((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF1_MANDATORY)).booleanValue())
		{
			String m_sBillRef1Display = null;

			if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF1_DISP_NAME_REQ)).booleanValue()
					&& !DataValidator.isEmptyString((String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF1_DISP_NAME)))
			{
				m_sBillRef1Display = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF1_DISP_NAME);
			}
			else
			{
				m_sBillRef1Display = ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.bil.reference.1");
			}
			m_oReceiptMap.put(m_sBillRef1Display, (String)getIBDynaBean().get(BillPaymentContants.FBEAN_BILL_REF1_NO));
		}

		if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF2_REQ)).booleanValue()
				&& ((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF2_MANDATORY)).booleanValue())
		{
			String m_sBillRef2Display = null;

			if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF2_DISP_NAME_REQ)).booleanValue()
					&& !DataValidator.isEmptyString((String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF2_DISP_NAME)))
			{
				m_sBillRef2Display = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_REF2_DISP_NAME);
			}
			else
			{
				m_sBillRef2Display = ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.bil.reference.2");
			}
			m_oReceiptMap.put(m_sBillRef2Display, (String)getIBDynaBean().get(BillPaymentContants.FBEAN_BILL_REF2_NO));
		}

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

		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.status"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_STATUS));

		//				if(!DataValidator.isEmptyString(m_sBalance))
		//				{
		//					m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.new.balance"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_FROM_ACCOUNT_BALANCE));
		//				}

		if(isPrepaidPayment(m_sPaymentType) &&
				!DataValidator.isEmptyString((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_PIN_NO)))
		{
			String m_sPinDisp = null;
			if(((Boolean)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_SERIAL_NO_INDICATER)).booleanValue())
			{
				m_sPinDisp = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_SERIAL_NO_NAME);
			}
			else
			{
				m_sPinDisp = ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.pin");
			}

			m_oReceiptMap.put(m_sPinDisp, (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_PIN_NO));

			if(!DataValidator.isEmptyString((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_PIN_EXPIRY_DATE)))
			{
				m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.pin.expiry.date"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_PIN_EXPIRY_DATE));
			}
		}

		if(!DataValidator.isEmptyString((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_ESB_REFERENCE_NO)))
		{
			m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.reference"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_ESB_REFERENCE_NO));
		}

		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.reference.number"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_REFERENCE_NO));
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.transaction.date"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_TRANSACTION_DATE));
		m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.transaction.time"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_TRANSACTION_TIME));

		//Add KFH GST Account No
		if(!"-".equalsIgnoreCase(gstChargesdis))
			m_oReceiptMap.put (ResourcesUtils.getApplicationResourceMessage ("general.gst.id.no"), IBLoadProperty.getValue("gst.id.no"));

		IBUtils.loopIntoReceiptDetails (this, m_oReceiptMap, DateTimeUtils.formatIBDateTimeToYMD(m_oDate), m_sTrnxID);
		m_oBillPaymentViewBean.set (CommonConstants.RECEIPT_MAP, m_oReceiptMap);
		m_sReceiptLink = IBUtils.getReceiptLink (BillPaymentContants.FORM_BEAN, BillPaymentContants.BILL_PAYMENT_VIEW_BEAN);
		m_oBillPaymentViewBean.set (CommonConstants.RECEIPT_LINK, m_sReceiptLink);
	}


	// End Create Receipt

	//			 SMS Notification START
	String m_sCustomerSMSMessage = "-";
	String m_sBeneficiarySMSMessage = "-";

	String m_sCustomerAmount = SMSServices.formatAmountValue(m_sAmount, null);
	String m_sBeneficiaryAmount = SMSServices.formatAmountValue(m_sAmount, null);

	String m_sTransactionTypeForSMSMessage = ResourcesUtils.getApplicationResourceMessage(SMSConstants.RESOURCE_SMS_TEXT_MESSAGE_SERVICE_BILL);
	String payeeShortName = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_SHORT_NAME);
	m_sCustomerSMSMessage = SMSServices.generateCustomerSMSMessage(
			m_sTransactionTypeForSMSMessage, 
			m_sCustomerAmount,
			payeeShortName.length()>14?payeeShortName.substring(0, 14):payeeShortName,
			m_sStatus, 
			new Date(),
			FormatterUtils.formatMoneyDisplay (m_sBalance, "", true));
	
	SMSServices.sendCustomerSMS(this, 
			m_oBillPaymentViewBean, 
			m_sAccountNo, 
			m_sStatus, 
			getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
			m_sTrnxTypeAll, 
			m_sTrnxID,
			m_sAmount, 
			getIBSessionObjects().getVisitor().getId(), 
			m_sCustomerSMSMessage, 
			m_oCurrentBVIDateTime,
			SMSConstants.DEBIT_IB_TYPE);

	m_sBeneficiarySMSMessage = SMSServices.generateBeneficiaryOtherSMSMessage(
			m_oBillPaymentViewBean, 
			m_sTransactionTypeForSMSMessage, 
			"", 
			m_sBeneficiaryAmount, 
			m_oCurrentBVIDateTime);

	SMSServices.sendBeneficiarySMS(this, 
			getIBDynaBean(),
			m_oBillPaymentViewBean, 
			m_sAccountNo, 
			m_sStatus, 
			getIBDynaBean().get(SIConstants.PAY_MODE).toString(), 
			m_sTrnxTypeAll, 
			m_sTrnxID,
			getIBSessionObjects().getVisitor().getId(),  
			m_sBeneficiarySMSMessage, 
			m_oCurrentBVIDateTime,
			"");

	ESBAccountEnquiryTC100Bean m_oTCEnquiryBean = getESBServices ().getAccountDetailsTC100 (m_sAccountNo);

	m_oBillPaymentViewBean.set (BillPaymentContants.VBEAN_FROM_ACCOUNT_BALANCE,
			FormatterUtils.formatMoneyDisplay (m_oTCEnquiryBean.getAvailable_Bal(), null, true));

	//			m_oReceiptMap.put(ResourcesUtils.getApplicationResourceMessage ("general.new.balance"), (String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_FROM_ACCOUNT_BALANCE));

	// UAT START
	m_oBillPaymentViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_BENE_SMS_SENT, SMSServices.isSMSLogged(this, m_oBillPaymentViewBean.get(SMSConstants.VBEAN_SMS_BENE_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentBVIDateTime.getDateDDMMMYYYYHMS()));
	m_oBillPaymentViewBean.set(SMSConstants.VBEAN_SMS_UAT_IS_CUSTOMER_SMS_SENT, SMSServices.isSMSLogged(this, m_oBillPaymentViewBean.get(SMSConstants.VBEAN_SMS_CUSTOMER_MOBILE_NO).toString(), SMSConstants.SMS_NOTIFICATION_TYPE, m_oCurrentBVIDateTime.getDateDDMMMYYYYHMS()));
	m_oBillPaymentViewBean.set(SMSConstants.VBEAN_SMS_UAT_BENE_SMS_MESSAGE, m_sBeneficiarySMSMessage);
	m_oBillPaymentViewBean.set(SMSConstants.VBEAN_SMS_UAT_CUSTOMER_SMS_MESSAGE, m_sCustomerSMSMessage);
	// UAT END

	// SMS Notification END

	getIBDynaBean ().set (BillPaymentContants.BILL_PAYMENT_VIEW_BEAN, m_oBillPaymentViewBean);

	String gstAbsorbedAmount = (String) m_oBillPaymentViewBean.get(BillPaymentContants.GST_CHARGES_WITHOUT_ROUNDING);
	String gstAbsorbed = GSTUtils.isGSTAmountAbsorbed(gstAbsorbedAmount);
	IBLogger.logInetTranHistory(
			this, 
			m_sTrnxID, //(String)m_oServiceInfoBean.get(ServiceInfo.BEAN_ATT_SERVICE_NAME),
			m_sTrnxTypeAll, 
			m_sAccountNo, 
			"", 
			"", 
			"", 
			m_sAmount, 
			m_sbDesc.toString (), 
			m_sStatus, 
			m_sBillAccountNo, 
			"", 
			m_sEffectiveDate, 
			getIBSessionObjects ().getRemoteIPAddress (), 
			"", 
			m_boIsResultSuccessful, 
			m_sPhoenixReference, 
			"", // Other1
			"", // Other2
			m_sEPayReference, 
			getIBSessionObjects ().getIBSessionId (), 
			m_sRevertReference, 
			"", // PhxChargeRefNo
			"", // PhxChargeRevertRefNo
			"", // FromAccCreateDate
			"", // ToAccCreateDate
			m_sReason,
			m_sPaymentMode,
			m_sPayFrequency,
			m_sTerminationDate,
			// Penril: Additional fields for GST report
			m_sChargesAmount,
			gstCharges,
			gstAbsorbed,
			gstAbsorbedAmount,
			getIBSessionObjects().getGSTGLAccount(),
			"",
			"",
			m_sPhoenixReference,
			String.valueOf(getIBSessionObjects().getVisitor().getId()),
			"" // No checking for staff account
			// End Penril: Additional fields for GST report
			);

	if(!DataValidator.isEmptyString((String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_ACCT_DISP_NAME)))
	{
		m_sBillAccNoDisplay = (String)m_oPayeeDetailsBean.get(BillPaymentContants.VBPAYEE_BILL_ACCT_DISP_NAME);
	}
	else
	{
		m_sBillAccNoDisplay = ResourcesUtils.getApplicationResourceMessage ("ib105.bill.payment.bill.account.no");
	}

	if(m_sTrnxType.equalsIgnoreCase(BillPaymentContants.BILL_PAYMENT_PREPAID_PAYMENT))
	{

		IBLogger.logPrepaidPaymentActivity(this,
				getIBDynaBean(),
				m_sTrnxID,
				m_sTrnxTypeAll,
				m_oCurrentBVIDateTime,
				getIBSessionObjects ().getRemoteIPAddress (),
				m_sPhoenixReference, "", "",
				m_sBillAccountNo,
				m_sRevertReference,
				m_sProductCode,
				m_sServiceCode,
				m_sEPayReference,
				m_sMerchantAccNo,
				m_sMerchantId,
				m_sOperatorId,
				m_sTerminalId,
				m_sPinNo,
				m_sPinExDate,
				m_sMercRespCode,
				m_sMercRespMsg,
				m_sTransTraceId,
				p_sProdSubCode,
				p_sContactNo,
				p_sInfo2,
				p_sInfo3,
				m_sChargesAmount,
				gstCharges,
				"",
				"",
				""
				);
	}
	else
	{
		if(DataValidator.isEmptyString(m_sBillAccountNo))
		{
			m_sBillAccountNo = "-";
		}

		IBLogger.logBillPaymentActivity(this,
				getIBDynaBean(),
				m_sTrnxID,
				m_sTrnxTypeAll,
				m_oCurrentBVIDateTime,
				m_oEffectiveDate,
				getIBSessionObjects ().getRemoteIPAddress (),
				m_sPhoenixReference, m_sDesc, "",
				m_sRevertReference,
				m_sProductCode,
				m_sServiceCode,
				m_sEPayReference,
				m_sMerchantAccNo,
				m_sMerchantId,
				m_sOperatorId,
				m_sTerminalId,
				m_sPinNo,
				m_sPinExDate,
				m_sMercRespCode,
				m_sMercRespMsg,
				m_sTransTraceId,
				p_sProdSubCode,
				p_sContactNo,
				p_sInfo2,
				p_sInfo3,
				m_sBillAccountNo,
				m_sBillAccNoDisplay,
				String.valueOf (DataUtils.convertBooleanToInt (m_boSIIndicator)),
				m_sChargesAmount,
				gstCharges);
	}
	if (m_boSIIndicator && m_boIsResultSuccessful &&
			!BillPaymentContants.BILL_PAYMENT_PREPAID_PAYMENT.equalsIgnoreCase (m_sTrnxType))
	{
		IBLogger.logSIDetail (
				this,
				m_sTrnxID,
				m_sTrnxID,
				SIConstants.TRANSCODE_BILL_PAYMENT,
				m_sTrnxTypeAll,
				m_sPaymentMode,
				m_sPayFrequency,
				m_sEffectiveDate,
				m_sTerminationDate,
				m_sSIServiceCode,
				m_boDeleteSIIndicator
				);
	}

	//#-- added by pixa 20121017 start
	if ( (!m_boSIIndicator) && m_boIsResultSuccessful && onlineAccPromoBean !=null &&
			!BillPaymentContants.BILL_PAYMENT_PREPAID_PAYMENT.equalsIgnoreCase (m_sTrnxType)){
		HibernateOnlineAccUtils.saveIBOnlineAccPromoTrnx(onlineAccPromoBean);
	} 
	//#-- added by pixa 20121017 end

	//#-- added by pixa(joo) 20130111 start
	try{
		String ChannelObj = "";
		if(getIBSessionObjects().getHttpSessionAttrObject("ChannelObj") != null)
		{
			ChannelObj = getIBSessionObjects().getHttpSessionAttrObject("ChannelObj").toString();
		}
		if(ChannelObj.equals("mobileApp"))
		{
			if(m_sTrnxType.equalsIgnoreCase(BillPaymentContants.BILL_PAYMENT_PREPAID_PAYMENT))
			{
				MobileTransaction m_oMobileTransaction = new MobileTransaction();
				m_oMobileTransaction.setDate(new Date());
				m_oMobileTransaction.setRimNo(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_RIM_NO));
				m_oMobileTransaction.setUsername(getIBSessionObjects ().getVisitor ().getName());
				m_oMobileTransaction.setCustomerName(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME));
				m_oMobileTransaction.setIbTransactionId(m_sTrnxID);
				m_oMobileTransaction.setTransactionType("1050");
				m_oMobileTransaction.setFromAccount(m_sAccountNo);
				//m_oMobileTransaction.setFromCy("");
				m_oMobileTransaction.setToAccount("");
				//m_oMobileTransaction.setToCy("");
				m_oMobileTransaction.setAmount(Double.valueOf(Double.parseDouble(m_sAmount)));
				m_oMobileTransaction.setStatus(m_sStatus);
				m_oMobileTransaction.setEffectiveDate(m_oEffectiveDate);
				m_oMobileTransaction.setRemoteIp(getIBSessionObjects ().getRemoteIPAddress ());
				m_oMobileTransaction.setPhoenixReference(m_sPhoenixReference);
				m_oMobileTransaction.setEpayReference(m_sEPayReference);
				m_oMobileTransaction.setPhoenixRevertReferenceNo(m_sRevertReference);
				//m_oMobileTransaction.setPhoenixChargesReferenceNo("");
				//m_oMobileTransaction.setPhoenixRevertChargesReferen("");
				m_oMobileTransaction.setDetails(m_sbDesc.toString ());
				m_oMobileTransaction.setFromAccountCreationDate(null);
				m_oMobileTransaction.setToAccountCreationDate(null);
				m_oMobileTransaction.setType("IN");

				//m_sPaymentDesc
				MobileReload mobileReload = new MobileReload();
				mobileReload.setPayeeCode((String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_PAYEE_CODE));
				mobileReload.setPayeeName((String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_FULL_NAME));
				mobileReload.setProductCode(m_sProductCode);
				mobileReload.setMobilePhoneNumber(m_sBillAccountNo);
				mobileReload.setServiceCode(m_sServiceCode);
				mobileReload.setMerchant(HibernateOnlineMobileReportsUtils.checkEmpty(m_sMerchantId).toString());
				mobileReload.setMerchantReferenceNo(m_sMerchantAccNo);
				mobileReload.setResponseMessage(m_sMercRespMsg);
				HibernateOnlineMobileReportsUtils.insertMobileReloadTransactionStore(m_oMobileTransaction, mobileReload);
			}
			else
			{	
				MobileTransaction m_oMobileTransaction = new MobileTransaction();
				m_oMobileTransaction.setDate(new Date());
				m_oMobileTransaction.setRimNo(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_RIM_NO));
				m_oMobileTransaction.setUsername(getIBSessionObjects ().getVisitor ().getName());
				m_oMobileTransaction.setCustomerName(getIBSessionObjects ().getVisitor ().getStringValue (AccessConstants.VISITOR_LAST_NAME));
				m_oMobileTransaction.setIbTransactionId(m_sTrnxID);
				m_oMobileTransaction.setTransactionType("1051");
				m_oMobileTransaction.setFromAccount(m_sAccountNo);
				//m_oMobileTransaction.setFromCy("");
				//m_oMobileTransaction.setToAccount("");
				//m_oMobileTransaction.setToCy("");
				m_oMobileTransaction.setAmount(Double.valueOf(Double.parseDouble(m_sAmount)));
				m_oMobileTransaction.setStatus(m_sStatus);
				m_oMobileTransaction.setEffectiveDate(m_oEffectiveDate);
				m_oMobileTransaction.setRemoteIp(getIBSessionObjects ().getRemoteIPAddress ());
				m_oMobileTransaction.setPhoenixReference(m_sPhoenixReference);
				m_oMobileTransaction.setEpayReference(m_sEPayReference);
				m_oMobileTransaction.setPhoenixRevertReferenceNo(m_sRevertReference);
				//m_oMobileTransaction.setPhoenixChargesReferenceNo("");
				//m_oMobileTransaction.setPhoenixRevertChargesReferen("");
				m_oMobileTransaction.setDetails(m_sbDesc.toString ());
				m_oMobileTransaction.setFromAccountCreationDate(null);
				m_oMobileTransaction.setToAccountCreationDate(null);
				m_oMobileTransaction.setType("IN");
				m_oMobileTransaction.setPaymentMode(m_sPaymentMode);

				BillPayment m_oBillPayment = new BillPayment();
				m_oBillPayment.setPayeeCode((String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_PAYEE_CODE));
				m_oBillPayment.setPayeeName((String) m_oPayeeDetailsBean.get (BillPaymentContants.VBPAYEE_FULL_NAME));
				m_oBillPayment.setProductCode(m_sProductCode);
				m_oBillPayment.setBillAccountNo(m_sBillAccountNo);
				m_oBillPayment.setBillAccountName((String)m_oBillPaymentViewBean.get(BillPaymentContants.VBEAN_BILL_HOLDER_NAME));
				m_oBillPayment.setMerchant("");//m_sMerchantId
				m_oBillPayment.setMerchantReferenceNo(m_sMerchantAccNo);
				m_oBillPayment.setResponseNo("");//m_sPinNo
				//m_oBillPayment.setSiIndicator(Short.valueOf(m_sPaymentMode));
				if(m_boSIIndicator){
					m_oBillPayment.setSiIndicator(Short.valueOf("1"));
				}
				else
				{
					m_oBillPayment.setSiIndicator(Short.valueOf("0"));
				}
				//m_oBillPayment.setSiIndicator(m_boSIIndicator);

				HibernateOnlineMobileReportsUtils.insertBillPaymentTransactionStore(m_oMobileTransaction, m_oBillPayment);
			}
		}
	}
	catch (Exception e)
	{

	}
	//#-- added by pixa(joo) 20130111 end

	getIBSessionObjects().setAccountEnquiryBean(null);
}
catch (Exception e)
{
	e.printStackTrace();

	m_sStatus = ResourcesUtils.getUnsuccessful ();
	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);
}
}
