<?php
	$path="../../";
	include("../../map.php");
	
	//$uitems = json_decode(GetArr("kayit"), true);
	$sqlu=mysqli_query($conn, "select * from t5 where ne='uye' $luye order by t1 asc"); while($rsu=mysqli_fetch_assoc($sqlu)){$u++; $users[] = $rsu; }
	$i=0;$sqlc=mysqli_query($conn, "select * from t4 where ne='cari' and n1 LIKE '%".$_GET["iq"]."%' and s1=".$_GET["id"]." $qry $luye order by t4 desc");
	$sqlu=mysqli_query($conn, "select * from t5 where id=".$_GET["id"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu); $cariname=$rsu["t1"];
	$sqlx=mysqli_query($conn, "select id,t1 from ".$_SESSION["lang"]." where ne='client_project' and s13=1 order by t1 asc");
	//-- Bakiye Hesapla -->
	//$itarih = explode(',',$date('d.m.Y'));
?>
<style>
<?php if($mobile<>""){?>
	.current_btn {margin-top:-15px; position:absolute; right:15px; z-index:999;}	
<?php }?>
</style>
<script type="text/javascript">
	jQuery(document).keypress(function(e){
		if (e.keyCode == 27){
			jQuery("#myModal").modal('hide');
		}
	});
	jQuery(function() {
		jQuery(".mfrm").click(function (){
			jQuery("#myModal").fadeIn();
			var title = jQuery(this).attr("data-title");
			jQuery(".modal-title").html(title);
			var theModal = jQuery(this).data("target"),
			frmSRC = jQuery(this).attr("data-url");
			var refSRC = jQuery(this).attr("data-ref");
			if(refSRC != undefined){
				jQuery(theModal + ' .mcbtn').attr('onclick', 'location.href=\''+refSRC+'\'');
			}
			jQuery(theModal + ' iframe').attr('src', frmSRC);
			jQuery(theModal + ' .close').click(function () {
				jQuery(theModal + ' iframe').attr('src', 'about:blank');
			});
		});
	});
	jQuery(".cmdl").click(function (){
		event.preventDefault();
		jQuery('#myModal').fadeOut('slow');
		jQuery('#modalFull').fadeOut('slow');
		jQuery('.modal-backdrop').fadeOut('slow');
		loadFunction('modules/clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&ts1=<?php echo $_GET["ts1"];?>&ts2=<?php echo $_GET["ts2"];?>','#icari', '');
	});
</script>
<form class="mdn" method="post" action="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=ycari" name="aform" id="ncurrent" autocomplete="off" style="width:100%;">
	<input type="hidden" name="cs2" id="cs2" value="0">
	<input type="hidden" name="cs5" id="cs5" value="<?php if($_SESSION["ProjeID"]>0){echo $_SESSION["ProjeID"];}else{echo "0";}?>">
	<table class="table fs13 mfs12" style="">
		<thead>
			<tr>
				<th><?php echo $sdil[40]; //İşlem Açıklama?><?php if($_SESSION["ProjeID"]>0){echo " PId".$_SESSION["ProjeID"];}?></th>
				<th class="w13 mw13"><?php echo $sdil[168]; //Tip?></th>
				<th class="w10 mw10 dn"><?php echo ctranslate("İşlem")?></th>
				<th class="w8 mw8"><?php echo $sdil[115]; //Tarih?></th>
				<th class="w10 mw10"><?php echo $sdil[154]; //Ödeme Tipi?></th>
				<th class="w8 mw8 tar"><span class="v3-bg-warning" style="padding: 5px 10px;"><?php echo ctranslate("Alacak")?></span></th>
				<th class="w8 mw8 tar"><span class="v3-bg-danger" style="padding: 5px 10px;"><?php echo ctranslate("Borç")?></span></th>
				<th class="w8 mw8 tar <?php if($module["e8_type"]=="1"){echo "dn";}?>"><span class="v3-bg-success" style="padding: 5px 10px;"><?php echo ctranslate("Alınan")?></span></th>
				<th class="w8 mw8 tar <?php if($module["e8_type"]=="1"){echo "dn";}?>"><span class="v3-bg-info" style="padding: 5px 10px;"><?php echo ctranslate("Ödenen")?></span></th>
				<th class="w10 mw5"></th>
			</tr>
		</thead>
		<tbody>
			<tr class="addtr" data-id="0" data-cke="0" data-action="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=ycari" data-url="../clients/ajax_client_current.php" data-did="#icari">
				<td>
					<input type="text" name="cn1" id="cn1" list="cln1" class="form-control" style="" placeholder="<?php echo $sdil[40]; //İşlem Açıklama?>" autofocus autocomplete="off">
					<datalist id="cln1" style="display:none;">
						<?php $sqlt=mysqli_query($conn, "select * from t4 where (ne='sfatura' or ne='afatura' or ne='ifatura')"); while($tip=mysqli_fetch_assoc($sqlt)){?>
							<option value="<?php echo $tip["t1"]?> <?php echo ctranslate("Nolu Fatura");?>" id="<?php echo $tip["id"]?>"><?php echo $tip["pb2"]?> <?php echo $kpb?></option>
						<?php }?>
						<?php foreach($users as $key=>$value){?>
							<option value="<?php echo $value["t1"]?>" id="<?php echo $value["id"]?>"><?php echo $value["t1"]?></option>
						<?php }?>
					</datalist>
					<script>
						jQuery( "#cn1" ).change(function(){
							var inputVal = jQuery(this).val();
							var id = jQuery("#cln1 option[value='"+inputVal+"']").attr("id");
							jQuery( "#cs2" ).val(id);
						});
					</script>
				</td>
				<td align="center">
					<input type="text" list="nst" id="ct11" name="ct11" class="form-control with-tip" title="<?php echo $sdil[168]; //Tip?> (t11)" placeholder="<?php echo $sdil[168]; //Tip?>" value="" autocomplete="off">
					<datalist id="nst" style="display:none;">
						<?php while($rsx=mysqli_fetch_assoc($sqlx)){?>
							<option id="<?php echo $rsx["id"]?>" value="<?php echo $rsx["t1"]?>"><?php echo $rsx["t1"]?></option>
						<?php }?>
						<?php if(mysqli_num_rows($sqlx)==0){?>
							<?php $sqlt=mysqli_query($conn, "select Distinct t11 from t4 where ne='cari' and t1<>''"); while($tip=mysqli_fetch_assoc($sqlt)){?>
								<option value="<?php echo $tip["t11"]?>" id="0"><?php echo $tip["t11"]?></option>
							<?php }?>
						<?php }?>
					</datalist>
					<script>
						jQuery("#ct11").change(function() {
							var inputVal = jQuery(this).val();
							var id = jQuery("#nst option[value='"+inputVal+"']").attr("id");
							jQuery("#cs5").val(id);
						});
					</script>
				</td>
					<td class="dn">
						<select name="y" class="form-control">
							<option value="Alacak"><?php echo $sdil[155]; //Alacak?></option><option value="Alınan"><?php echo $sdil[156]; //Alınan?></option><option value="Borç"><?php echo $sdil[156]; //Borç?></option><option value="Ödenen"><?php echo $sdil[158]; //Ödenen?></option>
						</select>
					</td>
				<td align="center">
					<input type="date" name="ct4" class="form-control " style="text-align:right;" value="<?php echo date("Y-m-d");?>">
				</td>
				<td align="center">
					<div style="display:flex">
						<select name="ct1" class="sna form-control" style="float:left;">
							<option value="Nakit"><?php echo $sdil[160]; //Nakit?></option>
							<option value="Banka"><?php echo $sdil[161]; //Banka?></option>
							<option value="Pos"><?php echo $sdil[162]; //Pos?></option>
							<option value="Çek"><?php echo $sdil[163]; //Çek?></option>
							<option value="Senet"><?php echo translate("Senet")?></option>
							<option value="Taksit"><?php echo $sdil[227]; //Taksit?></option>
						</select>
						<select name="ct6" class="sfa sna w45 form-control" style="float:left;">
							<option value="TRY" <?php if($kpb=="TRY"){echo "selected";}?>>&#xf195;</option>
							<option value="EUR" <?php if($kpb=="EUR"){echo "selected";}?>>&#xf153;</option>
							<option value="USD" <?php if($kpb=="USD"){echo "selected";}?>>&#xf155;</option>
							<option value="GBP" <?php if($kpb=="GBP"){echo "selected";}?>>&#xf154;</option>
						</select>
					</div>
				</td>
				<td align="center">
					<input type="text" name="cpb1" class=" form-control" value="0.00" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
				</td>
				<td class="<?php if($module["e8_type"]=="1"){echo "dn";}?>" align="center">
					<input type="text" name="cpb2" class=" form-control" value="0.00" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
				</td>
				<td class="" align="center">
					<input type="text" name="cpb3" class=" form-control" value="0.00" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
				</td>
				<td class="<?php if($module["e8_type"]=="1"){echo "dn";}?>" align="center">
					<input type="text" name="cpb4" class=" form-control" value="0.00" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
				</td>
				<td align="left">
					<a class="btn btn-warning btn-update-row" style="cursor:pointer; line-height:0px; padding:5px;" <?php if($_SESSION["kim"]=="yonetici"){?>Disabled<?php }?>><i class="fa fa-plus "></i></a>
				</td>
			</tr>
		</tbody>
	</table>
</form>
	<?php
		while($hcari=mysqli_fetch_assoc($sqlc)){$i++;
		if($hcari["t4"]==""){
			if($hcari["s3"]<10){$cs3="0".$hcari["s3"]."";}else{$cs3=$hcari["s3"];}
			if($hcari["s2"]<10){$cs2="0".$hcari["s2"]."";}else{$cs2=$hcari["s2"];}
			$tarih="".$hcari["s4"]."-".$cs3."-".$cs2."";
			$Rs = mysqli_query($conn, "update t4 set t4='".$tarih."' Where id=".$hcari["id"]."");
		}else{
			$tarih=dtarih($hcari["t4"],"yyyy-aa-gg");
		}
		$hide = false;
		if (mysqli_num_rows($sqlx) > 0) {
			if ($_SESSION["kim"] == "yonetici") {
				// Yönetici: ProjeID boşsa veya eşleşmiyorsa gizle
				if ($_SESSION["ProjeID"] == "" || $_SESSION["ProjeID"] != $hcari["s5"]) {
					$hide = true;
				}
			} else {
				// Yönetici değilse: ProjeID eşleşmiyorsa gizle
				if ($_SESSION["ProjeID"] !="" && $_SESSION["ProjeID"] != $hcari["s5"]) {
					$hide = true;
				}
			}
		}
	?>
<?php
		if($_GET["ts1"]=="" && $_GET["ts2"]==""){include("client_current_calc2.php");}
		if($hcari["t4"]=="0-00-00" or ($_GET["ts1"]=="" and $_GET["ts2"]=="" and $hcari["t4"] >= date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))) or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($hcari["t4"]>=$_GET["ts1"] and $hcari["t4"]<=$_GET["ts2"])){
		if($_GET["ts1"]<>"" && $_GET["ts2"]<>""){include("client_current_calc2.php");}
?>
	<form class="" method="post" action="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>&durum=kcari" name="aform" id="ecurrent" autocomplete="off" style="width:100%; <?php if ($hide) { echo "display:none"; }?>">                       
		<input type="hidden" name="cs2" id="cs2_<?php echo $hcari["id"];?>" value="<?php echo $hcari["s2"]?>">
		<input type="hidden" name="cs5" id="cs5_<?php echo $hcari["id"];?>" value="<?php echo $hcari["s5"]?>">
		<table class="table ddn  fs13 mfs12" style="">
			<tr class="v3-bg-<?php if($hcari["pb4"]>0){echo "info";}elseif($hcari["pb3"]>0){echo "success";}elseif($hcari["pb2"]>0){echo "danger";}elseif($hcari["pb1"]>0){echo "warning";}?>" data-id="<?php echo $hcari["id"];?>" data-cke="0" data-href="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>" data-action="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>&durum=kcari" data-url="../clients/ajax_client_current.php" data-did="#icari">
				<td class="">
					<?php echo kisalt($hcari["n1"],20);?>
				</td>
				<td class="mw25 tar">
					<?php if($hcari["pb3"]>0){echo "".wprice($hcari["pb3"])." <i class=\"fa fa-".strtolower($hcari["t6"])."\"></i>";}else{echo "".wprice($hcari["pb1"])." <i class=\"fa fa-".strtolower($hcari["t6"])."\"></i>";}?>
				</td>
				<td align="left" class="mw21 tw10 tar">
					<div style="margin-top:2px;">
						<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-success mfrm" data-toggle="modal" data-target="#myModal" data-width="90%" data-ajax="icari" data-url="../../fonksiyon.php?islem=cdetail&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>"><i class="fa fa-pencil "></i></a>
						<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-danger btn-delete-row" <?php if ($auth<>3){echo "Disabled";}?> data-href="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>&durum=scari"><i class="fa fa-times " style="padding:0px;"></i></a>
					</div>
				</td>
			</tr>
		</table>
		<table class="table mdn  fs13 mfs12" style="">
			<tr class="v3-bg-<?php if($hcari["pb4"]>0){echo "info";}elseif($hcari["pb3"]>0){echo "success";}elseif($hcari["pb2"]>0){echo "danger";}elseif($hcari["pb1"]>0){echo "warning";}?>" data-id="<?php echo $hcari["id"];?>" data-cke="0" data-href="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>" data-action="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>&durum=kcari" data-url="../clients/ajax_client_current.php" data-did="#icari">
				<td style="position:relative;">
					<?php if($hcari["t12"]<>""){?>
						<i class="fas fa-clock" style="position: absolute; right: 0px; top: 15px;" title="<?php echo dtarih($hcari["t12"],"gg ka yyyy")?>"></i>
					<?php }?>
					<input type="text" name="cn1" list="cln1_<?php echo $hcari["id"];?>" id="cn1_<?php echo $hcari["id"];?>" value="<?php echo $hcari["n1"];?>" class="form-control" autocomplete="off">
					<datalist id="cln1_<?php echo $hcari["id"];?>" style="display:none;">
						<?php $sqlt=mysqli_query($conn, "select * from t4 where s1='".$_GET["id"]."'"); while($tip=mysqli_fetch_assoc($sqlt)){?>
							<option value="<?php echo $tip["t1"]?> <?php echo ctranslate("Nolu Fatura");?>" id="<?php echo $tip["id"]?>"><?php echo $tip["pb2"]?> <?php echo $kpb?></option>
						<?php }?>
						<?php foreach($users as $key=>$value){?>
							<option value="<?php echo $value["t1"]?>" id="<?php echo $value["id"]?>"><?php echo $value["t1"]?></option>
						<?php }?>
					</datalist>
					<script>
						jQuery( "#cn1_<?php echo $hcari["id"];?>" ).change(function(){
							var inputVal = jQuery(this).val();
							var id = jQuery("#cln1_<?php echo $hcari["id"];?> option[value='"+inputVal+"']").attr("id");
							jQuery( "#cs2_<?php echo $hcari["id"];?>" ).val(id);
						});
					</script>
					</td>
					<td class="w13 mw13">
						<input type="text" list="est_<?php echo $hcari["id"];?>" name="ct11" id="ct11_<?php echo $hcari["id"];?>" class="form-control with-tip" title="<?php echo $sdil[168]; //Tip?> (t1)" placeholder="<?php echo $sdil[168]; //Tip?>" value="<?php echo $hcari["t11"]?>" autocomplete="off">
						<datalist id="est_<?php echo $hcari["id"];?>" style="display:none;">
							<?php $sqlt=mysqli_query($conn, "select Distinct t11 from t4 where ne='cari'"); while($tip=mysqli_fetch_assoc($sqlt)){?>
								<option value="<?php echo $tip["t11"]?>"><?php echo $tip["t11"]?></option>
							<?php }?>
						</datalist>
					<script>
						jQuery("#ct11_<?php echo $hcari["id"];?>").change(function() {
							var inputVal = jQuery(this).val();
							var id = jQuery("#est_<?php echo $hcari["id"];?> option[value='"+inputVal+"']").attr("id");
							jQuery("#ss5_<?php echo $hcari["id"];?>").val(id);
						});
					</script>
					</td>
					<td class="w10 mw10 dn">
						<select name="y" class="form-control ">
							<option value="Alacak" <?php if($hcari["pb1"]<>"0"){echo "Selected"; }?>><?php echo $sdil[155]; //Alacak?></option><option value="Alınan" <?php if($hcari["pb2"]<>"0"){echo "Selected"; }?>><?php echo $sdil[156]; //Alınan?></option><option value="Borç" <?php if($hcari["pb3"]<>"0"){echo "Selected"; }?>><?php echo $sdil[156]; //Borç?></option><option value="Ödenen" <?php if($hcari["pb4"]<>"0"){echo "Selected"; }?>><?php echo $sdil[158]; //Ödenen?></option>
						</select>
					</td>
					<td align="center" class="w8 mw8">
						<input type="date" name="ct4" class="form-control " style="text-align:right;" value="<?php echo $tarih;?>">
					</td>
					<td align="center" class="w10 mw10">
						<div style="display:flex">
							<select name="ct1" class="sna form-control" style="float:left;">
								<option value="Nakit" <?php if($hcari["t1"]=="Nakit"){?>Selected<?php }?>><?php echo $sdil[160]; //Nakit?></option>
								<option value="Banka" <?php if($hcari["t1"]=="Banka"){?>Selected<?php }?>><?php echo $sdil[161]; //Banka?></option>
								<option value="Pos" <?php if($hcari["t1"]=="Pos"){?>Selected<?php }?>><?php echo $sdil[162]; //Pos?></option>
								<option value="Çek" <?php if($hcari["t1"]=="Çek"){?>Selected<?php }?>><?php echo $sdil[163]; //Çek?></option>
								<option value="Senet" <?php if($hcari["t1"]=="Senet"){?>Selected<?php }?>><?php echo translate("Senet")?></option>
								<option value="Taksit" <?php if($hcari["t1"]=="Taksit"){?>Selected<?php }?>><?php echo $sdil[227]; //Taksit?></option>
							</select>
							<select name="ct6" class="sfa sna form-control w45" style="float:left;">
								<option value="TRY" <?php if($hcari["t6"]=="TL" or $hcari["t6"]=="TRY"){?>Selected<?php }?>>&#xf195;</option>
								<option value="EUR" <?php if($hcari["t6"]=="EUR"){?>Selected<?php }?>>&#xf153;</option>
								<option value="USD" <?php if($hcari["t6"]=="USD"){?>Selected<?php }?>>&#xf155;</option>
								<option value="GBP" <?php if($hcari["t6"]=="GBP"){?>Selected<?php }?>>&#xf154;</option>
							</select>
						</div>
					</td>
					<td align="center" class="w8 mw8">
						<input type="text" class=" form-control" name="cpb1" value="<?php echo wprice($hcari["pb1"]);?>" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
					</td>
					<td align="center" class="w8 mw8 <?php if($module["e8_type"]=="1"){echo "dn";}?>">
						<input type="text" class=" form-control" name="cpb2" value="<?php echo wprice($hcari["pb2"]);?>" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
					</td>
					<td align="center" class="w8 mw8">
						<input type="text" class=" form-control" name="cpb3" value="<?php echo wprice($hcari["pb3"]);?>" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
					</td>
					<td align="center" class="w8 mw8 <?php if($module["e8_type"]=="1"){echo "dn";}?>">
						<input type="text" class=" form-control" name="cpb4" value="<?php echo wprice($hcari["pb4"]);?>" onfocus="if(this.value == '0.00') { this.value = ''} "  onblur="if(this.value == '') { this.value='0.00'; }" style="text-align:right;">
					</td>
					<td align="left" class="w10 mw9">
						<div style="margin-top:2px;">
							<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-warning btn-update-row mw"><i class="fa fa-refresh "></i></a>
							<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-success mfrm" data-toggle="modal" data-target="#myModal" data-width="90%" data-ajax="icari" data-url="../../fonksiyon.php?islem=cdetail&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>"><i class="fa fa-pencil "></i></a>
						<?php if ($authority==0){?>
							<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-danger"><i class="fa fa-lock" style="padding:0px;"></i></a>
						<?php }else{?>
							<a style="cursor:pointer; line-height:0px; padding:5px;" class="btn btn-danger btn-delete-row" data-href="../clients/ajax_client_current.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $hcari["id"]?>&s5=<?php echo $hcari["s5"]?>&durum=scari"><i class="fa fa-times " style="padding:0px;"></i></a>
						<?php }?>
						</div>
					</td>
				</tr>
			</table>
		</form>		
	<?php }}?>
	<table class="table  fs13 mfs12" style="margin-top: 10px;">
	<?php if($module["currency"]<>""){?>
		<tr style="text-align:center; color:#f00; font-size:12px; font-weight:800;">
			<td class="w8 mdn" style="text-align:right; opacity: 0.5;" title="<?php echo ctranslate("Hesaplamaya Dahil Olmayan");?>"><a class="v3-btn v3-btn-info <?php if((($mcpb1-$mcpb2)-($mcpb3-$mcpb4))==0){echo "dn";}?>"><?php echo ctranslate("-Bakiye");?> : <?php echo $ikpb?> <?php echo wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))?></a></td>
			<td class="mdfx" colspan="3" style="text-align:right;">
				<a class="v3-btn v3-btn-success p5"><?php echo $sdil[159]; //BAKİYE?> : <?php echo wprice(($cpb1-$cpb2)-($cpb3-$cpb4))?> <?php echo $ikpb?></a>
			</td>
			<td class="mdfx w8" title="<?php echo ctranslate("Alacak");?>">
				<a class="v3-btn v3-btn-warning p5" style="color:#fff;float:right;"><?php echo wprice(($cpb1))?></a>
				<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[155]; //Alacak?></span>
			</td>
			<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Borç");?>">
				<a class="v3-btn v3-btn-danger p5" style="color:#fff;float:right;"><?php echo wprice(($cpb2))?></a>
				<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[156]; //Borç?></span>
			</td>
			<td class="w8 mdfx" title="<?php echo ctranslate("Alınan");?>">
				<a class="v3-btn v3-btn-<?php if($module["e8_type"]=="1"){echo "danger";}else{echo "success";}?> p5" style="color:#fff;float:right;"><?php echo wprice(($cpb3))?></a>
				<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[157]; //Alınan?></span>
			</td>
			<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Ödenen");?>">
				<a class="v3-btn v3-btn-info p5" style="color:#fff;float:right;"><?php echo wprice(($cpb4))?></a>
				<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[158]; //Ödenen?></span>
			</td>
			<td class="w10 mdn"></td>
		</tr>
	<?php }else{?>
		<?php //if(($try_pb1-$try_pb2)-($try_pb3-$try_pb4)>0){?>
			<tr style="text-align:center; color:#f00; font-size:12px; font-weight:800;">
				<td class="w8 mdn" style="text-align:right; opacity: 0.5;" title="<?php echo ctranslate("Hesaplamaya Dahil Olmayan");?>"><a class="v3-btn v3-btn-info <?php if((($mcpb1-$mcpb2)-($mcpb3-$mcpb4))==0){echo "dn";}?>"><?php echo ctranslate("-Bakiye");?> : <?php echo $ikpb?> <?php echo wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))?></a></td>
				<td class="mdfx" colspan="3" style="text-align:right;">
						<a class="v3-btn v3-btn-success p5"><i class="fa fa-try"></i> <?php echo wprice(($try_pb1-$try_pb2)-($try_pb3-$try_pb4))?></a>
				</td>
				<td class="mdfx w8" title="<?php echo ctranslate("Alacak");?>">
					<a class="v3-btn v3-btn-warning p5" style="color:#fff;float:right;"><?php echo wprice(($try_pb1))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[155]; //Alacak?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Borç");?>">
					<a class="v3-btn v3-btn-danger p5" style="color:#fff;float:right;"><?php echo wprice(($try_pb2))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[156]; //Borç?></span>
				</td>
				<td class="w8 mdfx" title="<?php echo ctranslate("Alınan");?>">
					<a class="v3-btn v3-btn-<?php if($module["e8_type"]=="1"){echo "danger";}else{echo "success";}?> p5" style="color:#fff;float:right;"><?php echo wprice(($try_pb3))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[157]; //Alınan?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Ödenen");?>">
					<a class="v3-btn v3-btn-info p5" style="color:#fff;float:right;"><?php echo wprice(($try_pb4))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[158]; //Ödenen?></span>
				</td>
				<td class="w10 mdn"></td>
			</tr>
		<?php //}?>
		<?php //if(($usd_pb1-$usd_pb2)-($usd_pb3-$usd_pb4)>0){?>
			<tr style="text-align:center; color:#f00; font-size:12px; font-weight:800;">
				<td class="w8 mdn" style="text-align:right; opacity: 0.5;" title="<?php echo ctranslate("Hesaplamaya Dahil Olmayan");?>"><!--<a class="v3-btn v3-btn-info <?php if((($mcpb1-$mcpb2)-($mcpb3-$mcpb4))==0){echo "dn";}?>"><?php echo ctranslate("-Bakiye");?> : <?php echo $ikpb?> <?php echo wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))?></a>--></td>
				<td colspan="3" style="text-align:right;">
					<a class="v3-btn v3-btn-success p5"><i class="fas fa-usd"></i> <?php echo wprice(($usd_pb1-$usd_pb2)-($usd_pb3-$usd_pb4))?></a>
				</td>
				<td class="mdfx w8" title="<?php echo ctranslate("Alacak");?>">
					<a class="v3-btn v3-btn-warning p5" style="color:#fff;float:right;"><?php echo wprice(($usd_pb1))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[155]; //Alacak?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Borç");?>">
					<a class="v3-btn v3-btn-danger p5" style="color:#fff;float:right;"><?php echo wprice(($usd_pb2))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[156]; //Borç?></span>
				</td>
				<td class="w8 mdfx" title="<?php echo ctranslate("Alınan");?>">
					<a class="v3-btn v3-btn-<?php if($module["e8_type"]=="1"){echo "danger";}else{echo "success";}?> p5" style="color:#fff;float:right;"><?php echo wprice(($usd_pb3))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[157]; //Alınan?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Ödenen");?>">
					<a class="v3-btn v3-btn-info p5" style="color:#fff;float:right;"><?php echo wprice(($usd_pb4))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[158]; //Ödenen?></span>
				</td>
				<td class="w10 mdn"></td>
			</tr>
		<?php //}?>
		<?php //if(($eur_pb1-$eur_pb2)-($eur_pb3-$eur_pb4)>0){?>
			<tr style="text-align:center; color:#f00; font-size:12px; font-weight:800;">
				<td class="w8 mdn" style="text-align:right; opacity: 0.5;" title="<?php echo ctranslate("Hesaplamaya Dahil Olmayan");?>"><!--<a class="v3-btn v3-btn-info <?php if((($mcpb1-$mcpb2)-($mcpb3-$mcpb4))==0){echo "dn";}?>"><?php echo ctranslate("-Bakiye");?> : <?php echo $ikpb?> <?php echo wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))?></a>--></td>
				<td colspan="3" style="text-align:right;">
					<a class="v3-btn v3-btn-success p5"><i class="fas fa-eur"></i> <?php echo wprice(($eur_pb1-$eur_pb2)-($eur_pb3-$eur_pb4))?></a>
				</td>
				<td class="mdfx w8" title="<?php echo ctranslate("Alacak");?>">
					<a class="v3-btn v3-btn-warning p5" style="color:#fff;float:right;"><?php echo wprice(($eur_pb1))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[155]; //Alacak?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Borç");?>">
					<a class="v3-btn v3-btn-danger p5" style="color:#fff;float:right;"><?php echo wprice(($eur_pb2))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[156]; //Borç?></span>
				</td>
				<td class="w8 mdfx" title="<?php echo ctranslate("Alınan");?>">
					<a class="v3-btn v3-btn-<?php if($module["e8_type"]=="1"){echo "danger";}else{echo "success";}?> p5" style="color:#fff;float:right;"><?php echo wprice(($eur_pb3))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[157]; //Alınan?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Ödenen");?>">
					<a class="v3-btn v3-btn-info p5" style="color:#fff;float:right;"><?php echo wprice(($eur_pb4))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[158]; //Ödenen?></span>
				</td>
				<td class="w10 mdn"></td>
			</tr>
		<?php //}?>
		<?php //if(($gbp_pb1-$gbp_pb2)-($gbp_pb3-$gbp_pb4)>0){?>
			<tr style="text-align:center; color:#f00; font-size:12px; font-weight:800;">
				<td class="w8 mdn" style="text-align:right; opacity: 0.5;" title="<?php echo ctranslate("Hesaplamaya Dahil Olmayan");?>"><!--<a class="v3-btn v3-btn-info <?php if((($mcpb1-$mcpb2)-($mcpb3-$mcpb4))==0){echo "dn";}?>"><?php echo ctranslate("-Bakiye");?> : <?php echo $ikpb?> <?php echo wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))?></a>--></td>
				<td colspan="3" style="text-align:right;">
						<a class="v3-btn v3-btn-success p5"><i class="fas fa-gbp"></i> <?php echo wprice(($gbp_pb1-$gbp_pb2)-($gbp_pb3-$gbp_pb4))?></a>
				</td>
				<td class="mdfx w8" title="<?php echo ctranslate("Alacak");?>">
					<a class="v3-btn v3-btn-warning p5" style="color:#fff;float:right;"><?php echo wprice(($gbp_pb1))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[155]; //Alacak?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Borç");?>">
					<a class="v3-btn v3-btn-danger p5" style="color:#fff;float:right;"><?php echo wprice(($gbp_pb2))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[156]; //Borç?></span>
				</td>
				<td class="w8 mdfx" title="<?php echo ctranslate("Alınan");?>">
					<a class="v3-btn v3-btn-<?php if($module["e8_type"]=="1"){echo "danger";}else{echo "success";}?> p5" style="color:#fff;float:right;"><?php echo wprice(($gbp_pb3))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[157]; //Alınan?></span>
				</td>
				<td class="w8 <?php if($module["e8_type"]=="1"){echo "dn";}else{echo "mdfx";}?>" title="<?php echo ctranslate("Ödenen");?>">
					<a class="v3-btn v3-btn-info p5" style="color:#fff;float:right;"><?php echo wprice(($gbp_pb4))?></a>
					<span class="lph ddn" style="margin-top:0px;"><?php echo $sdil[158]; //Ödenen?></span>
				</td>
				<td class="w10 mdn"></td>
			</tr>
		<?php //}?>
	<?php }?>
<tr>
<td colspan="10"><div class="fs8"><i class="fas fa-info"></i> Alt Toplamlar <b><?php if($_GET["ts1"]=="" && $_GET["ts2"]==""){echo "tüm";}else{echo "filtre uygulanmış";}?></b> verilerin toplamından hesaplanmıştır.</div></td>
</tr>
	</tbody>
</table>
<?php
// Verilerin alınıp atanması
$cs5 = !empty($_POST["cs5"]) ? $_POST["cs5"] : 0;
$ss2 = !empty($_POST["ss2"]) ? $_POST["ss2"] : 0;
if ($_GET["durum"] == "ycari") {
    // 'ycari' durumu için işlem yapılıyor
    $tutar = wprice($_POST["tutar"]);
    switch ($_POST["y"]) {
        case "Alacak":
            $kpb1 = $tutar;
            $kpb2 = $kpb3 = $kpb4 = 0;
            break;
        case "Alınan":
            $cpb1 = $cpb2 = $cpb4 = 0;
            $cpb3 = $tutar;
            break;
        case "Borç":
            $cpb1 = $cpb3 = $cpb4 = 0;
            $cpb2 = $tutar;
            break;
        case "Ödenen":
            $cpb1 = $cpb2 = $cpb3 = 0;
            $cpb4 = $tutar;
            break;
    }

	$lt1s = [];
	if ($_POST["cpb1"] > 0) { $lt1s[] = "Alacak: " . wprice($_POST["cpb1"]); }
	if ($_POST["cpb2"] > 0) { $lt1s[] = "Gelir: " . wprice($_POST["cpb2"]); }
	if ($_POST["cpb3"] > 0) { $lt1s[] = "Borç: " . wprice($_POST["cpb3"]); }
	if ($_POST["cpb4"] > 0) { $lt1s[] = "Gider: " . wprice($_POST["cpb4"]); }
	if (!empty($lt1s)) { $lt1 .= " > " . implode(" > ", $lt1s); }

    $rate = json_encode(['usd' => $usd, 'eur' => $eur, 'gpb' => $gbp]);
    // Veri ekleme sorgusu
    $sql = $conn->query("INSERT INTO t4(t1, t2, t3, t4, ne, t6, t11, pb1, pb2, pb3, pb4, ts1, n1, s1, s2, s5, s19) VALUES ('" . $_POST["ct1"] . "', 'cari', '" . mysqli_real_escape_string($conn, stripslashes($rate)) . "', '" . $_POST["ct4"] . "', 'cari', '" . $_POST["ct6"] . "', '" . $_POST["ct11"] . "', '" . sprice($_POST["cpb1"]) . "', '" . sprice($_POST["cpb2"]) . "', '" . sprice($_POST["cpb3"]) . "', '" . sprice($_POST["cpb4"]) . "', NOW(), '" . $_POST["cn1"] . "', '" . $_GET["id"] . "', '$ss2', '$cs5', '" . $_SESSION["user_id"] . "')");
    // Eğer 'Çek' işlemi yapılmışsa
    if ($_POST["ct1"] == "Çek") {
        $ct3 = $_POST["cpb1"] <> 0 ? "alinan" : ($_POST["cpb2"] <> 0 ? "verilen" : "");
        $ctutar = $_POST["cpb1"] <> 0 ? wprice($_POST["cpb1"]) : ($_POST["cpb2"] <> 0 ? wprice($_POST["cpb2"]) : 0);
        $sql = $conn->query("INSERT INTO t4(ne, t1, t2, t3, t4, pb1, n1, s1, s3, s4, ts1)  VALUES ('cek', '" . $_POST["ct1"] . "', '" . $_POST["ct2"] . "', '$ct3', '" . $_POST["ct4"] . "', '" . sprice($ctutar) . "', '" . $_POST["cn1"] . "', '" . $_GET["id"] . "', '" . $_POST["s3"] . "', '" . $_POST["s4"] . "', NOW())");
    }

} elseif ($_GET["durum"] == "kcari") {
    // 'kcari' durumu için işlem yapılıyor
	$lt1s = [];
	if ($_POST["cpb1"] > 0) { $lt1s[] = "Alacak: " . wprice($_POST["cpb1"]); }
	if ($_POST["cpb2"] > 0) { $lt1s[] = "Gelir: " . wprice($_POST["cpb2"]); }
	if ($_POST["cpb3"] > 0) { $lt1s[] = "Borç: " . wprice($_POST["cpb3"]); }
	if ($_POST["cpb4"] > 0) { $lt1s[] = "Gider: " . wprice($_POST["cpb4"]); }
	if (!empty($lt1s)) { $lt1 .= " > " . implode(" > ", $lt1s); }
    // Veri güncelleme sorgusu
    $sql = mysqli_query($conn, "UPDATE t4 SET t1='" . $_POST["ct1"] . "', t4='" . $_POST["ct4"] . "', t6='" . $_POST["ct6"] . "', t11='" . $_POST["ct11"] . "', n1='" . $_POST["cn1"] . "', pb1='" . sprice($_POST["cpb1"]) . "', pb2='" . sprice($_POST["cpb2"]) . "', pb3='" . sprice($_POST["cpb3"]) . "', pb4='" . sprice($_POST["cpb4"]) . "', s5='$cs5' WHERE id=" . $_GET["iid"]);

} elseif ($_GET["durum"] == "scari") {
    // 'scari' durumu için işlem yapılıyor
    $dsql = mysqli_query($conn, "SELECT * FROM t4 WHERE id='" . $_GET["iid"] . "'"); $drs = mysqli_fetch_assoc($dsql);
	$lt1s = [];
	if ($drs["pb1"] > 0) { $lt1s[] = "Alacak: " . wprice($drs["pb1"]); }
	if ($drs["pb2"] > 0) { $lt1s[] = "Gelir: " . wprice($drs["pb2"]); }
	if ($drs["pb3"] > 0) { $lt1s[] = "Borç: " . wprice($drs["pb3"]); }
	if ($drs["pb4"] > 0) { $lt1s[] = "Gider: " . wprice($drs["cpb4"]); }
	if (!empty($lt1s)) { $lt1 .= " > " . implode(" > ", $lt1s); }
    // Veri silme sorguları
    $sql = mysqli_query($conn, "DELETE FROM t4 WHERE id=" . $_GET["iid"]);
    $sql = mysqli_query($conn, "DELETE FROM genel WHERE ne='not' AND s2=" . $_GET["id"]);

} elseif ($_GET["durum"] == "cc_clear") {
    // 'cc_clear' durumu için işlem yapılıyor
    $ln2 = "Tüm cari hareketler temizlendi";
    // Veri silme sorgusu
    $sql = mysqli_query($conn, "DELETE FROM t4 WHERE ne='cari' AND s1=" . $_GET["id"]);
}
include("../public/log.php");
?>