<?php
	$path="../../"; include("../../map.php");
	include("../../scripts.php");
 ?>
<div style="width:100%;">
<table class="table"  style="">
		<thead>
			<tr class="mdn">
				<th class="black-cell w10 mw10" style="">ID</span></th>
				<th scope="col" class=""><?php echo $t25; //Cari?></th>
				<th scope="col" class="w15 mw15"><?php echo translate("Fatura Tarihi")?></th>
				<th scope="col" class="w15 mw15"><?php echo translate("Vade Tarihi")?></th>
				<th scope="col" class="w15 mw15"><?php echo $sdil[154]; //Ödeme Tipi?></th>
				<th scope="col" class="w15 mw15 tar"><?php echo $sdil[176]; //tutar?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			$ts1="";$ts2="";
			if($_GET["type"]<>""){
				$sorgu="ne like '%".$_GET["type"]."%'";
			}else{
				$sorgu="ne='sfatura' or ne='afatura' or ne='ifatura'";
			}
			$sqlf = mysqli_query($conn, "select * from t4 where ".$sorgu." ".$luye." order by id desc"); while($rsf=mysqli_fetch_assoc($sqlf)){
				if(($_GET["ts1"]=="" and $_GET["ts2"]=="" and $rsf["t9"] >= date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))) or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($rsf["t9"]>=$_GET["ts1"] and $rsf["t9"]<=$_GET["ts2"])){
				$sqlm = mysqli_query($conn, "select * from t5 where id=".$rsf["s1"]." order by id desc"); $rsm=mysqli_fetch_assoc($sqlm);
				$tahsilat=0;
				$sqlhc=mysqli_query($conn, "select * from t4 where ne='cari' and s5=".$rsf["id"]." order by id desc"); while($hcari=mysqli_fetch_assoc($sqlhc)){
					$tahsilat = $tahsilat + $hcari["pb3"];
				}
				?>
				<tr class="cp <?php if($rsf["pb2"]<>$tahsilat){echo "bg-warning";}else{echo "bg-success";}?>" onclick="location.href='?ne=muhasebe&islem=<?php echo $rsf["ne"]?>&id=<?php echo $rsf["id"]?>'">
					<td scope="row" class="mdn table-check-cell"><?php echo i2a($rsf["id"],7);?><br><?php echo $rsf["t1"]?></td>
					<td class=""><?php echo $rsm["t1"]?> <?php echo $rsf["n2"]?></td>
					<td><?php echo dtarih($rsf["t9"],"gg ua yyyy")?><?php if($rsf["t6"]<>""){echo "<br>".dtarih($rsf["t6"],"gg ua yyyy");?> <?php if($rsf["pb2"]-$rsf["pb3"]<>0){?><?php if($rsf["pb2"]<>$tahsilat and $rsf["t6"]<>"" and date("Y-m-d") >= $rsf["t6"]){echo '<i class="fa fa-exclamation-triangle text-danger" title=""></i>';}}}?></td>
					<td class="mdn"><?php if($rsf["ne"]=="afatura"){?><?php echo $sdil[149]; //Alış?><?php }elseif($rsf["ne"]=="sfatura"){?><?php echo $sdil[148]; //Satış?><?php }elseif($rsf["ne"]=="ifatura"){?><?php echo $sdil[139]; //İptal?><?php }?> <?php echo $sdil[24]; //Faturalar?></td>
					<td class="mdn"><?php echo $rsf["t2"]?></td>
					<td style="text-align:right;">
						<?php echo number_format($rsf["pb2"], 2, ',', '.');?> <?php echo $ikpb?><br>
						<?php if($rsf["pb2"]<>$tahsilat){?>
						<b>Kalan Bakiye : <?php echo number_format($rsf["pb2"]-$tahsilat, 2, ',', '.');?> <?php echo $ikpb?></b>
						<?php }else{?>
						<b>Tahsil Edildi</b>
						<?php }?>
					</td>
				</tr>
			<?php }}?>
		</tbody>
	</table>
</div>