<?php
//-------------------/Fatura Düzenle/-------
if($_GET["id"]<>""){
	$sql=mysqli_query($conn, "select * from t4 where id=".$_GET["id"].""); $rs=mysqli_fetch_assoc($sql);
	$ftarih="".$rs["s2"].".".$rs["s3"].".".$rs["s4"]."";
	$fno=$rs["t1"];
	$t4=$rs["t4"];
	$sqlm=mysqli_query($conn, "select * from t5 where id=".$rs["s1"].""); $rsm=mysqli_fetch_assoc($sqlm);
	$fcari=$rsm["id"];
	$fcisk=((100+$rsm["s5"])/100);
}else{
	//$fno=random_int(0, 10);
}
//-------------------/Fatura Düzenle/-------
?>
<div class="inner-wrapper">
	<!-- start: sidebar -->
	<aside id="sidebar-left" class="sidebar-left">
		
		<div class="sidebar-header">
			<div class="sidebar-title">
				Menu
			</div>
			<div class="sidebar-toggle hidden-xs" data-toggle-class="sidebar-left-collapsed" data-target="html" data-fire-event="sidebar-left-toggle">
				<i class="fa fa-bars" aria-label="Toggle sidebar"></i>
			</div>
		</div>
		
		<?php include('menu.php');?>
	</aside>
	<!-- end: sidebar -->
	<section role="main" class="content-body card-margin">
		<header class="page-header">
			<h2>Fatura İşlem</h2>
			<div class="right-wrapper text-right">
				<ol class="breadcrumbs">
					<li>
						<a href=".">
							<i class="fa fa-home"></i>
						</a>
					</li>
					<li><span><?php echo $sdil[23]; //Muhasebe?></span></li>
					<li><span><?php echo $sdil[24]; //Faturalar?></span></li>
					<li><span><?php if($_GET["id"]=="afatura"){?>Alış Faturası<?php }elseif($_GET["islem"]=="sfatura"){?>Satış Faturası<?php }elseif($_GET["islem"]=="ifatura"){?>İade Faturası<?php }?></span></li>
				</ol>
				<a class="sidebar-right-toggle" data-open="sidebar-right"><i class="fa fa-chevron-left"></i></a>
			</div>
		</header>
		<!-- start: page -->
		<div class="row">
			<div class="col p0">
				<section class="card form">
					<header class="card-header" style="text-align: start">
						<div class="card-actions" id="v-<?php echo $_GET['islem'];?>">
							<?php if($_GET["id"]<>"" and $_GET["islem"]=="sfatura"){?><a class="mb-1 mt-1 mr-1 btn btn-default" href="print_accounting.php?id=<?php echo $_GET["id"]?>&islem=<?php echo $_GET["islem"]?>" target="_blank" onClick="return confirm('#Yazdırmak İstediğinizden Eminmisiniz!')"><i class="fa fa-print"></i> <?php if($rs["s5"]==1){?>Yazdırıldı<?php }else{?>Yazdır<?php }?></a><?php }?>
							<!--
								<a href="#" class="card-action card-action-toggle" data-card-toggle=""></a>
								<a href="#" class="card-action card-action-dismiss" data-card-dismiss=""></a>
							-->
						</div>
						<h2 class="card-title"><?php if($_GET["id"]=="afatura"){?>Alış Faturası<?php }elseif($_GET["islem"]=="sfatura"){?>Satış Faturası<?php }elseif($_GET["islem"]=="ifatura"){?>İade Faturası<?php }?></h2>
						<p class="card-subtitle">...</p>
					</header>
					<form class="form" id="asave" name="rall" method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"];?><?php if($_GET["id"]<>""){?>&durum=guncelle&id=<?php echo $_GET["id"]?><?php }else{?>&durum=kaydet<?php }?>">
						<?php include("modules/public/control_bar.php");?>
						<?php if($_GET["durum"]=="ok"){?>
							<?php echo saveok();?>
							<div class="alert alert-success">
								<?php echo $sdil[212]; //islem Basariyla Gerçeklestirilmistir !?>
							</div>
						<?php }elseif($_GET["durum"]=="err"){?>
							<div class="alert alert-danger">
								Hata / <?php if($_GET["durum"]=="hata"){?>Ürün Bulunamadı.<?php }elseif($_GET["durum"]=="hata2"){?>Yeterli Stok Yok<?php }elseif($_GET["durum"]=="hata3"){?>Cari Seçilmemiş<?php }elseif($_GET["durum"]=="hata4"){?>Fatura No Girilmemiş<?php }elseif($_GET["durum"]=="hata5"){?>Ürün Faturada Mevcut<?php } //end if?>
							</div>
						<?php }?>
						<?php
						if($_GET["id"]<>""){
							$sqlfu=mysqli_query($conn, "select * from t4 where ne='furun' and s1=".$_GET["id"].""); while($rsfu=mysqli_fetch_assoc($sqlfu)){
								$sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rsfu["s2"].""); $rsu=mysqli_fetch_assoc($sqlu);
								if(mysqli_num_rows($sqlu)>0){
									$id=$rsu["id"];
									include("../deppo/tools/script/fiyat.php");
									include("accounting_calc.php");
							} //end if
						} //rsfu.movenext : loop
						?>
						<input type="hidden" name="ttoplam" value="<?php echo number_format($ttoplam,2)?>">
						<input type="hidden" name="kdv" value="<?php echo number_format($ttutar-$ttoplam,2)?>">
						<input type="hidden" name="ttutar" value="<?php echo number_format($ttutar,2)?>">
					<?php } //end if?>
					<div class="v8-columns">
						<div class="v8-col200pxL-left">
							<ul class="v8-side-tabs v8-js-tabs v8-same-height">
								<li><a href="#tab-detay"><i class="fa fa-bookmark"></i><span> <?php echo $sdil[207]; //Detay?></span></a></li>
							</ul>
						</div>
						<div class="v8-col200pxL-right">
							<div id="tab-detay" class="v8-tabs-content" style="display: flow-root;">
								<div class="v3-row">
									<div class="v3-col-md-<?php if($_GET["id"]<>""){?>6<?php }else{?>12<?php }?>" style="padding:0px; ">
										<fieldset class="v3-col-md-6">
											<legend><b>Cari </b> <span style="font-size:8px; color:#ccc;">(s1)</span></legend>
											<select name="cari" data-placeholder="Seçiniz" style="" class="form-control chosen-select" tabindex="8">
												<option value="0">Lütfen Seçiniz</option>
												<?php $sql=mysqli_query($conn, "select * from t5 order by t1 asc"); while($rs5=mysqli_fetch_assoc($sql)){?>
													<option value="<?php echo $rs5["id"];?>" title="<?php echo $rs5["m1"];?>" style="color:#6699FF" <?php if($rs5["id"]==$fcari){?>Selected<?php }?>><?php echo $rs5["t1"];?></option>
												<?php }?>
											</select>
										</fieldset>
										<fieldset class="v3-col-md-6">
											<legend>Fatura Tarih <span style="font-size:8px; color:#ccc;">(ts1)</span></legend>
											<input type="text" name="ftarih" id="simple-calendar" class="form-control datepicker" value="<?php if($ftarih==""){?><?php echo date(d);?>.<?php echo date(m);?>.<?php echo date(Y);?><?php }else{?><?php echo $ftarih?><?php }?>" placeholder="Fatura Tarihi">
										</fieldset>
										<fieldset class="v3-col-md-6">
											<legend>Tahsilat Evrak No <span style="font-size:8px; color:#ccc;">(t4)</span></legend>
											<input type="text" name="t4" class="form-control" style="width:100%;" value="<?php echo $t4?>" placeholder="KK, Çek, Dekont No;">
										</fieldset>
										<fieldset class="v3-col-md-6">
											<legend>Fatura No <span style="font-size:8px; color:#ccc;">(t1)</span></legend>
											<input type="text" name="fno" class="form-control"  value="<?php echo $fno?>" placeholder="Fatura No">
										</fieldset>
									</div>
									<?php if($_GET["id"]<>""){?>
										<fieldset class="v3-col-md-6">
											<legend>Fatura Tahsilat</legend>
											<table style="width:100%; margin:0px; padding:0px;">
												<tr>
													<td colspan="4" class="message warning" style="padding:5px;">
														"İskonto"'yu işledikten Sonra "Genel Toplam" Alanına Tahsilat Miktarını Yazınız !
													</td>
												</tr>
												<tr style="height:32px; background-color:#d7d7d7;">
													<td style="width:10%;">&nbsp;</td>
													<td>
														<select class="form-control" style="margin-left:10px; width:85%;" name="otipi">
															<option value="Nakit" <?php if($rs["t2"]=="Nakit"){?>Selected<?php } //end if?>>Nakit</option>
															<option value="Pos" <?php if($rs["t2"]=="Pos"){?>Selected<?php } //end if?>>Pos</option>
															<option value="Banka" <?php if($rs["t2"]=="Banka"){?>Selected<?php } //end if?>>Banka</option>
															<option value="Çek" <?php if($rs["t2"]=="Çek"){?>Selected<?php } //end if?>>Çek</option>
														</select>
													</td>
													<td>Ödeme Tipi</td>
													<td></td>
												</tr>
												<tr style="height:32px; background-color:#ebebeb;">
													<td>&nbsp;</td>
													<td><input type="text" class="form-control" style="margin-left:10px; width:85%;" value="<?php echo number_format(($ttoplam),2)?>" disabled size="20"></td>
													<td>Ara Toplam</td>
													<td></td>
												</tr>
												<?php if($kdvbir<>""){?>
													<tr style="height:32px; background-color:#d7d7d7;">
														<td>&nbsp;</td>
														<td><input type="text" class="form-control" style="margin-left:10px; width:85%;" value="<?php echo number_format(($kdvbir),2)?>" disabled size="20"></td>
														<td>Kdv 1%</td>
														<td></td>
													</tr>
												<?php } //end if?>
												<?php if($kdvsekiz<>""){?>
													<tr style="height:32px; background-color:#ebebeb;">
														<td>&nbsp;</td>
														<td><input type="text" class="form-control" style="margin-left:10px; width:85%;" value="<?php echo number_format(($kdvsekiz),2)?>" disabled size="20"></td>
														<td>Kdv 8%</td>
														<td></td>
													</tr>
												<?php } //end if?>
												<?php if($kdvonsekiz<>""){?>
													<tr style="height:32px; background-color:#d7d7d7;">
														<td>&nbsp;</td>
														<td><input type="text" class="form-control" style="margin-left:10px; width:85%;" value="<?php echo number_format(($kdvonsekiz),2)?>" disabled size="20"></td>
														<td>Kdv 18%</td>
														<td></td>
													</tr>
												<?php } //end if?>
												<?php if($ttutar=="" or $ttutar=="0"){?>
													<tr style="height:32px; background-color:#ebebeb;">
														<td>&nbsp;</td>
														<td><input type="text" class="form-control" style="margin-left:10px; width:85%;" value="0" disabled size="20"></td>
														<td>Kdv</td>
														<td></td>
													</tr>
												<?php } //end if?>
												<tr style="height:32px; background-color:#ebebeb;">
													<td>&nbsp;</td>
													<td><input name="indirim" id="indirim" type="text" class="form-control" style="margin-left:10px; width:85%;" value="<?php echo $rs["pb4"]?>" size="20"  onfocus="if(this.value == '0') { this.value = ''} "  onblur="if(this.value == '') { this.value='0'; }" ></td>
													<td>İskonto (TL)</td>
													<td><?php echo $isk?></td>
												</tr>
												<tr style="height:32px;" class="message danger">
													<td>&nbsp;</td>
													<td><input name="tahsilat" id="tahsilat" type="text" class="form-control" style="margin-left:10px; width:85%;" onclick="javascript: document.getElementById('tahsilat').value = '<?php if($rs["pb4"]=="0"){?><?php echo number_format(($ttutar),2)?><?php }else{?><?php echo number_format(($ttutar-$rs["pb4"]),2)?><?php } //end if?>'" placeholder="<?php if($rs["pb4"]=="0"){?><?php echo number_format(($ttutar),2)?><?php }else{?><?php echo number_format(($ttutar-$rs["pb4"]),2)?><?php } //end if?>" size="20"></td>
													<td>G.Toplam</td>
													<td><strong>Tahsilat: <?php echo number_format(($ctutar),2)?> TL</strong></td>
												</tr>
											</table>
										</fieldset>
									<?php }?>
								</form>
								<?php if($_GET["id"]<>""){?>
									<form name="fisle" method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=uekle">
										<table class="table table-no-more table-bordered table-striped mb-0">
											<tr>
												<th>Barkod/Ürün No</th>
												<th class="w10" style="text-align:right;">Adet</th>
												<th class="w10" style="text-align:right;">Kdv</th>
												<th class="w10" style="text-align:right;">Birim Fiyat</th>
												<th class="w8">İşlemler</th>
											</tr>
											<tr class="addtr">
												<td>
													<input type="text" name="t1" class="form-control" style="" value="" placeholder="Barkod/Ürün No" autofocus>
												</td>
												<td>
													<input type="text" class="form-control" style="color:#ccc; border:0px;text-align:right;" value="1" name="s5">
												</td>
												<td>
													<input type="text" class="form-control" style=" border:0px; color:#ccc;text-align:right;" value="0" disabled>
												</td>
												<td>
													<input type="text" class="form-control" style="border:0px; color:#ccc;text-align:right;" value="0.00 TL" disabled>
												</td>
												<td>
													<div class="input-group-btn">
														<button class="btn btn-primary" type="submit"><i class="fa fa-plus"></i></button>
														<button class="btn btn-primary" type="button" style="margin-left:2px;"><i class="fa fa-search"></i></button>
													</div>
												</td>
											</tr>
										</table>
									</form>
									<?php
									$sqlf=mysqli_query($conn, "select * from t4 where ne='furun' and s1=".$_GET["id"]." order by id desc"); while($rsfu=mysqli_fetch_assoc($sqlf)){
										$sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rsfu["s2"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu);
										$id=$rsu["id"];
										include("../deppo/tools/script/fiyat_v3.php");
										?>
										<form id="simple_form" method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=uguncelle&uid=<?php echo $rsfu["id"]?>">
											<table class="table table-no-more table-bordered table-striped mb-0">
												<input type="hidden" name="urunid" value="<?php echo $rsu["id"]?>">
												<input type="hidden" name="fiyat" value="<?php echo number_format($rsfu["pb1"],2)?>">
												<input type="hidden" name="s4" value="<?php echo $rsu["s4"]?>">						
												<tr>
													<td>
														<input type="text" name="t1" class="form-control" style="width:60%; float: left;" value="<?php echo $rsu["t1"]?>" placeholder="">
														<select name="rb" data-placeholder="Varyasyon Seçiniz" style="width:30%; float: left;" class="form-control chosen-select" tabindex="8">
															<option value="">Varyasyon</option>
															<?php $sql=mysqli_query($conn, "select * from varyasyon where s1=".$rsfu["s2"]." order by t1 asc"); while($rb=mysqli_fetch_assoc($sql)){?>
																<option value="<?php echo $rb["id"];?>" title="<?php echo $rb["id"];?>" style="color:#6699FF" <?php if ($rb["id"]==$rsfu["s6"]){?>Selected<?php }?>><?php echo $rb["t1"];?></option>
															<?php }?>
														</select>
													</td>
													<td class="w10">
														<input type="text" name="fuadet" class="form-control" style="text-align:right;" value="<?php echo $rsfu["s5"]?>" onfocus="if(this.value == '0') { this.value = ''} "  onblur="if(this.value == '') { this.value='0'; }">
													</td>
													<td class="w10">
														<input type="text" class="form-control" style="border:0px;text-align:right;" value="<?php echo $rsfu["s4"]?>" disabled>
													</td>
													<td class="w10">
														<input type="text" name="fufiyat" class="form-control" style="text-align:right;" value="<?php echo number_format($rsfu["pb1"],2)?>">
													</td>
													<td class="w8">
														<div class="input-group-btn">
															<button class="btn btn-primary" type="submit"><i class="fa fa-refresh"></i></button>
															<button tabindex="-1" data-toggle="dropdown" class="btn btn-primary dropdown-toggle"  style="margin-left: 2px;" type="button" aria-expanded="false">
																<span class="caret"></span>
															</button>
															<div class="dropdown-menu dropdown-menu-right btn-edit-row" x-placement="top-end" style="position: absolute; transform: translate3d(105px, -2px, 0px); top: 0px; left: 0px; will-change: transform;">
																<a style="text-align: left; width: 100%;" class="dropdown-item" href="muhasebe-serino.asp?ne=kayit&islem=<?php echo $_GET["islem"]?>&fid=<?php echo $_GET["id"]?>&id=<?php echo $id;?>" title="<?php echo $sdil[203]; //Düzenle?>"><i class="fa fa-pencil"></i> S.No</a>
																<a style="cursor:pointer; text-align: left; width: 100%;" title="<?php echo $sdil[204]; //Kaldir?>" class="dropdown-item" onClick="return confirm('#Bu Kayıt Silinecektir ! Onaylıyor musunuz ?')" href="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=usil&uid=<?php echo $rsfu["id"]?>&urunid=<?php echo $rsu["id"]?>"><i class="fa fa-times" aria-hidden="true"></i> <?php echo $sdil[204]; //Kaldir?></a>
															</div>
														</div>
													</td>
												</tr>
											</table>
										</form>
									<?php } //rsfu.movenext : loop ?>
								<?php } //end if ?>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="alert alert-info v3-row" style=" font-size:9px;bottom:-20px;">
			Bu Kayıt <?php echo $rs["ts1"];?> tarihinde Eklenmiş <?php if(!empty($rs["ts2"])){?> ve <?php echo $rs["ts2"];?> tarihinde güncellenmiştir. <?php }?>
		</div>
	</div>
</section>
</div>
</div>
</section>
<aside id="sidebar-right" class="sidebar-right">
	<div class="nano">
		<div class="nano-content">
			<a href="#" class="mobile-close d-md-none">
				Collapse <i class="fa fa-chevron-right"></i>
			</a>
			<div class="sidebar-right-wrapper">
				...
			</div>
		</div>
	</div>
</aside>
</div>
</section>
<script>
	function startDictation() {
		if (window.hasOwnProperty('webkitSpeechRecognition')) {
			var recognition = new webkitSpeechRecognition();
			recognition.continuous = false;
			recognition.interimResults = false;
			recognition.lang = "tr-TR";
			recognition.start();
			recognition.onresult = function(e) {
				document.getElementById('fcontrol').value
				= e.results[0][0].transcript;
				recognition.stop();
        //document.getElementById('labnol').submit();
    };
    recognition.onerror = function(e) {
    	recognition.stop();
    }
}
}
</script>
<?php
//--/Fatura Ekle/-------
if($_GET["durum"]=="kaydet"){
	if($_POST["cari"]==0){echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&hata3",self,500,1);}
	if($_POST["fno"]==""){echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&hata4",self,500,1);}
	$sqlk = mysqli_query($conn, "select * from t4 where ne='".$_GET["islem"]."' and s1=".$_POST["cari"]." and t1=".$_POST["fno"]." order by id desc"); $rsk=mysqli_fetch_assoc($sqlk);
	
	if(mysqli_num_rows($sqlk)>0){
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$rsk["id"]."",self,500,1);
	}else{
		$ftarih = explode('.',$_POST["ftarih"]);
		$sql = $conn->query("insert into t4(t1,t4,ne,ts1,s1,s2,s3,s4,s17,pb1,pb2,pb3,pb4) values ('".$_POST["fno"]."', '".$_POST["t4"]."', '".$_GET["islem"]."', '".$ctarih."', '".$_POST["cari"]."', '".$ftarih[0]."', '".$ftarih[1]."', '".$ftarih[2]."', '".$_SESSION["user_id"]."', '0', '0', '0', '0')");
		$sql = mysqli_query($conn, "select * from t4 where ne='".$_GET["islem"]."' order by id desc"); $rs=mysqli_fetch_assoc($sql);
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$rs["id"]."&durum=ok",self,500,1);
	}
//--/Fatura Ekle/-------
//--/Fatura Güncelle/---
}elseif($_GET["durum"]=="guncelle"){
	$ftarih = explode('.',$_POST["ftarih"]);
	$Rs = mysqli_query($conn, "update t4 set t1='".$_POST["fno"]."', t2='".$_POST["otipi"]."', t4='".$_POST["t4"]."', pb1='".$_POST["ttoplam"]."', pb2='".$_POST["ttutar"]."', pb3='".$_POST["kdv"]."', pb4='".$_POST["indirim"]."', s1='".$_POST["cari"]."', s2='".$ftarih[0]."', s3='".$ftarih[1]."', s4='".$ftarih[2]."' where id=".$_GET["id"]."");
	echo '<body onload="window.opener.location.reload();">';
//------------/Cari Kontrol ve Güncelle/---
	$sqlf = mysqli_query($conn, "select * from t4 where id='".$_GET["id"]."' order by id desc"); $rsf=mysqli_fetch_assoc($sqlf);
	if($_GET["ttoplam"]<>"0"){ //Tutar Boş Değilse
		if($rsf["ne"]=="sfatura"){
			$pb1=$rsf["pb2"]-$rsf["pb4"];
		//------------/Tahsilat Boş Değilse/---
			if($_POST["tahsilat"]=="" or $_POST["tahsilat"]=="0"){
				$pb2="0";
			}else{
				$pb2=$_POST["tahsilat"];
			}
		//------------/Tahsilat Boş Değilse/---
			$pb3="0";
			$pb4="0";
		}elseif($rsf["ne"]=="afatura" or $rsf["ne"]=="ifatura"){
			$pb1="0";
			$pb2="0";
			$pb3=$rsf["pb2"]-$rsf["pb4"];
			//------------/Tahsilat Boş Değilse/---
			if($_POST["tahsilat"]=="" or $_POST["tahsilat"]=="0"){
				$pb4="0";
			}else{
				$pb4=$_POST["tahsilat"];
			}
	//------------/Tahsilat Boş Değilse/---
		}
//------------/Cari Kaydet/---
		$sqlc = mysqli_query($conn, "select * from t4 where ne='cari' and s1=".$_POST["cari"]." and s5=".$_GET["id"]." order by id desc"); $rsc=mysqli_fetch_assoc($sqlc);
		if(mysqli_num_rows($sqlc)==0){
			$sql = $conn->query("insert into t4(t1,t2,ne,t4,t5,t6,pb1,pb2,pb3,pb4,s1,s2,s3,s4,s5,n1,ts1) values ('".$rsf["t2"]."', '".$_GET["islem"]."', 'cari', '".$rsf["t1"]."', '".$rsf["t4"]."', 'TL', '".$pb1."', '".$pb2."', '".$pb3."', '".$pb4."', '".$rsf["s1"]."', '".$rsf["s2"]."', '".$rsf["s3"]."', '".$rsf["s4"]."', '".$_GET["id"]."', '".$rsf["t1"]." Nolu Fatura', '".$ctarih."')");	
		}else{
			$Rs = mysqli_query($conn, "update t4 set t1='".$rsf["t2"]."', t2='".$_GET["islem"]."', ne='cari', t4='".$rsf["t1"]."', t5='".$rsf["t4"]."', t6='TL', pb1='".$pb1."', pb2='".$pb2."', pb3='".$pb3."', pb4='".$pb4."', s1='".$rsf["s1"]."', s2='".$rsf["s2"]."', s3='".$rsf["s3"]."', s4='".$rsf["s4"]."', n1='".$rsf["t1"]." Nolu Fatura' where id=".$rsc["id"]."");
	} //end if
//------------/Cari Kaydet/---
	}	//Tutar Boş Değilse
//------------/Cari Kontrol ve Güncelle/---
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);
//--/Fatura Tutar Güncelle/---
//--/Ürün Ekle/---------
}elseif($_GET["durum"]=="uekle"){
	$sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where t4='".$_POST["t1"]."' order by id desc"); $rsu=mysqli_fetch_assoc($sqlu);
	if(mysqli_num_rows($sqlu)==0){
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=hata",self,500,1);
	}else{
		$id=$rsu["id"];
		include("../deppo/tools/script/fiyat.php");
		if($_GET["islem"]=="afatura" or $_GET["islem"]=="ifatura"){
			$sql = $conn->query("insert into t4(t1,ne,ts1,s1,s2,s3,s4,s5,pb1) values ('".$_GET["islem"]."', 'furun', '".$ctarih."', ".$_GET["id"].", ".$rsu["id"].", '0', '0', '0', '0')");
		}else{
			$fiyat=$rsu["pb1"];
			if($_POST["s5"]==0){$ps5=1;}else{$ps5=$_POST["s5"];}
			if($rsu["s5"]<>0){
				$sql = $conn->query("insert into t4(t1,ne,ts1,s1,s2,s4,s5,pb1) values ('".$_GET["islem"]."', 'furun', '".$ctarih."', ".$_GET["id"].", ".$rsu["id"].", ".$rsu["s4"].", '".$ps5."', '".$fiyat."')");	
				$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$rsu["s5"]."-1' where id=".$rsu["id"]."");
			}else{
				echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=hata2",self,500,1);
			}
		} //end if
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);
	}
//--/Ürün Ekle/---------
//--/Ürün Güncelle/-----
}elseif($_GET["durum"]=="uguncelle"){
	$sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$_POST["urunid"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu);
	$sql = mysqli_query($conn, "select * from t4 where id=".$_GET["uid"]." order by id desc"); $rs=mysqli_fetch_assoc($sql);
	if($_GET["islem"]=="afatura" or $_GET["islem"]=="ifatura"){
//--/Alış Faturası/-----
//--/Varyasyon İşle/-----
		if($_POST["rb"]<>""){
			$rb=$_POST["rb"];
			$sqlb = mysqli_query($conn, "select * from varyasyon where id=".$rb." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
			if($_POST["fuadet"]=$rs["s5"]){
				$vadet=$rsb["s5"];
			}else{
				if($_POST["fuadet"] < $rs["s5"]){
					$vfadet=$_POST["fuadet"]-$rs["s5"];
					$vadet=$rs["s5"]+$vfadet;
				}elseif ($_POST["fuadet"] > $rs["s5"]){
					$vfadet=$rs["s5"]-$_POST["fuadet"];
					$vadet=$rs["s5"]-$vfadet;
				}
		} //end if
		$Rs = mysqli_query($conn, "update varyasyon set s5='".$vadet."' where id=".$_POST["rb"]."");
	}else{
		$rb="0";
	}
//--/Varyasyon İşle/-----
	if ($_POST["fuadet"]==$rs["s5"]){
		$adet=$rs["s5"];
	}else{   
		if($_POST["fuadet"] < $rs["s5"]){
			$fadet=$_POST["fuadet"]-$rs["s5"];
			$adet=$rsu["s5"]+$fadet;
		}elseif($_POST["fuadet"] > $rs["s5"]){
			$fadet=$rs["s5"]-$_POST["fuadet"];
			$adet=$rsu["s5"]-$fadet;
		}
	}
	$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$adet."', pb3='".$_POST["fufiyat"]."' where id=".$_POST["urunid"]."");
	$Rs = mysqli_query($conn, "update t4 set s5='".$_POST["fuadet"]."', pb1='".$_POST["fufiyat"]."', s4='".$_POST["s4"]."', s6='".$rb." where id=".$_GET["uid"]."");
//--/Alış Faturası/-----
}elseif($_GET["islem"]=="sfatura"){
//--/Varyasyon İşle/-----
	if($_POST["rb"]<>""){
		$rb=$_POST["rb"];
		$sqlb = mysqli_query($conn, "select * from varyasyon where id=".$rb." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
		if($_POST["fuadet"]==$rs["s5"]){
			$vadet=$rsb["s5"];
		}else{
			if($_POST["fuadet"] < $rs["s5"]){
				$vfadet=$_POST["fuadet"]-$rs["s5"];
				$vadet=$rsb["s5"]-$fadet;
			}elseif($_POST["fuadet"] > $rs["s5"]){
				$vfadet=$rs["s5"]-$_POST["fuadet"];
				$vadet=$rsb["s5"]+$vfadet;
				if($vadet < 0){ echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=hata2",self,500,1); }
	//--/Stok Kontrol/---
			} //end if
		} //end if
		$Rs = mysqli_query($conn, "update varyasyon set s5='".$vadet."' where id=".$_POST["rb"]."");
	}else{
		$rb="0";
	} //end if
//--/Varyasyon İşle/-----
//--/Satış Faturası/-----
	if($_POST["fuadet"]==$rs["s5"]){
		$adet=$rsu["s5"];
	}else{  
		if($_POST["fuadet"] < $rs["s5"]){
			$fadet=$_POST["fuadet"]-$rs["s5"];
			$adet=$rsu["s5"]-$fadet;
		}elseif($_POST["fuadet"] > $rs["s5"]){
			$fadet=$rs["s5"]-$_POST["fuadet"];
			$adet=$rsu["s5"]+$fadet;
			if($adet < 0){ echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=hata2",self,500,1); }
//--------------/Stok Kontrol/---
			} //end if
		} //end if
		$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$adet."' where id=".$_POST["urunid"]."");
		$Rs = mysqli_query($conn, "update t4 set s5='".$_POST["fuadet"]."', pb1='".$_POST["fufiyat"]."', s4='".$_POST["s4"]."', s6='".$rb."' where id=".$_GET["uid"]."");
//--/Satış Faturası/-----
	}
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);
//--/Ürün Güncelle/-----
//--/Stok İade/---------
}elseif($_GET["durum"]=="usil"){
	$sqlfu = mysqli_query($conn, "select * from t4 where id=".$_GET["uid"]." order by id desc"); $rsfu=mysqli_fetch_assoc($sqlfu);
	$sqlu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$_POST["urunid"]." order by id desc"); $rsu=mysqli_fetch_assoc($sqlu); //Ürün Adet
	if($_GET["islem"]=="afatura" or $_GET["islem"]=="ifatura"){
		$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$rsu["s5"]-$rsfu["s5"]."' where id=".$_POST["urunid"]."");
//--/Varyasyon iade/----
		if($rsfu["s6"]<>"0"){
			$sqlb = mysqli_query($conn, "select * from varyasyon where id=".$rsfu["s6"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
			$Rs = mysqli_query($conn, "update varyasyon set s5='".$rsb["s5"]-$rsfu["s5"]."' where id=".$rsfu["s6"]."");
	} //end if
//--/Varyasyon iade/----
}elseif($_GET["islem"]=="sfatura"){
//--/Varyasyon iade/----
	if($rsfu["s6"]<>"0"){
		$sqlb = mysqli_query($conn, "select * from varyasyon where id=".$rsfu["s6"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
		$Rs = mysqli_query($conn, "update varyasyon set s5='".$rsb["s5"]+$rsfu["s5"]."' where id=".$rsfu["s6"]."");
	} //end if
//--/Varyasyon iade/----
	$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$rsu["s5"]+$rsfu["s5"]."' where id=".$_POST["urunid"]."");
	} //end if
//--/Stok İade/---------
	$sql = mysqli_query($conn, "delete from t1 where s2=".$_GET["id"]."");
	$sql = mysqli_query($conn, "delete from t4 where id=".$_GET["uid"]."");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);
//--/Fatura Sil/--------
}elseif($_GET["durum"]=="sil"){
	$sql = mysqli_query($conn, "delete from t4 where id=".$_GET["id"]." or s5=".$_GET["id"]."");
	echo '<body onload="window.opener.location.reload(); window.close()">';
//--/Fatura Sil/--------
}
?>