<?php
include("../../../secure.php");
$path="../../../";
include("../../../map.php");
$yfd = new DateTime('first day of January');
if($_GET["print"]<>""){
	header("Content-Type: text/html;charset=utf-8");
	header('Content-Encoding: UTF-8');
	header("Content-Disposition: attachment; filename=".date("dmYHis").".xls");
	echo '<style type="text/css">table {border:1px solid !important;}</style>';
}else{
	include("../../../scripts.php");
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php if($_GET["print"]==""){?>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<?php }?>
<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(empty($_POST)){?>
<form action="" method="post">
	<div class="col-sm-2">
		<input type="text" class="form-control" name="kebir" list="li0" id="i0" placeholder="<?php echo translate("Kebir Hesap Kodu")?>">
			<datalist id="li0">
				<?php $sqlt1=mysqli_query($conn, "select * from t1 where s1=".$_SESSION["fID"]." and s2=1 order by n1,s10 asc"); while($rst1=mysqli_fetch_assoc($sqlt1)){?>
					<option <?php if($rst1["n3"]=="Grup" or $rst1["n3"]=="Muavin"){echo "disabled";}?> value="<?php echo $rst1["n1"]?>" data-ad="<?php echo $rst1["n2"]?>" data-tur="<?php echo $rst1["n3"]?>" data-tip="<?php echo $rst1["n4"]?>"><?php echo $rst1["n2"]?> {<?php echo $rst1["n3"]?>}</option>
				<?php }?>
			</datalist>
	</div>
	<div class="col-sm-3">
		<input type="text" class="form-control" name="muavin" list="li1" id="i1" placeholder="<?php echo translate("Muavin Hesap Kodu")?>">
			<datalist id="li1">
				<?php $sqlt1=mysqli_query($conn, "select * from t1 where s1=".$_SESSION["fID"]." and s2=1 order by n1,s10 asc"); while($rst1=mysqli_fetch_assoc($sqlt1)){?>
					<option <?php if($rst1["n3"]=="Grup" or $rst1["n3"]=="Kebir"){echo "disabled";}?> value="<?php echo $rst1["n1"]?>" data-ad="<?php echo $rst1["n2"]?>" data-tur="<?php echo $rst1["n3"]?>" data-tip="<?php echo $rst1["n4"]?>"><?php echo $rst1["n2"]?> {<?php echo $rst1["n3"]?>}</option>
				<?php }?>
			</datalist>
	</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-1">
		<button type="submit" name="btn" class="btn btn-warning" style="float:right;margin-right:10px;"><?php echo translate("Listele")?></button>
	</div>
</form>
<?php }elseif(!empty($_POST["muavin"])){ ?>
<?php $sqlfx = mysqli_query($conn, "select id,n2 from t1 where s1=".$_SESSION["fID"]." and n1='".$_POST["muavin"]."'"); $rsfx=mysqli_fetch_assoc($sqlfx);?>
			<table class="table">
				<tr>
					<td scope="col" style="width:40%; font-size:11px;" class=""><?php echo $_POST["muavin"]?><br><b><?php echo $rsfx["n2"]?></b><br><?php echo $_SESSION["fName"]?></td>
					<td scope="col" style="text-align:center;" class=""><b>Muavin Rapor</b><?php if($_POST["ts1"]<>"" or $_POST["ts2"]<>""){?><br><?php echo dtarih($_POST["ts1"],"gg.aa.yyyy")?>-<?php echo dtarih($_POST["ts2"],"gg.aa.yyyy")?><?php }?></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;">
				<tr>
					<th scope="col" style="width:10%;" class="">Fiş<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Fiş<br>No</th>
					<th scope="col" style="width:10%;" class="">Belge<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Belge<br>No</th>
					<th scope="col" style="width:10%;" class="">Vade<br>Tarihi</th>
					<th scope="col" style="" class="">Açıklama</th>
					<th scope="col" style="width:12%;" class="">Borç Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Alacak Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Bakiye</th>
				</tr>
				<?php
					$sqlf = mysqli_query($conn, "select id,t3,t4,t9,n1 from t4 where ne='fis' and s1=".$_SESSION["fID"]." order by t9 asc"); while($rsf=mysqli_fetch_assoc($sqlf)){
					$i=0;$sqlfu = mysqli_query($conn, "select id,t2,pb1,pb2 from t4 where s1='".$rsf["id"]."' and s2=".$_SESSION["fID"]." and t2='".$_POST["muavin"]."' order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
					if(($_POST["ts1"]=="" and $_POST["ts2"]=="") or ($_POST["ts1"]<>"" and $_POST["ts2"]<>"") and ($rsf["t9"]>=$_POST["ts1"] and $rsf["t9"]<=$_POST["ts2"])){
					$btoplam=$btoplam+$rsfu["pb1"];
					$atoplam=$atoplam+$rsfu["pb2"];
					$bakiye=$atoplam-$btoplam;
					if(intval($bakiye)<0){$t="B";}else{$t="A";}
				?>
				<tr>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["id"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t3"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["t4"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["n1"]?></td>
					<td scope="col" style="" class=""><?php if($rsfu["pb1"]<>0){echo number_format($rsfu["pb1"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php if($rsfu["pb2"]<>0){echo number_format($rsfu["pb2"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
				<?php }}}?>
				<tr>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""><?php echo number_format(abs($btoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($atoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
			</table>
<?php }elseif(empty($_POST["muavin"]) and empty($_POST["kebir"])){?>
			<table class="table">
				<tr>
					<td scope="col" style="width:40%; font-size:11px;" class="">Tüm Muavinler<br><?php echo $_SESSION["fName"]?></td>
					<td scope="col" style="text-align:center;" class=""><b>Muavin Rapor</b><?php if($_POST["ts1"]<>"" or $_POST["ts2"]<>""){?><br><?php echo dtarih($_POST["ts1"],"gg.aa.yyyy")?>-<?php echo dtarih($_POST["ts2"],"gg.aa.yyyy")?><?php }?></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;">
				<tr>
					<th scope="col" style="width:10%;" class="">Fiş<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Fiş<br>No</th>
					<th scope="col" style="width:10%;" class="">Belge<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Belge<br>No</th>
					<th scope="col" style="width:10%;" class="">Vade<br>Tarihi</th>
					<th scope="col" style="" class="">Açıklama</th>
					<th scope="col" style="width:12%;" class="">Borç Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Alacak Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Bakiye</th>
				</tr>
<?php
	$sqlfx = mysqli_query($conn, "select id,n1,n2 from t1 where s1=".$_SESSION["fID"]." and n3='Muavin' order by n1 asc"); while($rsfx=mysqli_fetch_assoc($sqlfx)){
	$sqlfu0 = mysqli_query($conn, "select id,t2,pb1,pb2 from t4 where s2=".$_SESSION["fID"]." and t2='".$rsfx["n1"]."' order by id asc"); $rsfu0=mysqli_fetch_assoc($sqlfu0);
?>
<?php if(mysqli_num_rows($sqlfu0)>0){?>
				<tr>
					<th scope="col" style="background: beige;" colspan="9"><?php echo $rsfx["n1"]?> {<?php echo $rsfx["n2"]?>}</th>
				<tr>
<?php }?>
				<?php
					//$sqlf = mysqli_query($conn, "select id,t3,t4,t9,n1 from t4 where ne='fis' and s1=".$_SESSION["fID"]." order by t9 asc"); while($rsf=mysqli_fetch_assoc($sqlf)){
					$i=0;$sqlfu = mysqli_query($conn, "select id,t2,pb1,pb2,s1 from t4 where s2=".$_SESSION["fID"]." and t2='".$rsfx["n1"]."' order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
					$sqlf = mysqli_query($conn, "select id,t3,t4,t9,n1 from t4 where ne='fis' and s1=".$_SESSION["fID"]." and id=".$rsfu["s1"]." order by t9 asc"); $rsf=mysqli_fetch_assoc($sqlf);
					if(($_POST["ts1"]=="" and $_POST["ts2"]=="") or ($_POST["ts1"]<>"" and $_POST["ts2"]<>"") and ($rsf["t9"]>=$_POST["ts1"] and $rsf["t9"]<=$_POST["ts2"])){
					$btoplam=$btoplam+$rsfu["pb1"];
					$atoplam=$atoplam+$rsfu["pb2"];
					$bakiye=$atoplam-$btoplam;
					if(intval($bakiye)<0){$t="B";}else{$t="A";}
				?>
				<tr class="mfrm cp" data-toggle="modal" data-target="#modalFull" data-title="<?php echo $_SESSION["fName"]?> Fiş Detay {<?php echo $rs19["t1"]?>}" data-url="../../accounting/accounting_voucher.php?id=<?php echo $rsf["id"]?>">
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["id"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t3"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["t4"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["n1"]?></td>
					<td scope="col" style="" class=""><?php if($rsfu["pb1"]<>0){echo number_format($rsfu["pb1"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php if($rsfu["pb2"]<>0){echo number_format($rsfu["pb2"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
				<?php }}?>
<?php }?>
				<tr>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""><?php echo number_format(abs($btoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($atoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
			</table>
<?php }elseif(!empty($_POST["kebir"])){?>
			<table class="table">
				<tr>
					<td scope="col" style="width:40%; font-size:11px;" class=""><b><?php echo $_POST["kebir"]?></b> Kebir > Muavinleri<br><?php echo $_SESSION["fName"]?></td>
					<td scope="col" style="text-align:center;" class=""><b>Muavin Rapor</b><?php if($_POST["ts1"]<>"" or $_POST["ts2"]<>""){?><br><?php echo dtarih($_POST["ts1"],"gg.aa.yyyy")?>-<?php echo dtarih($_POST["ts2"],"gg.aa.yyyy")?><?php }?></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;">
				<tr>
					<th scope="col" style="width:10%;" class="">Fiş<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Fiş<br>No</th>
					<th scope="col" style="width:10%;" class="">Belge<br>Tarihi</th>
					<th scope="col" style="width:10%;" class="">Belge<br>No</th>
					<th scope="col" style="width:10%;" class="">Vade<br>Tarihi</th>
					<th scope="col" style="" class="">Açıklama</th>
					<th scope="col" style="width:12%;" class="">Borç Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Alacak Tutar</th>
					<th scope="col" style="width:12%;" class=" tar">Bakiye</th>
				</tr>
<?php
	$sqlfx = mysqli_query($conn, "select n1 from t1 where s1=".$_SESSION["fID"]." and n3='Muavin' order by n1 asc"); while($rsfx=mysqli_fetch_assoc($sqlfx)){
	$sqlfu0 = mysqli_query($conn, "select id,t2,pb1,pb2 from t4 where s2=".$_SESSION["fID"]." and t2='".$rsfx["n1"]."' order by id asc"); $rsfu0=mysqli_fetch_assoc($sqlfu0);
if(substr($rsfx["n1"],0,3)==$_POST["kebir"]){
?>
<?php if(mysqli_num_rows($sqlfu0)>0){?>
				<tr>
					<th scope="col" style="background: beige;" class="" colspan="9"><?php echo $rsfx["n1"]?></th>
				<tr>
<?php }?>
				<?php
					$sqlf = mysqli_query($conn, "select id,t3,t4,t9,n1 from t4 where ne='fis' and s1=".$_SESSION["fID"]." order by t9 asc"); while($rsf=mysqli_fetch_assoc($sqlf)){
					$i=0;$sqlfu = mysqli_query($conn, "select id,t2,pb1,pb2 from t4 where s1='".$rsf["id"]."' and s2=".$_SESSION["fID"]." and t2='".$rsfx["n1"]."' order by id asc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
					if(($_POST["ts1"]=="" and $_POST["ts2"]=="") or ($_POST["ts1"]<>"" and $_POST["ts2"]<>"") and ($rsf["t9"]>=$_POST["ts1"] and $rsf["t9"]<=$_POST["ts2"])){
					$btoplam=$btoplam+$rsfu["pb1"];
					$atoplam=$atoplam+$rsfu["pb2"];
					$bakiye=$atoplam-$btoplam;
					if(intval($bakiye)<0){$t="B";}else{$t="A";}
				?>
				<tr>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["id"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t3"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["t4"]?></td>
					<td scope="col" style="" class=""><?php echo dtarih($rsf["t9"],"gg.aa.yyyy")?></td>
					<td scope="col" style="" class=""><?php echo $rsf["n1"]?></td>
					<td scope="col" style="" class=""><?php if($rsfu["pb1"]<>0){echo number_format($rsfu["pb1"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php if($rsfu["pb2"]<>0){echo number_format($rsfu["pb2"],2, ',', '.');}?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
				<?php }}}?>
<?php }}?>
				<tr>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""></td>
					<td scope="col" style="" class=""><?php echo number_format(abs($btoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($atoplam),2, ',', '.');?></td>
					<td scope="col" style="" class=" tar"><?php echo number_format(abs($bakiye),2, ',', '.')." ".$t;?></td>
				</tr>
			</table>
<?php }?>
<?php if(!empty($_POST)){?>
			<i class="btn btn-xs btn-warning fa fa-print noprint" style="position: absolute; top: 35px; right: 10px;" onclick="window.print();"></i>
			<form action="?print=yes&<?php echo Gets();?>" method="post">
			<?php echo Posts();?>
			<button type="submit" class="btn btn-xs btn-info fa fa-file-excel-o noprint" style="position: absolute; top: 35px; right: 40px;"></button>
			</form>
			<a href="?" class="btn btn-xs btn-info fa fa-arrow-left noprint" style="position: absolute; top: 35px; right: 70px;"></a>
<?php }else{?>
			<div style="position: absolute; bottom: 0px; font-size: 12px; background: beige; width: 100%; padding: 5px;">
				<p>- Kebir Hesap Kodu "Boş", Muavin Hesap Kodu "Boş"; Tüm Muavin Rapor</p>
				<p>- Kebir Hesap Kodu "Boş", Muavin Hesap Kodu "Dolu"; Muavin Rapor</p>
				<p>- Kebir Hesap Kodu "Dolu", Muavin Hesap Kodu "Boş"; Kebir Hesap Kodu'na Bağlı Muavin Rapor</p>
			</div>
<?php }?>