<?php
//include("../../secure.php");
$path="../../";
include("../../map.php");
if($_GET["op"]<>"xls"){
	include("../../scripts.php");
}
if($module["e8_type"]=="1"){$type="dn";}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style type="text/css">
	table {font-family: 'Open Sans', sans-serif;}
</style>
<div id="printed">
<?php if($_GET["durum"]=="seor"){?>
<title>Seo Report</title>
<table style="width:100%; margin-bottom:15px;">
	<tr>
		<td><img src="<?php echo $logo?>" style="height:80px;"></td>
		<td>
			<div style="width: 50%; border: 1px dashed #c53939; color: #c53939; text-align: center; transform: rotate(-5deg);">
				<h3 style="margin-top: 5px;">Seo Report</h3>By CrmPlus+
			</div>
			<span class="noprint" onclick="divyaz('printed')" style="position: absolute; right: 0px; top: 0px; padding: 5px; background: beige;">Yazdır</span>
		</td>
	</tr>
</table>
<?php }?>
<?php
if($module["e8_type"]=="1"){$dn="display:none"; $tcols="3";}else{$tcols="5";}
if($_GET["durum"]=="ucari" or $_GET["durum"]=="ucari_mail"){
	if($MA<>1 and $_GET["op"]<>"xls"){echo "<title>Cari Döküm</title> <body onload=\"window.print()\">";}
	$sql=mysqli_query($conn, "select * from t5 where id=".$_GET["id"]." order by id desc"); $rsm=mysqli_fetch_assoc($sql);
	$header="
	<div id=\"topdf\">
	<table border='0' cellpadding='0' cellspacing='0' style='width: 90%; margin-left: 5%; margin-top: 10px;' id='table2' class=\"noshadow\">
	<tr>
	<td valign='top' style=\"text-align:left;\"><img src=\"".$logo."\" style='max-height:65px;'  referrerpolicy='no-referrer'></td>
	<td valign='top' style=\"text-align:right; font-size:12px;\">
		".date("d.m.Y")."</br>
		".$rsm["t1"]."<br>
		".$rsm["t4"]."<br>
		".v3d($rsm["t2"])."
	</td>
	</tr>
	</table>
	";
	if($_GET["durum"]=="ucari_mail"){$header="";}
	$mesaj .= "
	<table class='table' cellspacing='0' style='width: 90%; margin-left: 5%; margin-top: 10px; font-size:13px;' class=\"noshadow\">
	<thead>
	<tr>
		<th class=\"w5\">".translate("Tarih")."</th>
		<th>".translate("Kısa Açıklama")."</th>
		<th style=\"text-align:right;\"class='w10'>".$sdil[155]."</th>
		<th style=\"text-align:right; ".$dn."\" class='w10'>".$sdil[157]."</th>
		<th style=\"text-align:right;\" class='".$type." w10'>".$sdil[156]."</th>
		<th style=\"text-align:right; ".$dn."\" class='".$type." w10'>".$sdil[158]."</th>
	</tr>
	</thead>
	<tbody>
	";
	$sqlc=mysqli_query($conn, "select * from t4 where ne='cari' and s1=".$_GET["id"]." order by id desc"); while($hcari=mysqli_fetch_assoc($sqlc)){
		include("../clients/client_current_calc2.php");
		if(($_GET["ts1"]=="" and $_GET["ts2"]=="") or ($_GET["ts1"]<>"" and $_GET["ts2"]<>"") and ($hcari["t4"]>=$_GET["ts1"] and $hcari["t4"]<=$_GET["ts2"])){
			$mesaj .= "
			<tr>
				<td>".dtarih($hcari["t4"],"gg/aa/yy")."</td>
				<td>".$hcari["n1"]."</td>
				<td style=\"text-align:right;\">".wprice($hcari["pb1"])." <i class=\"fa fa-".$hcari["t6"]."\"></i></td>
				<td style=\"text-align:right;".$dn."\">".wprice($hcari["pb2"])." <i class=\"fa fa-".$hcari["t6"]."\"></i></td>
				<td style=\"text-align:right;\" class='".$type."'>".wprice($hcari["pb3"])." <i class=\"fa fa-".$hcari["t6"]."\"></i></td>
				<td style=\"text-align:right;".$dn."\" class='".$type."'>".wprice($hcari["pb4"])." <i class=\"fa fa-".$hcari["t6"]."\"></i></td>
			</tr>
			";
		}}
		$mesaj .= "
		<tr>
		<td colspan='1'>
		";
		if(($mcpb1-$mcpb2)-($mcpb3-$mcpb4)>0){
		$mesaj .= "
		<button class=\"v3-btn\">".$ikpb." ".wprice(($mcpb1-$mcpb2)-($mcpb3-$mcpb4))."</button>
		";
		}
		$mesaj .= "
		</td>
		<td colspan='".$tcols."' style='text-align: right; color: #f00; font-size: 14px; font-weight: 800;'>
		";
		if($module["currency"]<>""){
			$mesaj .= "
			<button class=\"v3-btn v3-btn-success\">".$ikpb." ".wprice(($cpb1-$cpb2)-($cpb3-$cpb4))."</button>
			";
		}else{
			if(($try_pb1-$try_pb2)-($try_pb3-$try_pb4)>0){
				$mesaj .= "
				<button class=\"v3-btn v3-btn-success\"><i class=\"fa fa-try\"></i> ".wprice(($try_pb1-$try_pb2)-($try_pb3-$try_pb4))."</button>
				";
			}
			if(($eur_pb1-$eur_pb2)-($eur_pb3-$eur_pb4)>0){
				$mesaj .= "
				<button class=\"v3-btn v3-btn-success\"><i class=\"fa fa-eur\"></i> ".wprice(($eur_pb1-$eur_pb2)-($eur_pb3-$eur_pb4))."</button>
				";
			}
			if(($usd_pb1-$usd_pb2)-($usd_pb3-$usd_pb4)>0){
				$mesaj .= "
				<button class=\"v3-btn v3-btn-success\"><i class=\"fa fa-usd\"></i> ".wprice(($usd_pb1-$usd_pb2)-($usd_pb3-$usd_pb4))."</button>
				";
			}
			if(($gbp_pb1-$gbp_pb2)-($gbp_pb3-$gbp_pb4)>0){
				$mesaj .= "
				<button class=\"v3-btn v3-btn-success\"><i class=\"fa fa-gbp\"></i> ".wprice(($gbp_pb1-$gbp_pb2)-($gbp_pb3-$gbp_pb4))."</button>
				";
			}
		}
		$mesaj .= "
		</td>
		</tr>
		</tbody>
		</table>
		</div>
		";
		if($_GET["durum"]=="ucari_mail"){
			$mesaj		= $design_top.$header.$mesaj.$design_bottom;
			$malici		= base64_decode($rsm["t2"]);
			$konu		= translate("+Hesap Özeti");
			$path="../../../";
			emailgonder($malici,$konu,$cc,$mesaj);
		}else{
			if($_GET["op"]=="xls"){
				header("Content-type: application/vnd.ms-excel");
				$file="".cevir($rsm["t1"]).".xls";
				header("Content-type: application/vnd.ms-excel");
				header("Content-Disposition: attachment; filename=".$file."");
				header("Pragma: no-cache");
				header("Expires: 0");
			echo "\xEF\xBB\xBF"; //UTF-8 BOM
			echo $out;
			echo $mesaj;
		}else{
			echo $header.$mesaj;
		}
	}
}elseif($_GET["durum"]=="stok"){
	if($MA<>1){echo "<body onload=\"window.print()\">";}
	$sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$_GET["id"]." order by id desc"); $rs=mysqli_fetch_assoc($sqlu);
	$header="
	<div id=\"topdf\">
	<table border='0' cellpadding='0' cellspacing='0' style='width: 90%; margin-left: 5%; margin-top: 10px;' id='table2' class=\"noshadow\">
	<tr>
	<td valign='top' style=\"text-align:left;\"><img src=\"".$logo."\" style='max-height:65px;' referrerpolicy='no-referrer'></td>
	<td valign='top' style=\"text-align:right;\"> ".date("d.m.Y")."</br> ".$rs["t1"]."<br> ".$rs["t4"]." </td>
	</tr>
	</table>
	";
	$mesaj .= "
	<table class='table' cellspacing='0' style='width: 90%; margin-left: 5%; margin-top: 10px; font-size:13px;' class=\"noshadow\">
	<thead>
	<tr>
	<th>".translate("Firma")."</th>
	<th class=\"w15\">".translate("Belge No")."</th>
	<th class=\"w15\">".translate("Belge Tipi")."</th>
	<th class=\"w10\">".translate("Tarih")."</th>
	<th class=\"w5\">".translate("Miktar")."</th>
	<th class=\"w5\">".translate("Birim")."</th>
	</tr>
	</thead>
	<tbody>
	";
	$sqlreport = mysqli_query($conn, "select * from t4 where ne='stok' and s2=".$_GET["id"]." order by id desc"); while($report=mysqli_fetch_assoc($sqlreport)){
		$sqlm=mysqli_query($conn, "select * from t5 where id=".$report["s1"].""); $rsm=mysqli_fetch_assoc($sqlm);
		$mesaj .= "
		<tr>
		<td>".$rsm["t1"]."</td>
		<td>".$report["t1"]."</td>
		<td>".$report["t2"]."</td>
		<td>".dtarih($report["t9"],"gg aa yyyy")."</td>
		<td>".$report["s5"]."</td>
		<td>".$rs["t10"]."</td>
		</tr>
		";
	}
	$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);
		$mesaj .= "
		<tr>
		<td>".$rsm["t1"]."</td>
		<td>".$rsf["t1"]."</td>
		<td>".$rsf["ne"]."</td>
		<td>".dtarih($rsf["t9"],"gg aa yyyy")."</td>
		";
		if($rsf["ne"]=="sfatura"){$s5=$report["s5"]*-1;
		$mesaj .= "<td>".$s5."</td>";
	}else{
		$mesaj .= "<td>".$report["s5"]."</td>";
	}
	$mesaj .= "
	<td>".$rs["t10"]."</td>
	</tr>
	";
}
$sqlb = mysqli_query($conn, "select distinct t4,s5 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);
		$mesaj .= "
		<tr>
		<td>".$rsm["t1"]."</td>
		<td>".$siparis["t4"]."</td>
		<td>Sipariş</td>
		<td>".dtarih($siparis["ts1"],"gg.aa.yyyy")."</td>
		";
		$s5=$siparis["s2"]*-1;
		$mesaj .= "<td>".$s5."</td>";
		$mesaj .= "
		<td>".$rs["t10"]."</td>
		</tr>
		";
	}}
	$mesaj .= "
	</tbody>
	</table>
	</div>
	";
	echo $header.$mesaj;
}
if($_GET["durum"]=="seor"){
	$sql=mysqli_query($conn, "select DISTINCT n1 FROM genel where ne='seor' order by n1 asc"); while($rs=mysqli_fetch_assoc($sql)){
		echo '<table class="v3-bg-info" style="width:100%">';
			echo '<tr>';
				echo '<td colspan="4" style="padding: 10px;">';
					echo "<b>".$rs["n1"]."</b>";
				echo '</td>';
			echo '</tr>';
		echo '</table>';
			$sql2=mysqli_query($conn, "select * from genel where ne='seor' and n1='".$rs["n1"]."' order by ts1 desc limit 0,3"); while($rs2=mysqli_fetch_assoc($sql2)){
		echo '<table class="v3-bg-warning" style="width:100%">';
			echo '<tr>';
				echo '<td class="" style="padding: 10px; width:25%;">';
					echo "<b>".$rs2["n3"]."</b>";
				echo '</td>';
				echo '<td class="" style="padding: 10px; width:25%;">';
					echo "".$rs2["n2"]."";
				echo '</td>';
				echo '<td class="" style="padding: 10px; width:25%;">';
					echo "".$rs2["n5"]."";
				echo '</td>';
				echo '<td class="" style="padding: 10px; width:25%;">';
					echo "".dtarih($rs2["ts1"], "gg ua yyyy")."";
				echo '</td>';
			echo '</tr>';
		echo '</table>';
		}
	}
}
?>
</div>