<?php
//-- Operation -->
$sql = mysqli_query($conn, "select * from eticaret where id=".$_GET["id"]." order by id desc"); $rsi=mysqli_fetch_assoc($sql);
$sqlm = mysqli_query($conn, "select * from t5 where id=".$rsi["s1"]." order by id desc"); $customer=mysqli_fetch_assoc($sqlm);
if($rsi["s4"]<>$_GET["s4"]){
	if($_GET["s4"]==0){  //-- Bekleme -->
		//-- Stok -->
		if($rsi["s4"]==1 or $rsi["s4"]==3){       //-- Sevkiyattan veya Onayda Stok iade -->
			if($f7==1){
				$sqlsip = mysqli_query($conn, "select * from eticaret where ne='sepet' and s5=".$_GET["id"]." order by id desc"); while($rssip=mysqli_fetch_assoc($sqlsip)){
					$sqlb = mysqli_query($conn, "select * from t1 where ne='varyant' and id=".$rssip["s5"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
					if(mysqli_num_rows($sqlb)>0){
						$s5 = $rsb["s5"]+$rssip["s2"];
						$up = mysqli_query($conn, "update t1 set s5='".$s5."' where id=".$rssip["s5"]."");
					}
					$sqsu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rssip["s3"].""); $rssu=mysqli_fetch_assoc($sqsu);
					$s5 = $rssu["s5"]+$rssip["s2"];
					//echo "b:".$s5."";
					$up = mysqli_query($conn, "update lang1 set s5='".$s5."' where id=".$rssip["s3"]."");
					$up = mysqli_query($conn, "update eticaret set s12='0' where ne='sepet' and id=".$rssip["id"]."");
				}	//rssip While
			}
		}                                                               //-- Sevkiyattan veya Onayda Stok iade -->
		//-- Stok -->
	}elseif($_GET["s4"]==1){       //-- Onaylama -->
		//-- Stok -->
		if($rsi["s4"]<>3){                      //-- Sevkiyattan geri gelirse Stok düşme -->
			if($f7==1){
				$sqlsip = mysqli_query($conn, "select * from eticaret where ne='sepet' and s5=".$_GET["id"]." order by id desc"); while($rssip=mysqli_fetch_assoc($sqlsip)){		
					$sqlb = mysqli_query($conn, "select * from genel where ne='varyant' and id=".$rssip["s5"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
					if(mysqli_num_rows($sqlb)>0){
						if($rsb["s5"]==0 or $rssip["s2"] > $rsb["s5"]){
							echo "<SCRIPT LANGUAGE='JavaScript'>window.location='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&s4=".$_GET["s4"]."&id=".$_GET["id"]."&durum=hata';</script>";
						}else{
							$s5=$rsb["s5"]-$rssip["s2"];
							$up = mysqli_query($conn, "update t1 set s5='".$s5."' where id=".$rssip["s5"]."");
							$up = mysqli_query($conn, "update eticaret set s12='".$rssip["s2"]."' where ne='sepet' and id=".$rssip["id"]."");
						}
					}
					$sqsu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rssip["s3"].""); $rssu=mysqli_fetch_assoc($sqsu);
					if($rssu["s5"]==0 or $rssip["s2"] > $rssu["s5"]){
						echo "<SCRIPT LANGUAGE='JavaScript'>window.location='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&s4=".$_GET["s4"]."&id=".$_GET["id"]."&durum=hata';</script>";
					}else{
						$s5 = $rssu["s5"]-$rssip["s2"];
						//echo "O:".$s5."";
						$up = mysqli_query($conn, "update lang1 set s5='".$s5."' where id=".$rssip["s3"]."");
						$up = mysqli_query($conn, "update eticaret set s12='".$rssip["s2"]."' where ne='sepet' and id=".$rssip["id"]."");
					}
				}
			}
		}	//-- Sevkiyattan geri gelirse Stok düşme -->
		//-- Stok -->
		
	}elseif($_GET["s4"]==3){       //-- Sevkiyat -->
		//-- Stok -->
		if($rsi["s4"]==0 or $rsi["s4"]==2){       //-- Beklemeden veya İptalden gelirse Stok düş -->
			if($f7==1){
				$sqlsip = mysqli_query($conn, "select * from eticaret where ne='sepet' and s5=".$_GET["id"]." order by id desc"); while($rssip=mysqli_fetch_assoc($sqlsip)){
					$sqlb = mysqli_query($conn, "select * from genel where ne='varyant' and id=".$rssip["s5"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
					if(mysqli_num_rows($sqlb)>0){
						if($rsb["s5"]==0 or $rssip["s2"] > $rsb["s5"]){
							echo "<SCRIPT LANGUAGE='JavaScript'>window.location='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&s4=".$_GET["s4"]."&id=".$_GET["id"]."&durum=hata';</script>";
						}else{
							$s5=$rsb["s5"]-$rssip["s2"];
							$up = mysqli_query($conn, "update t1 set s5='".$s5."' where id=".$rssip["s5"]."");
						}
					}
					$sqsu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rssip["s3"].""); $rssu=mysqli_fetch_assoc($sqsu);
					if($rssu["s5"]==0 or $rssip["s2"] > $rssu["s5"]){
						echo "<SCRIPT LANGUAGE='JavaScript'>window.location='?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&s4=".$_GET["s4"]."&id=".$_GET["id"]."&durum=hata';</script>";
					}else{
						$s5 = $rssu["s5"]-$rssip["s2"];
						//echo "S:".$s5."";
						$up = mysqli_query($conn, "update lang1 set s5='".$s5."' where id=".$rssip["s3"]."");
					}
				}
			}
		}                                                               //-- Beklemeden veya İptalden gelirse Stok düş -->
		//-- Stok -->
	
	}elseif($_GET["s4"]==2 or $_GET["s4"]==5){       //-- İptal / İade -->
		//-- Stok -->
		//if($rsi["s4"]<>0){                      //-- Beklemeden gelirse Stok düşme -->
			if($f7==1){
				$sqlsip = mysqli_query($conn, "select * from eticaret where ne='sepet' and s5=".$_GET["id"]." order by id desc"); while($rssip=mysqli_fetch_assoc($sqlsip)){
					$sqlb = mysqli_query($conn, "select * from t1 where ne='varyant' and id=".$rssip["s5"]." order by id desc"); $rsb=mysqli_fetch_assoc($sqlb);
					if(mysqli_num_rows($sqlb)>0){
						$s5=$rsb["s5"]+$rssip["s2"];
						$up = mysqli_query($conn, "update lang1 set s5='".$s5."' where id=".$rssip["s3"]."");
					}
					$sqsu = mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rssip["s3"].""); $rssu=mysqli_fetch_assoc($sqsu);
					$s5=$rssu["s5"]+$rssip["s2"];
				//echo "İ:".$s5."";
					$up = mysqli_query($conn, "update lang1 set s5='".$s5."' where id=".$rssip["s3"]."");
					$up = mysqli_query($conn, "update eticaret set s12='0' where ne='sepet' and id=".$rssip["id"]."");
				}
			}
		//}                                                                //-- Beklemeden gelirse Stok düşme -->
		//-- Stok -->
	}
}
//-- Operation -->
//-- Notification -->
	if($rsi["s4"]<>$_REQUEST["s4"]){
		if($_REQUEST["s4"]==1){
			$konu=translate("+#Sipariş Onay");
			$icerik="<b>".$rsi["t4"]."</b> ".translate("+#order_mail_approved")."";
			$smstxt="".$rsi["t4"]." ".translate("+#order_sms_approved")."";
			//-- Cari -->
			if($c7==1){
				$sql = mysqli_query($conn, "select * from eticaret where id=".$_GET["id"]." order by id desc"); $siparis=mysqli_fetch_assoc($sql);
			//------------/Cari Kontrol ve Güncelle/---
				if($siparis["t5"]=="pos" or $siparis["t5"]=="payu"){
					$t1="Pos";
					$pb3=$_REQUEST["ototal"];
				}elseif($siparis["t5"]=="havale" or $siparis["t5"]=="kapida" or $siparis["t5"]=="morder"){
					$t1="Banka";
					$pb3="0";
				}elseif($siparis["t5"]=="modeme"){
					$t1="Nakit";
					$pb3="0";
				}
				$pb3=$_REQUEST["ototal"];
				$sqlc = mysqli_query($conn, "select * from t4 where ne='cari' and s5=".$_GET["id"]." order by id desc"); $cari=mysqli_fetch_assoc($sqlc);
				if(mysqli_num_rows($sqlc)>0){
					$sql = mysqli_query($conn, "update t4 set pb3='".$pb3."' where s5=".$_GET["id"]."");
				}
			//------------/Cari Kontrol ve Güncelle/---
			}
		//-- Cari -->
		}elseif ($_REQUEST["s4"]==2){
			$konu=translate("+#Sipariş İptal Edildi");
			$smstxt="".$rsi["t4"]." ".translate("+#order_sms_cancelled")."";
			$icerik="<b>".$rsi["t4"]."</b> ".translate("+#order_mail_cancelled")." ".$_POST["note"]."";
		}elseif($_REQUEST["s4"]==3){
			$konu=translate("+#Sipariş Sevkiyat Sürecinde");
			$smstxt="".$rsi["t4"]." ".translate("+#order_sms_shipped")."";
			$icerik="<b>".$rsi["t4"]."</b> ".$rsi["t12"]." [<a href=\"".cargotracking($rsi["t12"],$rsi["t13"])."\" target=\"_blank\">".$rsi["t13"]."</a>] ".translate("+#order_mail_shipped")."";
		}elseif($_REQUEST["s4"]==4){
			$konu=translate("+#Sipariş Teslimat Edildi");
			$smstxt="".$rsi["t4"]." ".translate("+#order_sms_complated")."";
			$icerik="<b>".$rsi["t4"]."</b> ".translate("+#order_mail_complated")."";
		}elseif($_REQUEST["s4"]==5){
			$konu=translate("+#Sipariş İade Onaylandı");
			$smstxt="".$rsi["t4"]." ".translate("+#order_sms_returned")."";
			$icerik="<b>".$rsi["t4"]."</b> ".translate("+#order_mail_returned")."";
		}
		$mesaj	= "
		<h3>".$konu."</h3>
		".$icerik."
		";
		$mesaj	= $design_top.$mesaj.$design_bottom;
		$path="../../../";
		if($_GET["barcode"]==""){
			if($module["user_bildirim_sms"]>0){
				smsgonder($smstxt,telefon($customer["t4"]));
			}
			if($module["user_bildirim_email"]>0){
				emailgonder(v3d($customer["t2"]), $konu, '', $mesaj);
			}
			if($module["user_bildirim_notification"]>0){
				sNotification($smstxt, $konu, "Crm");
			}
		}
	}
	//-- Notification -->
?>