Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/erp/controllers/
Upload File :
Current File : /var/www/html/mmishra/erp/controllers/anf_controller.php

<?php
//if (!class_exists($erpController)) {
	require_once __DIR__."/erp_controller.php";
//}
class anfController extends erpController {

    var $model;    
	
    public function __construct($model) {
		// call parent constructor
		// parent::__construct();
        // initialize variables
		
		$this->model 			= $model;
		$this->model->tupleID	= $this->tuple;

		$this->userIP 			= $this->getIP(); 			// requires in log entry			
		$this->appURL 			= $_SERVER['REQUEST_URI'];	// this is Request URI for log entry
		$this->referer 			= $_SERVER['HTTP_REFERER'];	// requires for log entry, not mandatory

		// maintain erp activity log for inner contents
		if ($_SESSION["loginID"] && strpos($this->appURL, 'inner')) {
			$this->model->erpLog($this->userIP, $this->appURL, $this->referer);
		} else if ($this->model->getMenuProtection($this->menu)) {
			print("<h1>Session expired. Please sign-in again.</h1>");
			exit;
		}			
    }

    public function __destruct() {
		
		//'Destroying: ', $this->moduleID, PHP_EOL;
        // log sql operation on corresponding table
        // call $erpModel->erpSql($sql);
        // print("Thanks.");
    }

	public function manageFeehead($action, $feeheadID) {
		$this->model->tableID 			= 'anf_feeheads';
		$this->model->tupleID 			= $feeheadID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$feeheadCode	 		= strtoupper($_POST['feeheadCode']);
				$feeheadName	 		= ucwords($_POST['feeheadName']);
				$accountType 			= $_POST['accountType'];
				$paymentTerm 			= $_POST['paymentTerm'];

				$this->model->saveFeehead($feeheadCode,$feeheadName,$accountType,$paymentTerm);
				$this->model->sqlLog();
                $this->errorText 		= 'Feehead record saved successfully.';
                break;
			case 'delete':
				$this->model->deleteFeehead();
				$this->model->sqlLog();
                $this->errorText 		= 'Feehead record deleted successfully.';
                break;
        }
		return $this->model->tupleID;
    }	

	public function manageFeechart($action, $feechartID) {
		$this->model->tableID 			= 'anf_feecharts';
		$this->model->tupleID 			= $feechartID;
		switch ($action) {
            case 'new':
			case 'edit':
				$this->editLock 		= '';
				break;
            case 'open':
            case 'help':
			case 'trash':
				break;
			case 'save':
                // save record
				$feeheadID	 			= $_POST['feeheadID'];
				$currency 				= $_POST['currency'];
				$feeAmount 				= $_POST['feeAmount'];
				if (!$feeAmount) $feeAmount = 0;
				$category 				= implode(',', $_POST['category']);
				$programID				= implode(',', $_POST['programID']);
				
				$this->model->saveFeechart($feeheadID,$currency,$feeAmount,$category,$programID);
				$this->model->sqlLog();
                $this->errorText 		= 'Feechart record saved successfully.';
                break;
			case 'delete':
				$this->model->deleteFeechart();
				$this->model->sqlLog();
                $this->errorText 		= 'Feechart record deleted successfully.';
                break;
        }
		return $this->model->tupleID;
    }	

	public function managePayment($action, $studentID) {
		$this->model->tableID 			= 'anf_payments';
		$this->model->tupleID 			= 0;
		switch ($action) {
			case 'online':
				$pg						= $this->params[0]; 	// ATOM or HDFC
				$accountType			= $this->params[1]; 	// 1 for fees, 2 for mess
				$paymentMode			= 'PG';			 		// online payment gateway
				$currency  				= 'INR';				// missing in PG response
				
				if ($pg == 'ATOM') {
					$paymentNo			= $_REQUEST['mmp_txn']; 	// transaction no.
					$datePayment		= date("Y-m-d"); // $_POST['date']; 		// date of transaction
					$bankName			= $_REQUEST['bank_name']; 	// name of bpayee bank
					$status				= $_REQUEST['f_code']; 	// status, OK for success, F for failure
					$amount				= $_REQUEST['amt']; 		// amount
					
					if (strtoupper($status) == 'OK') {
						$this->model->savePayment($studentID,$accountType,$paymentMode,$paymentNo,$bankName,$amount,$currency,$datePayment);
						$this->model->sqlLog();
						$this->errorText = "Transaction ID: $paymentNo => completed successfully.";
					} else {
						$this->errorText = $this->accountTypes[$accountType]. " payment transaction failed.";
					}
				} else if ($_POST['ResponseCode'] == 0) {						
					$paymentNo 			= $_POST['PaymentID'];	// payment ID
					$bankName 			= 'HDFC';				// missing in hdfc response
					$amount  			= $_POST['Amount'];
					$datePayment 		= $_POST['DateCreated'];
					
					$this->model->savePayment($studentID,$accountType,$paymentMode,$paymentNo,$bankName,$amount,$currency,$datePayment);
					$this->model->sqlLog();
					$this->errorText 	= "Transaction ID: $paymentNo => " .$_POST['ResponseMessage'];
				} else {
					$this->errorText 	= "Unidentified payment gateway.";
				}
				break;
			case 'save':
                // save record
				$accountType			= $this->params[0];
				$currency				= $this->params[2];
				
				$paymentMode			= $_POST['paymentMode'];
				$paymentNo				= $_POST['paymentNo'];
				$bankName				= ucwords($_POST['bankName']);
				$payAmount				= $_POST['payAmount'];
				$datePayment			= $_POST['datePayment'];
				
				if ($paymentNo) {
					$this->model->savePayment($studentID,$accountType,$paymentMode,$paymentNo,$bankName,$payAmount,$currency,$datePayment);
					//$this->model->sqlLog();
					$this->errorText 	= $this->accountTypes[$accountType]. " payment saved successfully.";
				} else {
					$this->errorText 	= "Payment No. is missing.";
				}
				break;
        }
		$this->model->tupleID 			= $studentID;
		return $this->model->tupleID;
    }	
}
// **********************************************************************
//							Payment processing
// **********************************************************************

class payment_config_test {
	var $Url 							= "https://paynetzuat.atomtech.in/paynetz/epi/fts";
	var $Login							= "160";
	var $Password						= "Test@123";
	//var $MerchantName					= "ATOM";
	var $MerchantName					= "NSE";
	var $TxnCurr						= "INR";
	var $TxnScAmt						= "0";
}

class payment_config {
	var $Url 							= "https://payment.atomtech.in/paynetz/epi/fts";
	var $Login							= "18589";
	var $Password						= "IIIT@123";
	var $MerchantName					= "IIIT";
	var $TxnCurr						= "INR";
	var $TxnScAmt						= "0";
}


class payment {
	var $url 							= null;

	function sendInfo($data){
		$ch 							= curl_init();

		curl_setopt($ch, CURLOPT_URL, $this->url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_PORT , 443); 
		//curl_setopt($ch, CURLOPT_SSLVERSION,3);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

		$returnData 					= curl_exec($ch);

		curl_close($ch);
			return $returnData;
	}
}

class ProcessPayment {
	function __construct() {
		$this->paymentConfig 			= new payment_config();
	}

	function requestMerchant() {
		$payment 						= new payment();
		$datenow 						= date("d/m/Y h:m:s");
		$modifiedDate 					= str_replace(" ", "%20", $datenow);
		$payment->url 					= $this->paymentConfig->Url;
		$postFields  					= "";
		
		$postFields .= "&login=" 		.$this->paymentConfig->Login;
		$postFields .= "&pass=" 		.$this->paymentConfig->Password;
		$postFields .= "&ttype=" 		.$_POST['TType'];
		$postFields .= "&prodid=" 		.$_POST['product'];
		$postFields .= "&amt=" 			.$_POST['amount'];
		$postFields .= "&txncurr=" 		.$this->paymentConfig->TxnCurr;
		$postFields .= "&txnscamt=" 	.$this->paymentConfig->TxnScAmt;
		$postFields .= "&clientcode=" 	.urlencode(base64_encode($_POST['clientcode']));//rollno
		$postFields .= "&txnid=" 		.rand(0,999999);
		$postFields .= "&date=" 		.$modifiedDate;
		$postFields .= "&custacc=" 		.$_POST['AccountNo'];
		$postFields .= "&ru=https://erp.iiita.ac.in/outer/anf/PGResponse/online/" .$_REQUEST['udf6']. "/ATOM/1";
		$postFields .= "&udf1=" 		.$_POST['udf1']; //name
		$postFields .= "&udf2=" 		.$_POST['udf2']; //email
		$postFields .= "&udf3=" 		.$_POST['udf3']; //mobile
		$postFields .= "&udf4=" 		.$_POST['udf4']; //program
		$postFields .= "&udf5=" 		.$_POST['udf5']; //batch
		$postFields .= "&udf6=" 		.$_REQUEST['udf6']; //studentID
		$postFields .= "&udf9=" 		.$_POST['udf9']; //semester

		$sendUrl = $payment->url. '?' 	.substr($postFields,1). "\n";

		$this->writeLog($sendUrl);

		$returnData 					= $payment->sendInfo($postFields);
		$this->writeLog($returnData. "\n");
		$xmlObjArray 					= $this->xmltoarray($returnData);

		$url 							= $xmlObjArray['url'];
		$postFields  					= "";
		$postFields .= "&ttype=" 		.$_POST['TType'];
		$postFields .= "&tempTxnId=" 	.$xmlObjArray['tempTxnId'];
		$postFields .= "&token=" 		.$xmlObjArray['token'];
		$postFields .= "&txnStage=1";
		$url = $payment->url. '?' 		.$postFields;
		$this->writeLog($url. "\n");

		header("Location: " .$url);
	}

	function writeLog($data){
		$fileName 						= date("Y-m-d").".txt";
		$fp 							= fopen("log/".$fileName, 'a+');
		$data 							= date("Y-m-d H:i:s")." - ".$data;
		fwrite($fp,$data);
		fclose($fp);
	}

	function xmltoarray($data){
		$parser 						= xml_parser_create('');
		xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
		xml_parse_into_struct($parser, trim($data), $xml_values);
		xml_parser_free($parser);

		$returnArray 					= array();
		$returnArray['url'] 			= $xml_values[3]['value'];
		$returnArray['tempTxnId'] 		= $xml_values[5]['value'];
		$returnArray['token'] 			= $xml_values[6]['value'];

		return $returnArray;
	}
}

?>