<meta charset="UTF-8">
<?php
$path="../../";
include("../../map.php");
?>
<style>
table tr td {border:1px solid #ccc;}
body {font-family: tahoma;}
</style>
<table style="width:100%;">
    <tr>
        <th style="width:8%">ID</th>
        <th style=";text-align:left;"><?php echo ctranslate("Ad Soyad/Firma");?></th>
        <th style="width:12%; text-align:right;"><?php echo ctranslate("Alacak");?></th>
        <th style="width:12%; text-align:right;"><?php echo ctranslate("Borç");?></th>
        <th style="width:12%; text-align:right;"><?php echo ctranslate("Bakiye");?></th>
        <th style="width:12%; text-align:right;"><?php echo ctranslate("Geciken");?></th>
    </tr>
    <?php
    if($_POST["s2"]<>""){
       $sorgu="and s2='".$_POST["s2"]."'";
   }
   $sql = mysqli_query($conn, "select * FROM t5 where t1 like '%".$_REQUEST["q"]."%' $sorgu $luye ORDER BY t1 asc"); while($rs = mysqli_fetch_assoc($sql)){ $jsi = json_decode($rs["n17"],true);
    $sqlc=mysqli_query($conn, "select * from t4 where ne='cari' and s1=".$rs["id"]." order by id desc");
	if(mysqli_num_rows($sqlc)>0){
		while($hcari=mysqli_fetch_assoc($sqlc)){
		//if($hcari["t12"]<>"" and $hcari["t12"] <= date("Y-m-d") and ($hcari["pb1"]>0)){$delayed = $delayed+ (($hcari["pb1"]-$hcari["pb2"]));}
		if($hcari["t4"]<>"" and $hcari["t4"] <= date("Y-m-d") and ($hcari["pb1"]>0)){$delayed = $delayed+ (($hcari["pb1"]-($hcari["pb2"]+$hcari["pb3"])));}
        if($hcari["t4"]=="0-00-00" and ($_POST["ts1"]=="" and $_POST["ts2"]=="") or ($_POST["ts1"]<>"" and $_POST["ts2"]<>"") and ($hcari["t4"]>=$_POST["ts1"] and $hcari["t4"]<=$_POST["ts2"])){
           include("../clients/client_current_calc2.php");
       }}
       ?>
       <tr>
        <td><?php echo i2a($rs["id"],7);?></td>
        <td><?php echo $rs["t1"]?> <?php if($jsi["ifirma"]<>""){echo "{".$jsi["ifirma"]."}";}?></td>
        <td style="text-align:right;"><?php echo wprice($cpb1); $alacak = $alacak + ($cpb1);?></td>
        <td style="text-align:right;"><?php echo wprice($cpb2-$cpb3); $borc = $borc + ($cpb2+$cpb3);?></td>
        <td style="text-align:right;"><?php echo wprice(($cpb1-$cpb2)-($cpb3-$cpb4)); $bakiye = $bakiye + (($cpb1-$cpb2)-($cpb3-$cpb4));?></td>
        <td style="text-align:right;"><?php if(($cpb1-$cpb2)-($cpb3-$cpb4)>0){echo wprice($delayed);}else{echo "0.00";}; $vdt = $vdt + ($delayed);?></td>
    </tr>
<?php $delayed=0; $cpb1=0;$cpb2=0;$cpb3=0;$cpb4=0;}}?>
       <tr>
        <td></td>
        <td style="text-align:right;"><?php echo ctranslate("Toplam")?> : </td>
        <td style="text-align:right;"><?php echo wprice($alacak);?></td>
        <td style="text-align:right;"><?php echo wprice($borc);?></td>
        <td style="text-align:right;"><b><?php echo wprice($bakiye);?></b></td>
        <td style="text-align:right;"><?php echo wprice($vdt);?></td>
    </tr>
</table>