<?php
	header('Content-Type: text/html; charset=utf-8');
	error_reporting(0);
	$path="../../";
	include("../../map.php");
	include("../../scripts.php");
	include("../../secure.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo $sdil[163]; //Çekler?></title>
</head>
<body>
    <div class="qmodal">
        <div class="qmodal-content">
            <!-- Left Tab Menu -->
            <div class="v8-columns">
                <!-- Content Area -->
                <div class="" ts1="<?php echo dtarih($rs["ts1"],"gg ka yy time");?>" ts2="<?php echo dtarih($rs["ts2"],"gg ka yy time");?>" ts3="<?php echo dtarih($rs["ts3"],"gg ka yy time");?>">
						<table class="table table-no-more table-bordered table-striped mb-0">
							<thead>
								<tr>
									<th class="w6">ID</th>
									<th class=""><?php echo $sdil[213]; //İşlem Açıklama?></th>
									<th class="w8"><?php echo $sdil[164]; //Senet?> No</th>
									<th class="w6"><?php echo $sdil[227]; //Taksit Sayısı?></th>
									<th class="w6"><?php echo $sdil[144]; //Tutar?></th>
									<th class="w6"><?php echo translate("Vade Tarihi");?></th>
									<th class="w12"><?php echo $t25s[0];?></th>
									<th class="w8"><?php echo $sdil[213]; //Durum?></th>
								</tr>
							</thead>
							
							<tbody>
								<form id="simple_form" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=ekle" autocomplete="off">
									<input type="hidden" name="s2" id="s2" value="0">
									<tr class="addtr" style="cursor:pointer;">
										<th scope="row" class="table-check-cell">.....</th>
										<td>
										<input type="text" name="n1" id="cn1" list="cln1" class="form-control" style="" placeholder="<?php echo $sdil[40]; //İşlem Açıklama?>" autofocus>
										<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 translate("Nolu Fatura");?>" id="<?php echo $tip["id"]?>"><?php echo $tip["pb2"]?> <?php echo $kpb?></option>
											<?php }?>
											<?php $sqlt=mysqli_query($conn, "select * from t4 where ne='service'"); while($tip=mysqli_fetch_assoc($sqlt)){?>
												<option value="<?php echo $tip["t1"]?> <?php echo $t36;?>" id="<?php echo $tip["id"]?>"><?php echo $tip["pb2"]?> <?php echo $kpb?></option>
											<?php }?>
										</datalist>
										<script>
										jQuery( "#cn1" ).change(function() {
											var inputVal = jQuery(this).val();
											var id = jQuery("#cln1 option[value='"+inputVal+"']").attr("id");
											jQuery( "#s2" ).val(id);
										});
										</script>
										</td>
										<td><input type="text" value="" name="t11" placeholder="<?php echo $sdil[164]; //Senetler?> No" class="form-control" style=""></td>
										<td><input type="text" value="" name="t2" placeholder="<?php echo $sdil[227]; //Taksit Sayısı?>" class="form-control" style=""></td>
										<td><input type="text" value="" name="pb1" placeholder="<?php echo $sdil[144]; //Tutar?>" class="form-control" style=""></td>
										<td><input type="date" value="<?php echo date("Y-m-d",strtotime("+1 month"));?>" name="t4" placeholder="<?php echo $sdil[164]; //Senetler?> <?php echo $sdil[115]; //Tarihi?>" id="simple-calendar" class="form-control datepicker"></td>
										<td>
											<select name="s1" class="ajax-select"><option><?php echo $sdil[221]; //Lütfen Seçiniz?></option></select>
										</td>
										<td class="table-actions"><button type="submit" class="btn btn-warning mbtn"><i class="fa fa-plus"></i><span class="ddn"> <?php echo $sdil[201]; //ekle?></span></button></td>
									</tr>
								</form>
								<?php
									$sql=mysqli_query($conn, "select * from t4 where ne='senet' and (t1 LIKE '%".$_GET["key"]."%' or n1 LIKE '%".$_GET["key"]."%') $lacc order by id desc"); while($rs=mysqli_fetch_assoc($sql)){
									//if(($_GET["ts1"]=="" and $_GET["ts2"]=="" and ($rs["t4"] >= date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days')) or $rs["t4"]=="")) or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($rs["t4"]>=$_GET["ts1"] and $rs["t4"]<=$_GET["ts2"])){
								?>
									<form id="simple_form" method="post" action="?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&durum=duzenle&id=<?php echo $rs["id"]?>">						
										<tr style="cursor:pointer;">
											<th scope="row" class="table-check-cell"><?php echo i2a($rs["id"],7);?></th>
											<td><input type="text" name="n1" id="cn1" class="form-control" value="<?php echo $rs["n1"]?>" style="" placeholder="<?php echo $sdil[40]; //İşlem Açıklama?>"></td>
											<td><input type="text" value="<?php echo $rs["t11"]?>" name="t11" placeholder="Senet No" class="form-control"></td>
											<td><input type="text" value="<?php echo $rs["t2"]?>" name="t2" placeholder="Banka-Şube" class="form-control"></td>
											<td><input type="text" value="<?php echo wprice($rs["pb1"])?>" name="pb1" placeholder="Tutar" class="form-control"></td>
											<td><input type="date" value="<?php echo $rs["t4"]?>" name="t4" placeholder="Vade Tarihi" id="simple-calendar" class="form-control"></td>
											<td>
												<select name="s1" class="ajax-select"><option value="<?php echo $rs["s1"];?>"><?php echo sabit($rs["s1"],"uye","t1");?></option></select>
											</td>
											<td class="table-actions">
												<button type="submit" class="btn btn-warning mbtn"><i class="fa fa-refresh"></i><span class="ddn"> <?php echo $sdil[203]; //Güncelle?></span></button>
											<?php if($_SESSION["kim"]=="Admin" or ($_SESSION["kim"]=="yonetici" and $_SESSION["y6"]==3)){?>
												<button type="button" class="btn btn-danger mbtn" onclick="location.href='?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $rs["id"]; ?>&durum=sil'"><i class="fa fa-times"></i><span class="ddn"> <?php echo $sdil[204]; //Kaldır?></span></button>
											<?php }else{?>
												<button type="button" class="btn btn-default mbtn" disabled><i class="fa fa-cancel"></i><span class="ddn"> <?php echo $sdil[204]; //Kaldır?></span></button>
											<?php }?>
												<button type="button" class="btn btn-<?php if($rs["s13"]=="1"){?>warning<?php }else{?>success<?php }?> mbtn" onclick="if(!confirm('Bildirimi iptal etmek istediğinize eminmisiniz?')) return false; location.href='?islem=<?php echo $_GET["islem"];?>&ne=<?php echo $_GET["ne"];?>&id=<?php echo $rs["id"];?>&s13=<?php if($rs["s13"]=="1"){?>0<?php }else{?>1<?php }?>'"><i class="fa-solid fa-bell<?php if($rs["s13"]=="1"){?>-slash<?php }?>"></i></button>
											</td>
										</tr>
									</form>
								<?php }?>
							</tbody>
							
						</table>
                 </div>
            </div>
</body>
<?php echo $footer?>
</html>
<?php
if($_POST["s1"]<>""){$s1=$_POST["s1"];}else{$s1=0;}
if($_GET["durum"]=="ekle"){
	$s1 = (int)$_POST["s1"];
	$s2 = ($_POST["s2"] != "") ? (int)$_POST["s2"] : 0;
	$taksitSayisi = (int)$_POST["t2"];
	$baslangicTarih = $_POST["t4"];
	$senetNo = (int)$_POST["t11"];
	$pb1 = sprice($_POST["pb1"]);
	$n1 = $_POST["n1"];
	for ($t = 0; $t < $taksitSayisi; $t++) {
		$taksitNo = $t + 1;
		$st1 = ($t == 0 || $taksitSayisi == 1) ? $senetNo : $senetNo + $t;
		$st4 = date("Y-m-d", strtotime($baslangicTarih . " +$t month"));
		$conn->query("INSERT INTO t4 (t11, t2, t4, ne, s1, s2, s13, s19, pb1, n1, ts1) VALUES ('$st1', '$taksitNo', '$st4', 'senet', '$s1', '$s2', '1', '{$_SESSION["user_id"]}', '$pb1', '$n1', NOW())");
		$insert_id = $conn->insert_id;
		$conn->query("INSERT INTO t4 (ne, t1, t2, t4, t12, t6, t11, pb1, pb2, pb3, pb4, s1, s5, n1, ts1) VALUES ('cari', 'Senet', 'cari', '" . date("Y-m-d") . "', '$taksitNo', '{$module["currency"]}', 'Senet', '$pb1', '0', '0', '0', '$s1', '$insert_id', '$n1', NOW())");
	}
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
}elseif($_GET["durum"]=="duzenle"){
	$Rs = mysqli_query($conn, "update t4 set t11='".$_POST["t11"]."', t2='".$_POST["t2"]."', t4='".$_POST["t4"]."', pb1='".sprice($_POST["pb1"])."', t9='".$_POST["t9"]."', n1='".$_POST["n1"]."' where id=".$_GET["id"]."");
	$Rs = mysqli_query($conn, "update t4 set pb1='".sprice($_POST["pb1"])."', t12='".$_POST["t4"]."' where s5=".$_GET["id"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
}elseif($_GET["s13"]<>""){
	$Rs = mysqli_query($conn, "update t4 set s13='".$_GET["s13"]."', ts2=now() where id=".$_GET["id"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
}elseif($_GET["durum"]=="sil"){
	$sql = mysqli_query($conn, "delete from t4 where id=".$_GET["id"]."");
	$sql = mysqli_query($conn, "delete from t4 where s5=".$_GET["id"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&durum=ok",self,500,1);
}
?>