<?php
	$path="../../";
	include("../../map.php");
	$sqlt=mysqli_query($conn, "select * from genel where ne='sftasarim'"); $rst=mysqli_fetch_assoc($sqlt);
	if(mysqli_num_rows($sqlt)==0){
		$sqli = $conn->query("insert into genel (ne) values ('sftasarim')");
	}
	if($_GET["view"]<>""){
		$sql = mysqli_query($conn, "update t4 set s13='2', t11=now() where (id=".$_GET["id"]." or t1='".$_GET["id"]."')");
	}
	
	$fcadres = explode(',',$rst["n1"]);
	$ftarih = explode(',',$rst["n2"]);
	$furunler = explode(',',$rst["n3"]);
	$ftoplam = explode(',',$rst["n4"]);
	$fdetay = explode(',',$rst["n5"]);
	$flogo = explode(',',$rst["n6"]);
	$fsart = explode(',',$rst["n7"]);
	$filetisim = explode(',',$rst["n8"]);
?>
<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">
<script>
function hide(id){var divObject=document.getElementById(id); divObject.style.display="none";}
function show(id){var divObject=document.getElementById(id); divObject.style.display="block";}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php if($MSA<>1){?>
<!--<body onload="window.print()">-->
<?php }?>
<?php if($_GET["edit"]<>"" and $MSA==1){?>
        <form id="sform" class="noprint" action="?id=<?php echo $_GET["id"]?>&islem=<?php echo $_GET["islem"]?>&durum=tkaydet" method="post" style="display:none;position:fixed; right:0px; top:30px; width:100px;" class="noprint">
           <input type="text" name="t1" value="<?php echo $rst["t1"]?>" Placeholder="td1" style="width:100px">
           <input type="text" name="t2" value="<?php echo $rst["t2"]?>" Placeholder="td2" style="width:100px">
           <input type="text" name="t3" value="<?php echo $rst["t3"]?>" Placeholder="td3" style="width:100px">
           <input type="text" name="t4" value="<?php echo $rst["t4"]?>" Placeholder="td4" style="width:100px">
           <input type="text" name="t5" value="<?php echo $rst["t5"]?>" Placeholder="td5" style="width:100px">
           <input type="text" name="t6" value="<?php echo $rst["t6"]?>" Placeholder="td6" style="width:100px">
           <input type="text" name="t7" value="<?php echo $rst["t7"]?>" Placeholder="td7" style="width:100px">
           <input type="submit" name="" value="Kaydet" style="display:none;">
       </form>
		<i class="fa fa-caret-left" id="fa-caret-left" style="position:fixed; right:0px; top:30px; font-size:30px;" onclick="show('sform');hide('fa-caret-left');"></i>
<?php }?>
   <style type="text/css">
	del{
		font-size:13px;
		color:darkgrey;
	}
   body {text-align: -webkit-center; padding:0px; margin:0px; font-size:<?php echo $fsize?>px; font-family:arial; background-image:url('../../assets/img/<?php if($_GET["edit"]<>"" and $MSA==1){?>fatura.jpg<?php }?>');}
<?php if($_GET["edit"]<>"" and $MSA==1){?>
   .fatura{text-align: left;position:relative; width:210mm; height:297mm; padding:0px; margin:0px;cursor:pointer; border:dashed 1px #ccc;}
   .fadres:hover, .ftarih:hover, .fvd:hover, .fvn:hover, .furunler:hover, .ftoplam:hover, .fdetay:hover, .flogo:hover, .fsart:hover, .filetisim:hover{ cursor:move; background: rgba(255, 255, 0, 0.5); border-top: 1px solid #d0d0d0; }
<?php }else{?>
   .fatura{text-align: left;border:solid 0px #ff3333; position:relative; width:210mm; height:297mm; padding:0px; margin:0px;margin-top:15px}
<?php }?>
   .fadres {
    <?php if($rst["n1"]==""){?>
       position: absolute; left: 16px; top: 139px; width: 360px; height: 92px;
   <?php }else{?>
       position:absolute; left:<?php echo $fcadres[0]?>px; top:<?php echo $fcadres[1]?>px; width:<?php echo $fcadres[2]?>px; height:<?php echo $fcadres[3]?>px;
   <?php }?>
}
.ftarih {
    <?php if($rst["n2"]==""){?>
	position: absolute; left: 718px; top: 149px; width: 153px; height: 25px;
   <?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 }?>
	text-align:right;
}
.fvd {position:absolute; left:20px; width:150px;}
.fvn {position:absolute; left:20px; width:150px;}
.furunler {
    <?php if($rst["n3"]==""){?>
	position: absolute; left: 12px; top: 426px; width: 866px; height: 254px;
   <?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"];}?>;}
.turunler tr td:nth-child(6) {width:<?php if($rst["t6"]==""){echo "40";}else{echo $rst["t6"];}?>;}
.turunler tr td:nth-child(7) {width:<?php if($rst["t7"]==""){echo "40";}else{echo $rst["t7"];}?>;}
.turunler tr td{border-bottom: solid 1px #ccc !important; height:32px;}
.ftoplam {
    <?php if($rst["n4"]==""){?>
       position: absolute; left: 586px; top: 712px; width: 222px; height: 84px;
   <?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;}
.fdetay {
    <?php if($rst["n5"]==""){?>
       position: absolute; left: 13px; top: 244px; width: 867px; height: 158px;
   <?php }else{?>
       position:absolute; left:<?php echo $fdetay[0]?>px; top:<?php echo $fdetay[1]?>px; width:<?php echo $fdetay[2]?>px; height:<?php echo $fdetay[3]?>px;
   <?php }?>
}
.flogo {
    <?php if($rst["n6"]==""){?>
       position: absolute; left: 15px; top: 12px; width: 287px; height: 107px;
   <?php }else{?>
       position:absolute; left:<?php echo $flogo[0]?>px; top:<?php echo $flogo[1]?>px; width:<?php echo $flogo[2]?>px; height:<?php echo $flogo[3]?>px;
   <?php }?>
}
.filetisim {
    <?php if($rst["n8"]==""){?>
       position: absolute; left: 591px; top: 26px; width: 287px; height: 107px;
   <?php }else{?>
       position:absolute; left:<?php echo $filetisim[0]?>px; top:<?php echo $filetisim[1]?>px; width:<?php echo $filetisim[2]?>px; height:<?php echo $filetisim[3]?>px;
   <?php }?>
}
.fsart {
    <?php if($rst["n7"]==""){?>
       position: absolute; left: 14px; top: 727px; width: 548px; height: 72px;
   <?php }else{?>
       position:absolute; left:<?php echo $fsart[0]?>px; top:<?php echo $fsart[1]?>px; width:<?php echo $fsart[2]?>px; height:<?php echo $fsart[3]?>px;
   <?php }?>
}
ul {list-style:none; padding: 0px; margin: 0px;}
ul li span {width:110px; float: left;}
</style>
<script>
    jQuery(function(){
        <?php if($_GET["edit"]<>"" and $MSA==1){?>
           jQuery('.fadres, .fvd, .fvn, .ftarih, .furunler, .ftoplam, .fkdv, .fgtoplam, .fdetay, .fsart, .flogo, .filetisim') .draggable() .resizable();
       <?php }?>
       jQuery('.fatura').click(function(){
          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=sftasarim'
         });
          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=sftasarim'
         });
          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=sftasarim'
         });
          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=sftasarim'
         });
          var d5p = jQuery('.fdetay').position();
          var d5h = jQuery('.fdetay').height();
          var d5w = jQuery('.fdetay').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=sftasarim'
         });
          var d6p = jQuery('.flogo').position();
          var d6h = jQuery('.flogo').height();
          var d6w = jQuery('.flogo').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=sftasarim'
         });
          var d7p = jQuery('.fsart').position();
          var d7h = jQuery('.fsart').height();
          var d7w = jQuery('.fsart').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=sftasarim'
         });
          var d8p = jQuery('.filetisim').position();
          var d8h = jQuery('.filetisim').height();
          var d8w = jQuery('.filetisim').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=sftasarim'
         });
          return false;
      });
   });
</script>
<?php
//-------------------/Fatura Düzenle/-------
if($_GET["id"]<>""){
	$sqlf=mysqli_query($conn, "select * from t4 where (id=".$_GET["id"]." or t1='".$_GET["id"]."')"); $rsf=mysqli_fetch_assoc($sqlf); $jsi = json_decode($rsf["n17"], true); $jsm = json_decode($rsf["m1"], true);
	$ftarih="".$rsf["s4"]."-".$rsf["s3"]."-".$rsf["s2"].""; $fno=$rsf["t1"]; $t4=$rsf["t4"];
	$sqlm=mysqli_query($conn, "select * from t5 where id=".$rsf["s1"].""); $rs5=mysqli_fetch_assoc($sqlm); $jsfi = json_decode($rs5["n17"], true);
	$fcariID=$rsf["s1"]; $fcariName=$rs5["t1"]; $fcariEmail=v3d($rs5["t2"]);
	$sql_temp=mysqli_query($conn, "select * from genel where id='".$jsi["isablon"]."'"); $rs_temp=mysqli_fetch_assoc($sql_temp);
	include("../accounting/accounting_calc.php");
}
//-------------------/Fatura Düzenle/-------
?>
<title><?php echo $rsf["n2"]?> <?php echo ctranslate("Teklif")?></title>
<div class="fatura">
<div style="position: absolute; font-size: 200px; color: #cccccc1f; transform: rotate(-40deg); top: 15%; left: 15%;"><?php echo ctranslate("TEKLİF")?></div>
<?php if(mysqli_num_rows($sql_temp)>0){?>
    <div class="flogo"><img src="<?php echo medya($rs_temp["id"],1,"resim","t1","", $weburl)?>" style="max-height:80px;"></div>
<?php }else{?>
    <div class="flogo"><img src="<?php echo $logo;?>" style="max-height:80px;"></div>
<?php }?>
    <div class="filetisim">
        <b><?php echo $firma?></b><br>
        <?php echo $fadres?><br>
        <?php echo $ftel?><br>
        <?php echo $fmail?><br>
    </div>
    <div class="fadres">
        <?php echo ctranslate("Sayın")?>; <b><?php echo $rs5["t1"]?></b><?php if($rs5["i1"]<>""){echo "<br>".$rs5["i1"];}?><br /><?php echo $rs5["n5"]?>
        <br>Email :<?php echo v3d($rs5["t2"])?><br><?php echo ctranslate("Telefon")?> :<?php echo $rs5["t4"]?>
    </div>
    <div class="ftarih"><?php echo dtarih($rsf["t9"],"gg.aa.yyyy");?></div>
    <div class="furunler">
        <table class="turunler" style="width:100%">
            <tr>
               <td><?php echo ctranslate("Kodu");?></td>
               <td><?php echo ctranslate("Adı");?></td>
               <td><?php echo ctranslate("Birim");?></td>
               <td class="htax" style="text-align:right;"><?php echo ctranslate("Kdv");?></td>
               <td style="text-align:right;"><?php echo ctranslate("Fiyat");?></td>
               <td style="text-align:right;"><?php echo ctranslate("Tutar");?></td>
           </tr>
           <?php $aylik=0;
           $sqlfu=mysqli_query($conn, "select * from t4 where ne='furun' and s1=".$rsf["id"].""); while($rsfu=mysqli_fetch_assoc($sqlfu)){$jsui = json_decode($rsfu["n17"], true);
            $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);
			if(mysqli_num_rows($sqlu)>0){
				$uAdi=$rsu["t1"];
				$uKod=$rsu["t4"];
			}else{
				$uAdi=$rsfu["n1"];
				$uKod="U0000000";
			}
			if($rsfu["pb3"]<>0){
				$discount=($discount+(($rsfu["pb3"]-$rsfu["pb1"])*$rsfu["s5"]));
				$tsf=($tsf+($rsfu["pb3"]));
			}
          ?>
          <!----------------------------------------------/uSatır/--->
          <tr>
           <td><?php echo $uKod?></td>
           <td><?php echo $uAdi?><?php if(mysqli_num_rows($sqlv)>0){echo " {".$rsv["t1"]."}";}?><br><span style="font-size:10px"><?php echo $rsfu["n2"]?></span>
			<?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($jsui["i".$i.""]<>""){?>	<b><?php echo $rsi["n1"];?></b> : <?php echo $jsui["i".$i.""];?><?php }?>
					<?php }else{?>
					<?php if($jsui["i".$i.""][0]<>""){?>	<b><?php echo $rsi["n1"];?></b> : <?php echo $jsui["i".$i.""][0];?><?php }?>
					<?php }?>
					<?php }?>
				</div>
			<?php }?>
			</td>
           <td><?php echo $rsfu["s5"]?> <?php echo $rsfu["t10"];?></td>
           <td  class="htax" style="text-align:right;"><?php if($rsfu["s4"]>0){?>%<?php echo $rsfu["s4"]?><?php }else{?>-<?php }?></td>
           <td style="text-align:right;"><?php if($rsfu["pb3"]<>0){?><span style="font-size:12px;"><?php if($jsfi["ictip"]=="kurumsal"){echo "".wprice($rsfu["pb3"])." *tsf";}else{echo "<del>".wprice($rsfu["pb3"])."</del>";}?></span><br><?php }?><?php echo wprice($rsfu["pb1"])?>&nbsp;<i class="fa fa-<?php echo strtolower($rsfu["t2"]);?>"></i></td>
           <td style="text-align:right;"><?php echo wprice($rsfu["pb1"]*$rsfu["s5"])?>&nbsp;<i class="fa fa-<?php echo strtolower($rsfu["t2"]);?>"></i></td>
       </tr>
   <?php $kpb=$rsfu["t2"];}?>
</table>
</div>
<div class="ftoplam">
	<ul style="width:100%">
<?php if($discount>0){?>
       <li style="text-align:right;"><span><?php if($jsfi["ictip"]=="kurumsal"){echo ctranslate("tsf")." ";}?><?php echo ctranslate("Toplam");?></span> : <?php echo wprice($stotal+$discount)?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li>
<?php }else{?>
       <li style="text-align:right;"><span><?php echo ctranslate("Toplam"); //Toplam?></span> : <?php echo wprice(($stotal))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li>
<?php }?>
<?php if($rsf["pb4"]>0 and ($jsfi["ictip"]=="bireysel" or $jsfi["ictip"]=="")){?>
       <li style="text-align:right;"><span><?php echo ctranslate("İndirim"); //Toplam?></span> : <?php echo wprice($stotal-$total)?> <i class="fa fa-<?php echo strtolower($rsf["t5"])?>"></i></li>
<?php }elseif($discount>0 and ($jsfi["ictip"]=="bireysel" or $jsfi["ictip"]=="")){?>
       <li style="text-align:right;"><span><?php echo ctranslate("İndirim"); //Toplam?></span> : <?php echo wprice($discount)?> <i class="fa fa-<?php echo strtolower($rsf["t5"])?>"></i></li>
<?php }?>
       <li style="text-align:right;"><span><?php echo ctranslate("Ara Toplam")?></span> : <?php echo wprice(($total))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li>
       <?php if(!empty($kdv1)){?><li class="htax" style="text-align:right;"><span><?php echo ctranslate("Kdv")?> 1%</span> : <?php echo wprice(($kdv1))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <?php if(!empty($kdv8)){?><li class="htax" style="text-align:right;"><span><?php echo ctranslate("Kdv")?> 8%</span> : <?php echo wprice(($kdv8))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <?php if(!empty($kdv18)){?><li class="htax" style="text-align:right;"><span><?php echo ctranslate("Kdv")?> 18%</span> : <?php echo wprice(($kdv18))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <?php if(!empty($kdv20)){?><li class="htax" style="text-align:right;"><span><?php echo ctranslate("Kdv")?> 20%</span> : <?php echo wprice(($kdv20))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <?php if(!empty($kdvdiger)){?><li class="htax" style="text-align:right;"><span><?php echo ctranslate("Kdv")?> </span> : <?php echo wprice(($kdvdiger))?> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li><?php }?>
       <li style="text-align:right;"><span><?php echo ctranslate("Genel Toplam")?></span> : <b><?php echo wprice(($gtotal))?></b> <i class="fa fa-<?php echo strtolower($kpb)?>"></i></li>
   </ul>
</div>
<div class="fsart">
* <?php echo translate("Bu teklif");?>, <b><?php echo dtarih($rsf["t10"],"gg ua yyyy");?></b> <?php echo translate("tarihine kadar geçerlidir.");?> <?php if($rsf["t7"]>0){?><br><?php echo translate("Depozito")?>; <b><?php echo wprice($rsf["t7"]);?></b> <i class="fa fa-<?php echo strtolower($kpb)?>"></i><?php }?><?php if($rsf["t2"]<>""){?><br><?php echo $sdil[154]; //Ödeme Tipi?>; <b><?php echo translate($rsf["t2"])?></b><?php }?>
<?php if($jsfi["ictip"]=="kurumsal"){echo "<p style=\"font-size:12px\"><b>*tsf</b> Tavsiye edilen satış fiyatı</p>";}?>
<?php if (empty($kdv1) && empty($kdv8) && empty($kdv18) && empty($kdv20) && empty($kdvdiger)) {echo "<br>* Fiyatlara KDV dahil değildir.";}?>
<?php if($jsi["iperiodic_daily"]>0 || $jsi["iperiodic_monthly"]>0 || $jsi["iperiodic_yearly"]>0){echo "<br>* <b>".wprice($jsi["iperiodic_daily"]+$jsi["iperiodic_monthly"]+$jsi["iperiodic_yearly"])."</b> periyodik ödeme mevcuttur.";}?>
<table class="noshadow tbl2" style="width:100%;">
	<?php $i=0;$sqli=mysqli_query($conn, "select * from genel where ne='senet' and s2=".$rsf["id"]." order by id desc"); while($rsi=mysqli_fetch_assoc($sqli)){$i++;?>
	<tr>
		<td style="vertical-align: top;" class="tar"><?php echo $i;?>.<?php echo translate("Taksit")?> <?php echo $rsi["t10"]?> - <?php echo $ikpb?> <?php echo wprice($rsi["pb1"])?></td>
	</tr>
	<?php }?>
</table>
</div>
<div class="fdetay"><?php echo $rsf["n1"]?></div>
</div>
<?php
if($_GET["durum"]=="tkaydet"){
	$Rs = mysqli_query($conn, "update genel set t1='".$_POST["t1"]."', t2='".$_POST["t2"]."', t3='".$_POST["t3"]."', t4='".$_POST["t4"]."', t5='".$_POST["t5"]."', t6='".$_POST["t6"]."', t7='".$_POST["t7"]."' where ne='sftasarim'");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."",self,500,1);
}
?>