Your IP : 216.73.216.79


Current Path : /var/www/html/jkdm/
Upload File :
Current File : /var/www/html/jkdm/geneod.php

<?php
	//date_default_timezone_set("America/Anchorage");
	date_default_timezone_set('Asia/Dhaka');
	$servername = "10.13.182.98";
	$username = "mydlv";
	$password = "[0$7@mDB!]";
	$dbname = "jkdm";

	$pmt_crdate = date('Y-m-d H:i:s', strtotime('+2 hours'));
	
	// myopensoftnet
/*
	$servername = "myopensoft.ddns.net";
	$username = "root";
	$password = "[0$7@mDB!]";
	$dbname = "jkdm";
*/	
	// Create connection
	$conn = new mysqli($servername, $username, $password, $dbname);
	// Check connection
	if ($conn->connect_error) {
		die("Connection failed: " . $conn->connect_error);
	}


	//$directory = "D:/laragon2/www/mydlv/EOD";
	$directory = '/var/www/html/jkdm/EOD';
	$arrFile = array();
	
	// Open a directory, and read its contents
	if (is_dir($directory)){
	  if ($opendirectory = opendir($directory)){
		while (($file = readdir($opendirectory)) !== false){
			if ($file != "." && $file != ".." && $file != "newRHB.sh") {
				$arrFile[] = $file;
				//echo "filename:" . $file . "\n";
			}
		}
		closedir($opendirectory);
	  }
	}
	
	for ($i=0; $i<count($arrFile); $i++) {
		$newFile = $arrFile[$i];
		
		$sql2 = "SELECT filename FROM eod_header WHERE filename = '$newFile'";
		$result = mysqli_query($conn, $sql2);

		if (mysqli_num_rows($result) > 0) {
		  echo $newFile . ' exist'. "\n";
		} else {
			//echo "0 results : " . $newFile . '<BR>';
			$path = $directory.'/'.$newFile;
			$handle = @fopen($path, "r");
			
			while (!feof($handle)) // Loop til end of file.
			{
				$buffer = fgets($handle, 4096);
				
				$list = explode("|",$buffer);
				
				$totaldata = count($list);
				
				if ($totaldata == 3) { 			// Header
					//echo $list[0] . '-' . $list[1] . '-' . $list[2];
					$filename 		= $list[1];
					$filedate	  	= $list[2];
					$header = "INSERT INTO eod_header (filename, filedate, created_at) VALUES ('$filename', '$filedate', '$pmt_crdate')";
					$conn->query($header);
					$eodID = $conn->insert_id;
				} else if ($totaldata == 2) {	// footer - total data
					$recordcount = $list[0];
					$sql = "UPDATE eod_header SET 
						totalreceived	= '$recordcount'			
					WHERE 
						eodid = '$eodID'";
					$conn->query($sql);
				} else {						// data
					$trasactionid 	= $list[1];
					$msgToken 		= $list[2];			
					$refno 			= $list[3];
					$OrderNo 		= $list[4];
					$refno2 		= $list[5];
					$bankID 		= $list[6];
					$currency 		= $list[7];
					$amount 		= (double) str_replace(',', '', $list[8]);
					$amount2 		= (double) str_replace(',', '', $list[9]);
					$pmtCode 		= $list[10];
					$bankRef 		= $list[11];
					$com 			= $list[12];
					$acctno 		= $list[13];
					$others 		= $list[14];

					$eoddata = "INSERT INTO eod_data 
								(eodid, transactionid, pmt_msgtoken, refno, pmt_refno, refno2, pmt_bank, currency, amount_paid, pmt_amount, pmt_code, bank_ref, com, acctno, others, created_at) 
								VALUES 
								('$eodID', '$trasactionid', '$msgToken', '$refno', '$OrderNo', '$refno2', '$bankID', '$currency', '$amount', '$amount2', '$pmtCode', '$bankRef', '$com','$acctno','$others', '$pmt_crdate')
							";
					//echo $eoddata. '<br>';
					$conn->query($eoddata);
				}
			}
	  
		}
	}
	
	
	echo "done import\n";