<?php 
$path="../../../";
$path2="config/"; include("".$path."config/map.php");
include("".$path."deppo/tools/script/fonksiyon".$ver.".php");
include("".$path."deppo/tools/script/cevir.php");
if($_GET["ne"]=="siparis"){
	$invoice = file_get_contents(''.$weburl.'/ws/?module='.$_GET["ne"].'&itemid='.$_GET["id"].'');
	$invoice = json_decode($invoice, true);
	//Print_r($invoice); exit();
	$sqlic=mysqli_query($conn, "select * from t4 where s5=".$_GET["id"].""); $rsic=mysqli_fetch_assoc($sqlic);
	if(mysqli_num_rows($sqlic)==0){
		$sql = $conn->query("insert into t4(t1,t2,t3,t4,t9,ne,n2,ts1,s1,s2,s3,s4,s5,s19,pb1,pb2,pb3,pb4) values ('".$invoice["data"][0]["orderNo"]."', '".$invoice["data"][0]["paymentMethod"]."', '', 'fatura', '".date("Y-m-d")."', 'sfatura', '".$invoice["data"][0]["orderNo"]." Nolu Sipariş', now(), '".$invoice["data"][0]["userID"]."', '', '', '', '".$invoice["data"][0]["id"]."', '".$_SESSION["user_id"]."', '0', '".$invoice["data"][0]["total"]."', '".$invoice["data"][0]["total"]."', '0')");
		$invoice_Id = $conn->insert_id;
		if($invoice["data"][0]["Interest"]>0){
			$sql  = $conn->query("insert into t4(t1,t6,t10,ne,n1,ts1,s1,s2,s3,s4,s5,pb1,pb2,n17) values ('sfatura', 'TRY', 'adet', 'furun', 'Vade Farkı', now(), ".$invoice_Id.", '0', '0', '18', '1', '".$invoice["data"][0]["Interest"]."', '0', '".addslashes(stripslashes($rjsi))."')");
		}
		if($invoice["data"][0]["cargoPrice_width_tax"]>0){
			$sql  = $conn->query("insert into t4(t1,t6,t10,ne,n1,ts1,s1,s2,s3,s4,s5,pb1,pb2,n17) values ('sfatura', 'TRY', 'adet', 'furun', 'Sevkiyat Ücreti', now(), ".$invoice_Id.", ".$invoice["data"][0]["cargoID"].", '0', '18', '1', '".$invoice["data"][0]["cargoPrice_width_tax"]."', '0', '".addslashes(stripslashes($rjsi))."')");
		}
		foreach($invoice["data"][0]["products"] as $key=>$value){
			$sql  = $conn->query("insert into t4(t1,t6,t10,ne,ts1,s1,s2,s3,s4,s5,pb1,pb2,n17) values ('sfatura', 'TRY', '".$value["unit"]."', 'furun', now(), ".$invoice_Id.", ".$value["id"].", '0', ".$value["tax_percent"].", '".$value["qyt"]."', '".$value["price_with_tax"]."', '0', '".addslashes(stripslashes($rjsi))."')");
		}
		echo "<center>Muhasebeye Aktarıldı</center>";
		sleep(5);
	}else{
		exit();
	}
}
?>
<center style="margin-top: 10%; font-size: 30px;">
<?php
	$sqli=mysqli_query($conn, "select * from genel where ne='tanim' and t2='efatura'"); $rsi=mysqli_fetch_assoc($sqli);
	if(mysqli_num_rows($sqli) > 0) {
		include("../integration/AccountingOperations/gib/efatura/invoice.php");
		if($rinvoice["faultstring"]<>""){
			include("../integration/AccountingOperations/gib/earsiv/invoice.php");
		}
		if($sendF->REQUEST_RETURN->RETURN_CODE=="0"){
			echo "Fatura Gonderildi<br>";
			echo "<h3>Fatura No : <b>".$sendF->INVOICE_ID."</b></h3>";
			if($_GET["ne"]=="fatura"){$tbl="t4";}else{$tbl="eticaret";}
			$sql = mysqli_query($conn, "update $tbl set t1='".$sendF->INVOICE_ID."' where id=".$_GET["id"]."");
		}else{
			//echo "#".$sendF->ERROR_TYPE->INTL_TXN_ID."<br>".$sendF->ERROR_TYPE->ERROR_SHORT_DES." => ".$sendF->ERROR_TYPE->ERROR_CODE;
			echo "#".$sendF->ERROR_TYPE->ERROR_CODE;
		}
	}else{
		echo "Entegrasyon henüz yapılmamış";
	}
?>
</center>