<?php
	$path="../../";
	include("../../map.php");
	$sqlt=mysqli_query($conn, "select * from genel where ne='ftasarim'"); $rst=mysqli_fetch_assoc($sqlt);
	if(mysqli_num_rows($sqlt)==0){
		$sqli = $conn->query("insert into genel (ne) values ('ftasarim')");
	}
	$fadres = explode(',',$rst["n1"]);
	$ftarih = explode(',',$rst["n2"]);
	$furunler = explode(',',$rst["n3"]);
	$ftoplam = explode(',',$rst["n4"]);
	$fyaziile = explode(',',$rst["n5"]);
	$fvd = explode(',',$rst["n6"]);
	$fvn = explode(',',$rst["n7"]);
	$not = explode(',',$rst["n8"]);
	$kur = explode(',',$rst["n9"]);
	if($rst["t9"]<>""){
		$fsize = $rst["t9"];
	}else{
		$fsize = 10;
	}
?>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="ruler/ruler.css" rel="stylesheet" type="text/css">
<script src="ruler/jquery.ruler.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div style="position: fixed; margin-left:50%; margin-rigth:50%; top: 100px; width: 60px; height: 60px; font-size: 150px; z-index: 9999999999999999999; display:none;" id="check" class="fa fa-check"></div>
<?php if($MA<>1){?>
<body onload="window.print()">
<?php }?>
   <style type="text/css">
   body { padding:0px; margin:0px; font-family:arial; background-image:url('../../assets/img/<?php if($_SESSION["user"]=="Master" or $_SESSION["user"]=="SuperAdmin"){?>fatura.jpg<?php }?>');}
	table {font-size:<?php echo $fsize?>px; font-family:arial;}
   .fatura{border:solid 0px #ff3333; position:relative; width:100%; height:100%; padding:0px; margin:0px; cursor:pointer;}
   .fadres:hover, .ftarih:hover, .fvd:hover, .fvn:hover, .furunler:hover, .ftoplam:hover, .fyaziile:hover, .not:hover, .kur:hover{
       cursor:move;
       background: rgba(255, 255, 0, 0.5);
       border-top: 1px solid #d0d0d0;
   }
   .fadres {
    <?php if($rst["n1"]==""){?>
       position:absolute; left:70px; top:-8px; width:300px;
   <?php }else{?>
       position:absolute; left:<?php echo $fadres[0]?>px; top:<?php echo $fadres[1]?>px; width:<?php echo $fadres[2]?>px; height:<?php echo $fadres[3]?>px;
   <?php }?>
	}
	.ftarih {
		<?php if($rst["n2"]==""){?>
		   position:absolute; left:727px; top:81px; width:130px;
	   <?php }else{?>
		   position:absolute; left:<?php echo $ftarih[0]?>px; top:<?php echo $ftarih[1]?>px; width:<?php echo $ftarih[2]?>px; height:<?php echo $ftarih[3]?>px;
	   <?php }?>
	}
	.fvd {
	<?php if($rst["n6"]==""){?>
		position:absolute; top:125px; left:500px; width:100px; height:24px;
	<?php }else{?>
		position:absolute; top:<?php echo $fvd[1]?>px; left:<?php echo $fvd[0]?>px; width:<?php echo $fvd[2]?>px; height:<?php echo $fvd[3]?>px;
	<?php }?>
	}
	.fvn {
	<?php if($rst["n7"]==""){?>
		position:absolute; top:150px; left:500px; width:100px; height:24px;
	<?php }else{?>
		position:absolute; top:<?php echo $fvn[1]?>px; left:<?php echo $fvn[0]?>px; width:<?php echo $fvn[2]?>px; height:<?php echo $fvn[3]?>px;
	<?php }?>
	}
	.not {
	<?php if($rst["n8"]==""){?>
		position:absolute; top:150px; left:500px; width:100px; height:24px;
	<?php }else{?>
		position:absolute; top:<?php echo $not[1]?>px; left:<?php echo $not[0]?>px; width:<?php echo $not[2]?>px; height:<?php echo $not[3]?>px;
	<?php }?>
	}
	.kur {
	<?php if($rst["n9"]==""){?>
		position:absolute; top:150px; left:500px; width:100px; height:24px;
	<?php }else{?>
		position:absolute; top:<?php echo $kur[1]?>px; left:<?php echo $kur[0]?>px; width:<?php echo $kur[2]?>px; height:<?php echo $kur[3]?>px;
	<?php }?>
	}
	.furunler {
		<?php if($rst["n3"]==""){?>
		   position:absolute; left:50px;  top:225px; width:95%;
	   <?php }else{?>
		   position:absolute; left:<?php echo $furunler[0]?>px; top:<?php echo $furunler[1]?>px; width:<?php echo $furunler[2]?>px; height:<?php echo $furunler[3]?>px;
	   <?php }?>
	}
	.furun {display:flex; width:95%;}
	.turunler tr td:first-child {width:<?php if($rst["t1"]==""){echo "90";}else{echo $rst["t1"];}?>;}
	.turunler tr td:nth-child(2) {width:<?php if($rst["t2"]==""){echo "330";}else{echo $rst["t2"];}?>;}
	.turunler tr td:nth-child(3) {width:<?php if($rst["t3"]==""){echo "100";}else{echo $rst["t3"];}?>;}
	.turunler tr td:nth-child(4) {width:<?php if($rst["t4"]==""){echo "140";}else{echo $rst["t4"];}?>;}
	.turunler tr td:nth-child(5) {width:<?php if($rst["t5"]==""){echo "40";}else{echo $rst["t5"];}?>;}
	.ftoplam {
		<?php if($rst["n4"]==""){?>
		   position:absolute; left:680px; top:698px; width:200px;
	   <?php }else{?>
		   position:absolute; left:<?php echo $ftoplam[0]?>px; top:<?php echo $ftoplam[1]?>px; width:<?php echo $ftoplam[2]?>px; height:<?php echo $ftoplam[3]?>px;
	   <?php }?>
	}
	.fkdv {position:absolute; left:20px; width:300px;}
	.fgtoplam {position:absolute; left:20px; width:300px;}
	.fyaziile {
		<?php if($rst["n5"]==""){?>
		   position:absolute; left:149px; top:591px; width:415px;
	   <?php }else{?>
		   position:absolute; left:<?php echo $fyaziile[0]?>px; top:<?php echo $fyaziile[1]?>px; width:<?php echo $fyaziile[2]?>px; height:<?php echo $fyaziile[3]?>px;
	   <?php }?>
	}
	ul {list-style:none; padding: 0px;}
	ul li span {width:100px; float: left;}
</style>
<script>
    jQuery(function(){
       <?php if($_SESSION["user"]=="Master" or $_SESSION["user"]=="SuperAdmin"){?>
       //jQuery('body').ruler();
		jQuery('.fadres, .fvd, .fvn, .ftarih, .furunler, .ftoplam, .fkdv, .fgtoplam, .fyaziile, .not, .kur') .draggable() .resizable();     
       jQuery('.fatura').click(function(){
		  //stime('#check','show',1500);
          var d1p = jQuery('.fadres').position();
          var d1h = jQuery('.fadres').height();
          var d1w = jQuery('.fadres').width();
          var data = {"ne" : "n1", "l" : d1p.left, "t" : d1p.top, "w" : d1w, "h" : d1h};
          jQuery.ajax({
             type:'POST', data:data, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d2p = jQuery('.ftarih').position();
          var d2h = jQuery('.ftarih').height();
          var d2w = jQuery('.ftarih').width();
          var data2 = {"ne" : "n2", "l" : d2p.left, "t" : d2p.top, "w" : d2w, "h" : d2h};
          jQuery.ajax({
             type:'POST', data:data2, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d3p = jQuery('.furunler').position();
          var d3h = jQuery('.furunler').height();
          var d3w = jQuery('.furunler').width();
          var data3 = {"ne" : "n3", "l" : d3p.left, "t" : d3p.top, "w" : d3w, "h" : d3h};
          jQuery.ajax({
             type:'POST', data:data3, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d4p = jQuery('.ftoplam').position();
          var d4h = jQuery('.ftoplam').height();
          var d4w = jQuery('.ftoplam').width();
          var data4 = {"ne" : "n4", "l" : d4p.left, "t" : d4p.top, "w" : d4w, "h" : d4h};
          jQuery.ajax({
             type:'POST', data:data4, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d5p = jQuery('.fyaziile').position();
          var d5h = jQuery('.fyaziile').height();
          var d5w = jQuery('.fyaziile').width();
          var data5 = {"ne" : "n5", "l" : d5p.left, "t" : d5p.top, "w" : d5w, "h" : d5h};
          jQuery.ajax({
             type:'POST', data:data5, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d6p = jQuery('.fvd').position();
          var d6h = jQuery('.fvd').height();
          var d6w = jQuery('.fvd').width();
          var data6 = {"ne" : "n6", "l" : d6p.left, "t" : d6p.top, "w" : d6w, "h" : d6h};
          jQuery.ajax({
             type:'POST', data:data6, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d7p = jQuery('.fvn').position();
          var d7h = jQuery('.fvn').height();
          var d7w = jQuery('.fvn').width();
          var data7 = {"ne" : "n7", "l" : d7p.left, "t" : d7p.top, "w" : d7w, "h" : d7h};
          jQuery.ajax({
             type:'POST', data:data7, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d8p = jQuery('.not').position();
          var d8h = jQuery('.not').height();
          var d8w = jQuery('.not').width();
          var data8 = {"ne" : "n8", "l" : d8p.left, "t" : d8p.top, "w" : d8w, "h" : d8h};
          jQuery.ajax({
             type:'POST', data:data8, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          var d9p = jQuery('.kur').position();
          var d9h = jQuery('.kur').height();
          var d9w = jQuery('.kur').width();
          var data9 = {"ne" : "n9", "l" : d9p.left, "t" : d9p.top, "w" : d9w, "h" : d9h};
          jQuery.ajax({
             type:'POST', data:data9, dataType:'json', url:'../../fonksiyon.php?durum=ftasarim'
         });
          return false;
      });
<?php }?>
   });
</script>
<?php
	$sql = mysqli_query($conn, "select * from t4 where id=".$_GET["id"].""); $rsf=mysqli_fetch_assoc($sql);
	$ftarih="".$rsf["s2"].".".$rsf["s3"].".".$rsf["s4"]."";
	$fno="".$rsf["t1"]."";
	$sqlm = mysqli_query($conn, "select * from t5 where id=".$rsf["s1"].""); $rsm=mysqli_fetch_assoc($sqlm);
	$jsi = json_decode($rsm["n17"], true);
	if($h5<>1){
		$fadres = "".$rsm["n5"]."<br>".$rsm["t4"]."";
	}else{
		$sqla=mysqli_query($conn, "select * from t1 where ne='adress' and t2='".$_SESSION['lang']."' and id=".$siparis["s11"].""); $adress=mysqli_fetch_assoc($sqla);
		$fadres .= "".$adress["n2"]." (".$adress["n1"].")<br>";
		$fadres .= "".$adress["n6"]." ".loc($adress["n3"])." / ".loc($adress["n4"])." / ".loc($adress["n5"])."";
	}
	$fcari=$rsm["id"];
	if($rsm["s5"]<>"0"){$fcisk=($rsm["s5"]+100)/100;}else{$fcisk=0;}
?>
<div class="fatura">
	<div class="fadres">
        <b><?php if($jsi["ifirma"]<>""){?><?php echo $jsi["ifirma"];?><br><?php }?><?php echo $rsm["t1"]?></b><br>
        <?php echo $fadres?>
    </div>
    <div class="fvd">
        <?php if($jsi["ivdaire"]<>""){?><?php echo $jsi["ivdaire"]?><?php }else{?><?php echo $jsi["i2"]?><?php }?>
    </div>
    <div class="fvn">
        <?php if($jsi["ivnumara"]<>""){?><?php echo $jsi["ivnumara"]?><?php }else{?><?php echo $jsi["i3"]?><?php }?>
    </div>
    <div class="not"><?php echo $rsf["n1"]?></div>
    <div class="kur"><?php echo $rsf["t4"]?></div>
    <div class="ftarih"><?php echo $ftarih;?></div>
    <div class="furunler">
        <table class="turunler">
            <?php
            include("../accounting/accounting_calc.php");
            $sqlfu=mysqli_query($conn, "select * from t4 where ne='furun' and s1=".$_GET["id"]." order by id desc"); while($rsfu=mysqli_fetch_assoc($sqlfu)){
            $sqlu=mysqli_query($conn, "select * from ".$_SESSION["lang"]." where id=".$rsfu["s2"].""); $rsu=mysqli_fetch_assoc($sqlu);
			$sqlv=mysqli_query($conn, "select * from genel where id=".$rsfu["s6"].""); $rsv=mysqli_fetch_assoc($sqlv);
			$jsi = json_decode($rsfu["n17"], true);
            if(mysqli_num_rows($sqlu)>0){
				$id=$rsu["id"]; include("../../../deppo/tools/script/prices.php");
				$uAdi=$rsu["t1"];
				$uKod=$rsu["t4"];
			}else{
				$uAdi=$rsfu["n1"];
				$uKod="U0000000";
			}
            ?>
              <!----------------------------------------------/uSatır/--->
              <tr>
               <td><?php echo $uKod?><?php if($rsu["t5"]<>""){echo "<br>".$rsu["t5"];}?></td>
               <td><?php echo $uAdi?><?php if(mysqli_num_rows($sqlv)>0){echo " {".$rsv["t1"]."}";}?>
<?php $sqli=mysqli_query($conn, "select * from genel where ne='inputs' and (t2='All' or t2='".$_SESSION["lang"]."') and n3='kayit' and n4<>'switch' and (n2='0' or n2='".$rsu["id"]."') and n6='required' and s1=0 order by s10,id asc");?>
<?php if(mysqli_num_rows($sqli)>0){?>
<div style="font-size:12px;">
					<?php $i=0; while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
<?php if($rsi["n4"]=="input" or $rsi["n4"]=="textarea"){?>
<?php if($jsi["i".$i.""]<>""){?>	<b><?php echo $rsi["n1"];?></b> : <?php echo $jsi["i".$i.""];?><?php }?>
<?php }else{?>
<?php if($jsi["i".$i.""][0]<>""){?>	<b><?php echo $rsi["n1"];?></b> : <?php echo $jsi["i".$i.""][0];?><?php }?>
<?php }?>
					<?php }?>
</div>
<?php }?>
			   </td>
               <td><?php echo $rsfu["s5"]?> <?php echo $rsfu["t10"];?></td>
               <td style="text-align:right;"><?php echo wprice($rsfu["pb1"])?>&nbsp;<i class="fa fa-<?php echo strtolower($rsfu["t10"]);?>"></i></td>
               <td style="text-align:right;"><?php echo wprice($rsfu["pb1"]*$rsfu["s5"])?>&nbsp;<?php echo strtolower($rsfu["t10"]);?></td>
           </tr>
       <?php }?>
   </table>
</div>
<div class="fyaziile"><?php echo yaziile(str_replace(",","",number_format(($gtotal),2)),2,"Türk Lirası","Krş","#");?></div>
<div class="ftoplam">
	<ul>
       <li style="text-align:right;"><span><?php echo $sdil[175]; //Ara Toplam?></span> : <?php echo wprice(($stotal))?> <?php echo $ikpb?></li>
       <li style="text-align:right;"><span><?php echo $sdil[102]; //Sale?></span> : <?php echo wprice($stotal-$total)?> <?php echo $ikpb?></li>
       <li style="text-align:right;"><span><?php echo $sdil[159]; //Balance?></span> : <?php echo wprice(($total))?> <?php echo $ikpb?></li>
       <?php if(!empty($kdvbir)){?><li style="text-align:right;"><span><?php echo $sdil[86]; //Tax?> 1%</span> : <?php echo wprice(($kdvbir))?> <?php echo $ikpb?></li><?php }?>
       <?php if(!empty($kdvsekiz)){?><li style="text-align:right;"><span><?php echo $sdil[86]; //Tax?> 8%</span> : <?php echo wprice(($kdvsekiz))?> <?php echo $ikpb?></li><?php }?>
       <?php if(!empty($kdvonsekiz)){?><li style="text-align:right;"><span><?php echo $sdil[86]; //Tax?> 18%</span> : <?php echo wprice(($kdvonsekiz))?> <?php echo $ikpb?></li><?php }?>
       <?php if(!empty($kdvdiger)){?><li style="text-align:right;"><span><?php echo $sdil[86]; //Tax?> </span> : <?php echo wprice(($kdvdiger))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <li style="text-align:right;"><span><?php echo $sdil[176]; //Toplam?></span> : <?php echo wprice(($gtotal))?> <?php echo $ikpb?></li>
   </ul>
</div>
</div>