<?php
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
$path="../../";
include("../../map.php");
include("../../scripts.php");
include("../../secure.php");
	//findDirectoryPath("deppo")
$sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$_GET["id"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu);
if($_GET["ts1"]<>"" and $_GET["ts2"]<>""){
	$qry = " and t9>='".$_GET["ts1"]."' and t9<='".$_GET["ts2"]."'";
}
?>
<!DOCTYPE html>
<html lang="en">
<style>
	<?php if($mobile<>""){?>
		.current_btn {margin-top:-15px; position:absolute; right:15px; z-index:999;}	
	<?php }?>
	tbody td, th { padding: 0px !important; }
	.table.table-no-more td {
		padding-left: 0px !important;
	}
</style>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title><?php echo $rs["t1"];?></title>
</head>
<body>
	<div class="qmodal">
		<div class="qmodal-content">
			<div class="alert alert-warning" id="result" style="display:none;"></div>
			<!-- Header with Action Buttons -->
			<div class="qmodal-header">
				<div class="header-title">
					<nav aria-label="breadcrumb">
						<ol class="breadcrumb">
							<li class="breadcrumb-item"><a href="?"><i class="fa fa-home"></i></a></li>
							<li class="breadcrumb-item"><a href="#"><?php echo $t21;?></a></li>
							<li class="breadcrumb-item active" aria-current="page"><?php echo $rs["t1"];?></li>
						</ol>
					</nav>
				</div>
				<div class="" style="min-width: 800px; overflow:auto;">
					<div style="float:right; margin-bottom:5px;">
						<div class="current_btn fr">
							<button type="button"  style="float:right; margin-left:10px;" class="btn btn-default" data-toggle="dropdown"> <i class="fa fa-share-alt"></i> </button>
							<div class="dropdown-menu" role="menu">
								<button type="button" onclick="window.open('modules/print/print.php?ne=<?php echo $_GET["ne"]?>&id=<?php echo $_GET["id"]?>&ts1=<?php echo $_GET["ts1"];?>&ts2=<?php echo $_GET["ts2"];?>&durum=stok')" class="btn btn-xs btn-default dropdown-item text-1"><i class="fa fa-print"></i> <?php echo ctranslate("Yazdır")?></button>
							</div>
							<button onclick="location.href='?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"];?>&durum=empty'" class="fr mml10 ml10 btn btn-warning filter_btn <?php if($MSA<>"1"){echo "dn";}?>" style="padding: 1px 6px;"><i class="fas fa-trash " aria-hidden="true"></i></button>
							<div class="fr mmr10 mr10 filter_form" style="margin-top:-2px; display:none;">
								<form id="form1"  action="?#&tab-rapor" method="get">
									<input type="hidden" name="ne" value="<?php echo $_GET["ne"]?>">
									<input type="hidden" name="islem" value="<?php echo $_GET["islem"]?>">
									<input type="hidden" name="id" value="<?php echo $_GET["id"]?>">
									<select id="when">
										<option ts1="">Zaman Aralığı</option>
										<option ts1="<?php echo date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'))?>"><?php echo ctranslate("Son 30 Gün")?></option>
										<option ts1="<?php echo date("Y-m-d")?>"><?php echo ctranslate("Bugün")?></option>
										<option ts1="<?php echo $haftabasi?>"><?php echo ctranslate("Bu Hafta")?></option>
										<option ts1="<?php echo $aybasi?>"><?php echo ctranslate("Bu Ay")?></option>
										<option ts1="<?php echo $yilbasi?>"><?php echo ctranslate("Bu Yıl")?></option>
										<option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -1 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -1 years'))?></option>
										<option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -2 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -2 years'))?></option>
										<option ts1="<?php echo date('Y-m-d', strtotime($yilbasi. ' -3 years'))?>"><?php echo date('Y', strtotime(date("Y"). ' -3 years'))?></option>
									</select>
									<input type="date" name="ts1" id="fts1" value="<?php if($_GET["ts1"]<>""){echo $_GET["ts1"];}else{echo date('Y-m-d', strtotime(date("Y-m-d"). ' -30 days'));}?>">
									<input type="date" name="ts2" id="fts2" value="<?php if($_GET["ts2"]<>""){echo $_GET["ts2"];}else{echo date("Y-m-d");}?>">
									<button type="submit" style="display:none;"></button>
									<button type="button" onclick="document.getElementById('form1').submit();" class="btn btn-xs btn-warning"><i class="fa fa-filter"></i></button>
								</form>
							</div>
							<button type="button" class="fr btn btn-warning filter_btn"  onclick="toggle('.filter_form');toggle('.filter_btn');"><i class="fa fa-filter " aria-hidden="true"></i></button>
						</div>
						<?php if($_SESSION["kim"]<>"yonetici"){?>
						<!--<a href="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=call" class="btn btn-xs btn-warning"><i class="fa fa-trash-o "></i></a>-->
						<?php }?>
						<script>
							jQuery('#when').on('change',function(){
								var w = jQuery("#when option:selected" ).attr("ts1");
								jQuery('#fts1').val(w);
							});
							jQuery("#ss1").change(function() {
								jQuery('#st9').val('<?php echo date("Y-m-d")?>');
							});
							jQuery('#fts1').on('change',function(){
								jQuery('#fts2').val('<?php echo date("Y-m-d")?>');
							});
						</script>
					</div>
				</div></div>
				<!-- 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");?>">
						<?php if($_GET["ts1"]=="" and $_GET["ts2"]==""){?>
							<!--<div class="alert alert-warning w50 fl">#<?php echo ctranslate("Son 30 Gün Listeniyor.")?></div>-->
						<?php }?>
						<form method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=ysh" name="aform" id="ncurrent" autocomplete="off">
							<input type="hidden" name="cs5" id="cs5" value="0">
							<table class="table table-no-more table-bordered table-striped mb-0 mmt20">
								<tbody>
									<tr class="addtr">
										<td>
											<select class="v3-form-control" style="" name="ss1" id="ss1">
												<option value="0"><?php echo ctranslate("Lütfen Seçiniz")?></option>
												<?php $sqlt=mysqli_query($conn, "select * from t5 where t1 LIKE '%".$_GET["q"]."%' $qry $luye order by t1 asc"); while($tip=mysqli_fetch_assoc($sqlt)){ $jsmi = json_decode($tip["n17"],true);?>
												<option value="<?php echo $tip["id"]?>"><?php if($jsmi["ifirma"]<>""){echo $jsmi["ifirma"];}else{echo $tip["t1"];}?></option>
											<?php }?>
										</select>
									</td>
									<td class="w15">
										<input type="text" name="st1" id="" class="form-control" style="" placeholder="<?php echo ctranslate("Belge No")?>">
									</td>
									<td class="w15">
										<input type="text" name="st2" id="st2" list="lst2" class="form-control" style="" placeholder="<?php echo ctranslate("Belge Tipi")?>">
										<datalist id="lst2">
											<option value="Fatura"></option>
											<option value="İrsaliye"></option>
											<option value="Diğer"></option>
										</datalist>
									</td>
									<td class="w15">
										<input type="date" name="st9" id="st9" class="form-control" style="" value="<?php echo date("Y-m-d")?>">
									</td>
									<td class="w10">
										<div style="position: absolute; color: silver; margin-top: 7px; margin-left: 5px;"><?php echo $rsu["t10"];?></div>
										<input type="text" name="ss5" class="form-control" style="text-align:right;" value="">
									</td>
									<td  class="w6">
										<button class="btn btn-warning" style="cursor:pointer; line-height:0px; padding:5px; font-size:16px;" <?php if($_SESSION["kim"]=="yonetici"){?>Disabled<?php }?>><i class="fa fa-plus"></i></span></button>
									</td>
								</tr>
							</tbody>
						</table>
					</form>
					<?php $sqlreport = mysqli_query($conn, "select * from t4 where ne='stok' and s2=".$_GET["id"]." $qry order by id desc");?>
					<?php if(mysqli_num_rows($sqlreport)>0){?>
						<table class="table table-no-more table-bordered table-striped mb-0">
							<tr>
								<td class="bg-warning p5"><i class="fas fa-exchange-alt"></i> <?php echo ctranslate("Stok Hareketleri")?></td>
							</tr>
						</table>
						<?php
						while($report=mysqli_fetch_assoc($sqlreport)){
							$sqlm=mysqli_query($conn, "select * from t5 where id=".$report["s1"].""); $rsm=mysqli_fetch_assoc($sqlm); $jsmi = json_decode($rsm["n17"],true);
							?>
							<form class="" method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $report["id"]?>&durum=ksh" name="aform" id="ecurrent" autocomplete="off">                       
								<table class="table table-no-more table-bordered table-striped mb-0">
									<tr>
										<td><input type="text" name="ss1" id="" class="form-control" style="" value="<?php if($jsmi["ifirma"]<>""){echo $jsmi["ifirma"];}else{echo $rsm["t1"];}?>"></td>
										<td class="w15"><input type="text" name="st1" id="" class="form-control" style="" value="<?php echo $report["t1"]?>" placeholder="<?php echo ctranslate("Belge No")?>"></td>
										<td class="w15"><input type="text" name="st2" id="" class="form-control" style="" value="<?php echo $report["t2"];?>" placeholder="<?php echo ctranslate("Belge Tipi")?>"></td>
										<td class="w15"><input type="date" name="st9" id="" class="form-control" style="" value="<?php echo $report["t9"];?>"></td>
										<td class="w10">
											<div style="position: absolute; color: silver; margin-top: 7px;margin-left: 5px;"><?php echo $rsu["t10"];?></div>
											<input type="text" name="ss5" id="" class="form-control tar" style="" value="<?php echo $report["s5"];?>" onkeypress="return SadeceRakam(event);" onblur="if(this.value == '') { this.value='0';};SadeceRakam(event,false);" onfocus="if(this.value == '0') { this.value = ''}">
										</td>
										<td align="left" class="w6">
											<div style="margin-top:2px;">
												<a style="cursor:pointer; line-height:0px; padding:5px; font-size:16px;" class="btn btn-danger" <?php if($_SESSION["kim"]=="yonetici"){?>Disabled<?php }?> href="report_product.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $report["id"]?>&durum=ssh"><i class="fas fa-trash " style="padding:0px; font-size:14px;"></i></a>
											</div>
										</td>
									</tr>
								</table>
							</form>
						<?php }?>
					<?php }?>
					<?php if($module["muhasebe_fatura"]==1){?>
						<table class="table table-no-more table-bordered table-striped mb-0" style="<?php if($qry<>""){echo "display:none;";}?>">
							<tr>
								<td class="bg-warning p5" style="padding:15px !important"><i class="fas fa-exchange-alt"></i> <?php echo ctranslate("Fatura Stok Hareketleri")?></td>
							</tr>
						</table>
						<?php
						$sqlreport = mysqli_query($conn, "select * from t4 where ne='furun' and s2=".$_GET["id"]." order by id desc"); while($report=mysqli_fetch_assoc($sqlreport)){
							$sqlf=mysqli_query($conn, "select * from t4 where id=".$report["s1"].""); $rsf=mysqli_fetch_assoc($sqlf);
							$sqlm=mysqli_query($conn, "select * from t5 where id=".$rsf["s1"].""); $rsm=mysqli_fetch_assoc($sqlm); $jsmi = json_decode($rsm["n17"],true);
							?>
							<table class="table table-no-more table-bordered table-striped mb-0" style="<?php if($qry<>""){echo "display:none;";}?>">
								<tr>
									<td class=""><input type="text" id="" class="form-control" style="" value="<?php if($jsmi["ifirma"]<>""){echo $jsmi["ifirma"];}else{echo $rsm["t1"];}?>"></td>
									<td  class="w15"><input type="text" id="" class="form-control" style="" value="<?php echo $rsf["t1"]?>"> <?php if($report["s3"]=="1"){?><i class="fa fa-question" title="Gecici Stok islemi"></i><?php }?></td>
									<td class="w15"><input type="text" id="" class="form-control" style="" value="<?php echo $rsf["ne"];?>"></td>
									<td class="w15"><input type="date" id="" class="form-control" style="" value="<?php echo $rsf["t9"];?>"></td>
									<td class="w10 tar">
										<div style="position: absolute; color: silver; margin-top: 5px;margin-left: 5px;"><?php echo $rs["t10"];?></div>
										<input type="text" id="" class="form-control tar" style="" value="<?php if($rsf["ne"]=="sfatura"){echo $report["s5"]*-1;}else{echo $report["s5"];}?>">
									</td>
									<td align="left" class="w6">
										<a class="btn btn-warning" target="_blank" href="<?php echo $weburl?>/crmplus/?ne=muhasebe&islem=sfatura&id=<?php echo $rsf["id"]?>" title="Fatura Yazdır" style="cursor:pointer; line-height:0px; padding:5px; font-size:16px;"><i class="fa fa-search"></i></span></a>
									</td>
								</tr>
							</table>
						<?php }?>
					<?php }?>
					<?php if($s1==1){?>
						<table class="table table-no-more table-bordered table-striped mb-0" style="<?php if($qry<>""){echo "display:none;";}?>">
							<tr>
								<td class="bg-warning p5" style="padding:15px !important"><i class="fas fa-exchange-alt"></i> <?php echo ctranslate("Eticaret Stok Hareketleri")?></td>
							</tr>
						</table>
						<?php
						$sqlb = mysqli_query($conn, "select distinct t4,s5,s2 from eticaret where ne='sepet' and s3=".$_GET["id"].""); while($siparissep=mysqli_fetch_assoc($sqlb)){
							$sqls = mysqli_query($conn, "select * from eticaret where ne='siparis' and id=".$siparissep["s5"]." and (s4=1 or s4=4 or s4=3)"); $siparis=mysqli_fetch_assoc($sqls);
							if(mysqli_num_rows($sqls)>0){
								$sqlm=mysqli_query($conn, "select * from t5 where id=".$siparis["s1"].""); $rsm=mysqli_fetch_assoc($sqlm); $jsmi = json_decode($rsm["n17"],true);
								$qty = $qty + ($siparissep["s2"]*-1);
								?>
								<table class="table table-no-more table-bordered table-striped mb-0" style="<?php if($qry<>""){echo "display:none;";}?>">
									<tr data-id="<?php echo $report["id"];?>" data-cke="0" data-href="modules/products/report_product.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $report["id"]?>" data-action="modules/products/report_product.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&iid=<?php echo $report["id"]?>&durum=ksh" data-url="modules/products/report_product.php" data-did="#tab-rapor">
										<td><input type="text" id="" class="form-control" style="" value="<?php if($jsmi["ifirma"]<>""){echo $jsmi["ifirma"];}else{echo $rsm["t1"];}?>"></td>
										<td class="w15"><input type="text" id="" class="form-control" style="" value="<?php echo $siparis["t4"]?>"></td>
										<td class="w15"><input type="text" id="" class="form-control" style="" value="Sipariş"></td>
										<td class="w15"><input type="date" id="" class="form-control" style="" value="<?php echo dtarih($siparis["ts1"],"yyyy-aa-gg");?>"></td>
										<td class="w10 tar">
											<div style="position: absolute; color: silver; margin-top: 5px;margin-left: 5px;"><?php echo $rs["t10"];?></div>
											<input type="text" id="" class="form-control tar" style="" value="<?php echo $siparissep["s2"]*-1;?>">
										</td>
										<td align="left" class="w6">
											<a class="btn btn-warning mfrm" data-toggle="modal" data-target="#myModal" data-url="../../modules/print/print_order.php?mode=modal&id=<?php echo $siparis["id"]?>" data-title="Sipariş Yazdır" title="Sipariş Yazdır" style="cursor:pointer; line-height:0px; padding:5px; font-size:16px;"><i class="fa fa-search"></i></span></a>
										</td>
									</tr>
								</table>
							<?php }?>
						<?php }?>
						<table class="table table-no-more table-bordered table-striped mb-0" style="">
							<tr>
								<td class=""></td>
								<td class="w15"></td>
								<td class="w15"></td>
								<td class="w15"></td>
								<td class="w10 tar"><input type="text" id="" class="form-control tar" style="" value="<?php echo $qty?>"></td>
								<td class="w6"></td>
							</tr>
						</table>
					</div>
				<?php }?>
			</div>
		</div>
	</body>
	<?php echo $footer?>
	</html>
	<?php
	if ($_GET["durum"]=="ysh"){
		$ln2="".$_POST["cn1"]." [".$_POST["ct1"]." ".$_POST["ct6"]."]<br>".$_POST["ct4"]."<br>Alacak : ".$_POST["cpb1"]."<br>Alınan : ".$_POST["cpb2"]."<br>Borç : ".$_POST["cpb3"]."<br>Ödenen : ".$_POST["cpb4"]."";
		$sql = $conn->query("insert into t4(t1,t2,t9,ne,ts1,s1,s2,s5,s19) values ('".$_POST["st1"]."', '".$_POST["st2"]."', '".$_POST["st9"]."', 'stok', now(), '".$_POST["ss1"]."', '".$_GET["id"]."', '".$_POST["ss5"]."', '".$_SESSION["user_id"]."')");
		$qty=$rsu["s5"]+$_POST["ss5"];
		$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$qty."' where id=".$_GET["id"]."");
		echo "<script type=\"text/javascript\"> jQuery(document).ready(function(){location.href='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."'}); </script>";
	}elseif ($_GET["durum"]=="ssh"){
		$dsql=mysqli_query($conn, "select * from t4 where id='".$_GET["iid"]."'"); $drs=mysqli_fetch_assoc($dsql);
	//$lt1="#".$_GET["id"]." > #".$_GET["iid"]."";
	//$ln2="".$drs["n1"]." [".$drs["t1"]." ".$drs["t6"]."]<br>".$drs["t4"]."<br>Alacak : ".$drs["pb1"]."<br>Alınan : ".$drs["pb2"]."<br>Borç : ".$drs["pb3"]."<br>Ödenen : ".$drs["pb4"]."";
		if($drs["s5"]>0){ $qty=$rsu["s5"] - $drs["s5"]; }else{$qty=$rsu["s5"] + abs($drs["s5"]);}
		$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$qty."' Where id=".$_GET["id"]."");
		$sql = mysqli_query($conn, "delete from t4 where id=".$_GET["iid"]);
		echo "<script type=\"text/javascript\"> jQuery(document).ready(function(){location.href='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."'}); </script>";
	}elseif ($_GET["durum"]=="ksh"){
		$ln2="".$_POST["cn1"]." [".$_POST["ct1"]." ".$_POST["ct6"]."]<br>".$_POST["ct4"]."<br>Alacak : ".$_POST["cpb1"]."<br>Alınan : ".$_POST["cpb2"]."<br>Borç : ".$_POST["cpb3"]."<br>Ödenen : ".$_POST["cpb4"]."";
		$Rs = mysqli_query($conn, "update t4 set t1='".$_POST["ct1"]."', t4='".$_POST["ct4"]."', t6='".$_POST["ct6"]."', t11='".$_POST["ct11"]."', n1='".$_POST["cn1"]."', pb1='".str_replace(',','',number_format($_POST["cpb1"],2))."', pb2='".str_replace(',','',number_format($_POST["cpb2"],2))."', pb3='".str_replace(',','',number_format($_POST["cpb3"],2))."', pb4='".str_replace(',','',number_format($_POST["cpb4"],2))."', s5='".$cs5."' Where id=".$_GET["iid"]."");
	}
	include("../public/log.php");
?>