<?php 



include('view/new_header_file.php');



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



include_once("classes/oanda.php");



include_once('classes/phpToPDF.php');



$nowDate = date('Y-m-d');



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



$transactions = $transactions['transactions'];







?>









<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />



<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>



<style type="text/css">

	

	.dataTables_wrapper

	{

		margin-top: 50px !important;

	}

	.dataTables_length > label > select

	{

		text-transform: none;

		background-color: #202943;

		color: #fff;

		border-color: #202943;

		padding: 5px;

		width: 60px;

		margin-left: 10px;

		margin-right: 10px;

	}

	#tradeTable > thead, #tradeTable > tfoot

	{

		background-color: #131722 !important;

		color: #fff !important;

		padding: 10px !important;

	}

	table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd

	{

		color: #fff !important;

		background: #202943 !important;

	}

	table.dataTable.stripe tbody tr.odd, table.dataTable.display tbody tr.odd > .sorting_1

	{

		color: #fff !important;

		background: #202943 !important;

	}

	table.dataTable.display tbody tr.even > .sorting_1, table.dataTable.order-column.stripe tbody tr.even > .sorting_1

	{

		

		background: #0E1528 !important;

		color: #fff;	

	}

	table.dataTable tbody tr

	{

		background: #0E1528 !important;

		color: #fff;

	}

	#tradeTable > tfoot

	{

		padding-top: 10px !important;

		padding-bottom: 10px !important;

	}

	table.dataTable thead .sorting_asc

	{

		padding: 20px !important;

	}

	.dataTables_info

	{

		color: #fff !important;

	}

	.paginate_button

	{

		color: #fff !important;

	}

	.dataTables_wrapper .dataTables_paginate .paginate_button.disabled, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active

	{

		color: #fff !important;

	}

	.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover

	{

		background: #202943 !important;

		color: #fff !important;

		border-color: #202943 !important;

	}

	.dataTables_wrapper .dataTables_filter input

	{

		background: #202943 !important;

		color: #fff !important;

		border: none !important;

		padding-top: 5px !important;

		padding-bottom: 5px !important;

	}

	.fc-today{

		background: #F15A1F !important;



	}

	.fc-toolbar.fc-header-toolbar

	{

		background: #000 !important;

		padding: 20px !important;

	}
	body.crypt-dark table .fc-day
	{
		border:1px solid #005097 !important;
	}
	body.crypt-dark table th
	{
		background-color: #005097 !important;
		padding: 10px;
	}
	.fc-toolbar.fc-header-toolbar
	{
		background-color: #005097 !important;
		background: #005097 !important;	
	}
	.fc-view, .fc-view > table
	{
		border:1px solid #005097;
	}
	.fc-unthemed .fc-divider, .fc-unthemed .fc-popover .fc-header, .fc-unthemed .fc-list-heading td
	{
		background: #005097 !important;
	}
	.fc-unthemed .fc-divider, .fc-unthemed .fc-popover .fc-header, .fc-unthemed .fc-list-heading td:hover
	{
			background: #005097 !important;
		
	}
	.fc-allow-mouse-resize:hover, .fc-list-item:hover
	{
			background-color: #005097 !important;
	}
	.fc-list-item, .fc-list-heading
	{

		font-weight: 800 !important;
		font-size: 18px !important; 

	}
	.fc-list-item:hover
	{
		color: #000 !important;
	}
	
	.fc-list-item
	{

		color: #fff !important;

	}
	.fc-list-heading-alt
	{
		margin-left: 10px !important;
	}
</style>

  

<div class="container trade-container" style="margin-top: 40px;">



<div class="row">



	<div class="col-md-2">

		

	</div>



	<div class="col-md-8 col-lg-8">



		 <div id='theme-system-selector' class='selector'>

        Theme System:



        <select>

          <option value='bootstrap' selected>Bootstrap 4</option>

          <option value='standard'>unthemed</option>

        </select>

      </div>



      <div data-theme-system="bootstrap" class='selector' style='display:none'>

        <select style="display: none;">

          <option value='' selected>Default</option>

          <option value='cerulean'>Cerulean</option>

          <option value='cosmo'>Cosmo</option>

          <option value='cyborg'>Cyborg</option>

          <option value='darkly'>Darkly</option>

          <option value='flatly'>Flatly</option>

          <option value='journal'>Journal</option>

          <option value='litera'>Litera</option>

          <option value='lumen'>Lumen</option>

          <option value='lux'>Lux</option>

          <option value='materia'>Materia</option>

          <option value='minty'>Minty</option>

          <option value='pulse'>Pulse</option>

          <option value='sandstone'>Sandstone</option>

          <option value='simplex'>Simplex</option>

          <option value='sketchy'>Sketchy</option>

          <option value='slate'>Slate</option>

          <option value='solar'>Solar</option>

          <option value='spacelab'>Spacelab</option>

          <option value='superhero'>Superhero</option>

          <option value='united'>United</option>

          <option value='yeti'>Yeti</option>

        </select>

      </div>



      <span id='loading' style='display:none'>loading theme...</span>



       <div id='calendar'></div>









	<p style="color: #fff;">

		<?php 



		$tranxArray = array();



		$dateTransactionArray = array();



		foreach ($transactions as $trnx) {

			# code...

			$getTransactionsDate = $trnx['time'];



			$explodeDate = explode('T', $getTransactionsDate);



			array_push($dateTransactionArray, $explodeDate[0]);





		}



		$makeUniqueDateArray = array_unique($dateTransactionArray);



		$makeUniqueDateArray = array_values($makeUniqueDateArray);

		





			foreach ($transactions as $tranx) {



		$fulltime = $tranx['time'];



		$type = $tranx['type'];

	

		$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'];



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

			$tranxdate = $get_date[0];







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





			if ($type == 'ORDER_FILL') {



				array_push($tranxArray, $fullarray);

			

			}



	





}



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



$calendarString = "";



$get_full_result = $result['result'];







/*print_r($makeUniqueDateArray);*/





$calendarString = "";



foreach ($makeUniqueDateArray as $transaction_dates) {

	# code...



	$totalProfit = 0;



	foreach ($get_full_result as $fullResult) {





		$full_profit = $fullResult['fullprofit'];

		$full_time = $fullResult['time'];

		$full_type = $fullResult['tradetype'];







		if ($full_time == $transaction_dates) {



			$totalProfit = $totalProfit + $full_profit;





		}





	}





	$stringEval = "{

		title: '".$totalProfit."',

		start: '".$transaction_dates."',

	},";



	$calendarString = $calendarString.$stringEval;



}







		?>

	</p>













    </div>



	</div>





  <!-- Modal -->

  <div class="modal" id="calendarModal" role="dialog">

    <div class="modal-dialog">

    

      <!-- Modal content-->

      <div class="modal-content">

        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>

          <h4 class="modal-title">Modal Header</h4>

        </div>

        <div class="modal-body">

          <p>Some text in the modal.</p>

        </div>

        <div class="modal-footer">

          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

        </div>

      </div>

      

    </div>

  </div>











</div>

	





<?php



include('view/new_footer_file.php');



?>









<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>





<link href='calendar_assets/packages/core/main.css' rel='stylesheet' />

<link href='calendar_assets/packages/daygrid/main.css' rel='stylesheet' />

<script src='calendar_assets/packages/core/main.js'></script>

<script src='calendar_assets/packages/interaction/main.js'></script>

<script src='calendar_assets/packages/daygrid/main.js'></script>

<script src='calendar_assets/packages/bootstrap/main.js'></script>

<script src='calendar_assets/packages/interaction/main.js'></script>

<script src='calendar_assets/packages/list/main.js'></script>

<script src='calendar_assets/js/theme-chooser.js'></script>



<script>



  document.addEventListener('DOMContentLoaded', function() {

    var calendarEl = document.getElementById('calendar');

    var calendar;



    initThemeChooser({

      init: function(themeSystem) {

        calendar = new FullCalendar.Calendar(calendarEl, {

          plugins: [ 'bootstrap', 'interaction', 'dayGrid', 'timeGrid', 'list' ],

          themeSystem: 'darkly',

          header: {

            left: 'prev,next today',

            center: 'title',

            right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'

          },

          defaultDate: '<?=$nowDate ?>',

          weekNumbers: false,

          navLinks: true, // can click day/week names to navigate views

          editable: true,

          eventLimit: true, // allow "more" link when too many events

          events: [

            <?=$calendarString; ?>

          ],
          eventRender: function(info) {



          	var get_title = info.event.title;



          	var get_type = info.event._def.extendedProps.message;



          	trade_type = "";



	        	info.el.style.paddingTop = "1px";

	        	info.el.style.paddingBottom = "1px";

	        	info.el.style.border = "none";



	        if (get_title == 'Trade Opened') {

	        	

	        	info.el.style.backgroundColor  = "orange";


	       		 

	        }else{



	        	var intTitle = parseInt(get_title);



	        	if (intTitle < 0) {



	        		info.el.style.backgroundColor  = "red";



	        	}else{



	        		info.el.style.backgroundColor  = "green";

	        	}





	        	







	        }

	    },

	    eventClick:  function(event, jsEvent, view) {





        }

        });

        calendar.render();

      },



      change: function(themeSystem) {

        calendar.setOption('themeSystem', 'darkly');

      }



    });



  });



</script>





<!-- Development version -->

<script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.js"></script>



<!-- Production version -->

<script src="https://unpkg.com/@popperjs/core@2"></script>



<script>

 $("[data-toggle='tooltip']").tooltip();



</script>