<?php 
include_once("classes/database.class.php");

include_once("classes/oanda.php");


$userUId = $_POST['uid'];

$start = $_POST['start'];

$end = $_POST['end'];

$account = new oandaAPI();

$transactions = $account->getTransactions($userUId);

$transactions = $transactions['transactions'];

$tranxArray = array();

foreach ($transactions as $tranx) {

		$fulltime = $tranx['time'];

		$type = $tranx['type'];

		$explodeTime = explode('T', $fulltime);

		$transactionDate = $explodeTime[0];

		$startDateConverting = strtotime($start);

		$endDateConverting = strtotime($end);

		$convertingTranxDate = strtotime($transactionDate);

		$tranxChangeFormat = date('d M Y', $convertingTranxDate);

		$startDateCheck = date('Y-m-d', $startDateConverting);

		$differenceStartDate = $convertingTranxDate - $startDateConverting;

		$differenceEndDate = $convertingTranxDate - $endDateConverting;
			
		if ($differenceEndDate < 0 && $differenceStartDate >= 0) {
			
			$instrument = "";

			$tradeType = "";

			$tradeProfit = 0.0000;

			$fullProfit = 0.000;

			if ($type == 'ORDER_FILL') {
				# code...
				$instrument = $tranx['instrument'];

				$tradeType = $tranx['reason'];

				$instrument = str_replace('_', '-', $instrument);


				if ($tradeType == 'MARKET_ORDER') {
					# code...
					$tradeProfit = '-';
					
				}else{

					$getProfit = $tranx['tradesClosed'][0]['realizedPL'];

					$tradeProfit = $getProfit;

					$fullProfit = $fullProfit + $getProfit;
				}



			}

			$accountBalance = $tranx['accountBalance'];

			$fullarray = array('date'=>$tranxChangeFormat, 'instrument'=>$instrument, 'tradetype'=>$tradeType, 'balance'=>$accountBalance, 'profit'=>$tradeProfit, 'fullprofit'=>$fullProfit);

			if ($type == 'ORDER_FILL') {
				# code...
				array_push($tranxArray, $fullarray);
			}

			

		}

	


}

$result = array('result'=>$tranxArray);

print_r(json_encode($result));

?>