<?php
	$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);
		$s5=$rsu["s5"]-$rsfu["s5"];
		$Rs = mysqli_query($conn, "update ".$_SESSION["lang"]." set s5='".$s5."' where id=".$rsfu["s2"]."");
	} //rsfu.movenext : loop
//--/Satış Faturası/-----
//------------/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($rsf["pb2"]<>0){ //Tutar Boş Değilse
			$pb1=str_replace(',','',$rsf["pb2"]);
			$pb2=0;
	if($rsf["t7"]<>0){ //Tahsilat Boş Değilse
			$pb3=str_replace(',','',number_format($rsf["t7"],2));
	}else{
			$pb3=0;
	}
			$pb4=0;
//------------/Cari Kaydet/---
		$sqlc = mysqli_query($conn, "select * from t4 where ne='cari' and s1=".$_POST["s1"]." 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["ne"]."', 'cari', '".$rsf["t9"]."', '".$rsf["t1"]."', '".$kpb."', '".$pb1."', '".$pb2."', '".$pb3."', '".$pb4."', '".$rsf["s1"]."', '".$rsf["s2"]."', '".$rsf["s3"]."', '".$rsf["s4"]."', '".$_GET["id"]."', '".$rsf["t1"]." Nolu Sipariş', '".$ctarih."')");	
		}else{
			$Rs = mysqli_query($conn, "update t4 set t1='".$rsf["t2"]."', t2='".$_GET["islem"]."', ne='cari', t4='".$rsf["t9"]."', t5='".$rsf["t1"]."', 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 Sipariş' where id=".$rsc["id"]."");
	} //end if
//------------/Cari Kaydet/---
	}	//Tutar Boş Değilse
//------------/Cari Kontrol ve Güncelle/---
?>