<?php
include("../../../secure.php");
$path="../../../";
include("../../../map.php");
include("../../../scripts.php");
$yfd = new DateTime('first day of January');
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style type="text/css">
	table {font-family: 'Open Sans', sans-serif;}
	@media print { .noprint { display: none !important; } }
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td {
    padding: 3px;
    line-height: 1.2;
}
</style>
<?php if($_POST["ts1"]==""){?>
<form action="" method="post">
	<div class="col-sm-3">
		<input type="text" class="form-control" name="pay" list="li1" id="i1" placeholder="<?php echo translate("Tedavüldeki Pay Adedi")?>">
	</div>
	<div class="col-sm-3">
		<input type="date" class="form-control" name="ts1" placeholder="" value="<?php echo $yfd->format('Y-m-d')?>">
	</div>
	<div class="col-sm-3">
		<input type="date" class="form-control" name="ts2" placeholder="" value="<?php echo date('Y-m-d')?>">
	</div>
	<div class="col-sm-3">
		<button type="submit" name="btn" class="btn btn-warning" style="float:right;margin-right:10px;"><?php echo translate("Listele")?></button>
	</div>
</form>
<?php
}elseif($_POST["ts1"]<>""){
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and (t10>99 and t10<110) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$nbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and (t10>119 and t10<130) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$dbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and (t10>109 and t10<120) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$fvbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and (t10>129 and t10<140) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$gbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0; $atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and t2='142 01 002' order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$gkbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and t2<>'142 01 002' and (t10>139 and t10<150) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$dvbakiye=$btoplam-$atoplam;
	}
}
$btoplam=0;$atoplam=0;
$i=0;$sqlfu = mysqli_query($conn, "select * from t4 where s2=".$_SESSION["fID"]." and (t10>149 and t10<190) order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
	if($_REQUEST["ts1"]<>"" and ($rsfu["t9"]>=$_REQUEST["ts1"] and $rsfu["t9"]<=$_REQUEST["ts2"])){
		$btoplam=$btoplam+$rsfu["pb1"];
		$atoplam=$atoplam+$rsfu["pb2"];
		$dbbakiye=$btoplam-$atoplam;
	}
}
$toplam_deger=(($nbakiye+$dbakiye+$fvbakiye+$gbakiye+$gkbakiye+$dvbakiye)+$dbbakiye);
?>
<div class="container">
			<table class="table">
				<tr>
					<td scope="col" style="width:40%; font-size:11px;" class=""><?php echo $_SESSION["fName"]?></td>
					<td scope="col" style="text-align:center;" class=""><b><?php echo ihb($_REQUEST["tip"])?> Değerleme <?php if($_REQUEST["ts1"]<>"" or $_REQUEST["ts2"]<>""){?><br><?php echo dtarih($_REQUEST["ts1"],"gg.aa.yyyy")?>-<?php echo dtarih($_REQUEST["ts2"],"gg.aa.yyyy")?><?php }?></b></td>
					<td scope="col" style="width:30%; font-size:11px; text-align:right" class=""><?php echo dtarih(date("Y-m-d H:i:s"),"gg.aa.yyyy time")?></td>
				</tr>
			</table>
			<table class="table" style="font-size:11px; margin-top:25px;">
				<tr>
					<td scope="col" style="" class=""><?php echo translate("Portföy değeri")?></td>
					<td scope="col" style="width:20%; text-align:right;" class=""><?php echo number_format(($fvbakiye+$gbakiye+$gkbakiye),2,',','.')?></td>
				</tr>
				<tr>
					<td scope="col" style="" class=""><?php echo translate("Aktif değer")?></td>
					<td scope="col" style="width:20%; text-align:right;" class=""><?php echo number_format(($nbakiye+$dbakiye+$fvbakiye+$gbakiye+$gkbakiye+$dvbakiye),2,',','.')?></td>
				</tr>
				<tr>
					<td scope="col" style="" class=""><?php echo translate("Toplam değer")?></td>
					<td scope="col" style="width:20%; text-align:right;" class=""><?php echo number_format(($toplam_deger),2,',','.')?></td>
				</tr>
				<tr>
					<td scope="col" style="" class=""><?php echo translate("Pay değeri")?></td>
					<td scope="col" style="width:20%; text-align:right;" class=""><?php echo number_format(($toplam_deger/$_POST["pay"]),6,',','.')?></td>
				</tr>
			</table>
</div>
			<i class="btn btn-xs btn-warning fa fa-print noprint" style="position: absolute; top: 35px; right: 10px;" onclick="window.print();"></i>
			<a href="?" class="btn btn-xs btn-info fa fa-arrow-left noprint" style="position: absolute; top: 35px; right: 40px;"></a>
<?php }?>