<?php
$path="../../"; include("../../map.php");
header('Content-Type: text/html; charset=utf-8');
if($_REQUEST["id"]<>""){
	$sqlf=mysqli_query($conn, "select * from t4 where id=".$_GET["id"].""); $rsf=mysqli_fetch_assoc($sqlf); $jsi = json_decode($rsf["n17"], true);
}
if($jsi["isablon"]<>""){
	$sql_temp=mysqli_query($conn, "select * from genel where id='".$jsi["isablon"]."'"); $rs_temp=mysqli_fetch_assoc($sql_temp);
}
if($_POST["tmpID"]<>""){
	$sql_temp=mysqli_query($conn, "select * from genel where id='".$_POST["tmpID"]."'"); $rs_temp=mysqli_fetch_assoc($sql_temp);
}
if($_POST){
	//header("Content-type: application/vnd.ms-word");
	//header("Content-Disposition: attachment; Filename=sozlesme_".date("YmdHis").".doc");
}else{
	include("../../scripts.php");
}
function get_info($metin="",$User_ID=""){
	global $module; global $firm; global $conn;
	if($metin<>""){
		$sql_client=mysqli_query($conn, "select id,t1,t2,t4,n5,n17 from t5 where id=".$User_ID.""); $rsc=mysqli_fetch_assoc($sql_client);  $jsic = json_decode($rsc["n17"], true);
		$firma	= srep($firm["firma"]);
		$fadres	= srep($firm["fadres"]);
		$metin 	= str_replace("{firma}", $firm["firma"], $metin);
		$metin 	= str_replace("{fresmi}", $firm["firma_resmi"], $metin);
		$metin 	= str_replace("{fyetkili}", $firm["firma_yetkili"], $metin);
		$metin 	= str_replace("{fadres}", $firm["fadres"], $metin);
		$metin 	= str_replace("{tarih}", date("d/m/Y"), $metin);
		$metin 	= str_replace("{date}", date("d/m/Y"), $metin);
		$metin 	= str_replace("{starih}", date("d/m/Y"), $metin);
		$metin 	= str_replace("{fiyat}", $_POST["fiyat"], $metin);
		$metin 	= str_replace("{price}", $_POST["fiyat"], $metin);
		$metin 	= str_replace("{sure}", $_POST["sure"], $metin);
		$metin 	= str_replace("{time}", $_POST["sure"], $metin);
		$metin 	= str_replace("{ssure}", $_POST["sure"], $metin);
		$metin 	= str_replace("{temrin}", $_POST["temrin"], $metin);
		$metin 	= str_replace("{deadline}", $_POST["temrin"], $metin);
		$metin 	= str_replace("{psure}", $_POST["temrin"], $metin);
		$metin 	= str_replace("{konu}", $_POST["konu"], $metin);
		$metin 	= str_replace("{subject}", $_POST["konu"], $metin);
		$metin 	= str_replace("{sicerik}", $_POST["konu"], $metin);
		if(mysqli_num_rows($sql_client)>0){
			$metin = str_replace("{madres}", $rsc["n5"], $metin);
			if($jsic["ifirma"]<>""){
				$metin = str_replace("{Ad_Soyad}", $jsic["ifirma"], $metin);
				$metin = str_replace("{misim}", $jsic["ifirma"], $metin);
			}else{
				$metin = str_replace("{Ad_Soyad}", $rsc["t1"], $metin);
				$metin = str_replace("{misim}", $jsic["ifirma"], $metin);
			}
		}	
	}else{
		$metin="Sözleşme metni bulunamadı!";
	}
	return $metin;
}
$tax_text = "+ Kdv"; // Varsayılan olarak KDV hariç
if (!empty($jsi["ikdv1"]) || !empty($jsi["ikdv8"]) || !empty($jsi["ikdv18"]) || !empty($jsi["ikdv20"]) || !empty($jsi["ikdvdiger"])) {
    $tax_text = ""; // KDV varsa metni boş bırak
	$periodic = $jsi["iperiodic_with_qty_tax"];
	$subtotal = sprice($jsi["isubtotal"]) + sprice($periodic) + sprice($jsi["ikdv1"]) + sprice($jsi["ikdv8"]) + sprice($jsi["ikdv18"]) + sprice($jsi["ikdv20"]) + sprice($jsi["ikdvdiger"]);
}else{
	$periodic = $jsi["iperiodic"];
	$subtotal = sprice($jsi["isubtotal"]) + sprice($periodic);
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
	body {font-family:arial; font-size:12px}
	table {border:0px solid #fff;}
	table tr {border:0px solid #fff;}
	table tr td {padding:10px; border:0px solid #fff;}
	img {height:65px;}
	.note-editable { height: 300px !important; }
	.skiptranslate {visibility:hidden !important;}
	.btn-group>.btn-group:last-child>.btn:first-child {height: 20px;}
</style>
<title><?php echo ctranslate("Sözleşme")?></title>
<?php if(!$_POST){ ?>
<div class="v3-container" style="margin-top:15px;">
<form class="no-print" method="post" action="?<?php if($_REQUEST["id"]<>""){echo "id=".$_REQUEST["id"]."";}?>" target="_blank">
	<div class="v3-row">
		<div class="v3-col-xs-4">
			<input type="text" name="fiyat" class="v3-form-control" value="<?php if (!empty($subtotal)){ echo wprice($subtotal) . " " . $kpb . " ".$tax_text.""; } else { echo "0.00 " . $kpb . " ".$tax_text.""; }?>" placeholder="0.00 <?php echo $kpb;?>" style="margin-bottom: 5px;">
		</div>
		<div class="v3-col-xs-4">
			<input type="text" name="temrin" class="v3-form-control" value="15 Gün" placeholder="x Gün" style="margin-bottom: 5px;">
		</div>
		<div class="v3-col-xs-4">
			<input type="text" name="sure" class="v3-form-control" value="1 Yıl" placeholder="x Yıl" style="margin-bottom: 5px;">
		</div>
		<div class="v3-col-xs-12">
			<textarea name="konu" class="v3-form-control summernote" placeholder="Konu" style="margin-bottom: 5px;"></textarea>
		</div>
		<div class="v3-col-xs-5">
			<select name="tmpID" data-placeholder="Seçiniz" style="" class="form-control" tabindex="8" style="margin-bottom: 5px;">
				<option value="0">Sözleşme Seçiniz</option>
				<?php $sqls=mysqli_query($conn, "select * from genel where ne='sablon' order by id desc"); while($rss=mysqli_fetch_assoc($sqls)){ ?>
					<option value="<?php echo $rss["id"];?>" <?php if ($rss["id"]==$jsi["isablon"]){?>Selected<?php }?>><?php echo $rss["t1"];?></option>
				<?php }?>
			</select>
		</div>
		<div class="v3-col-xs-5">
			<select name="User_ID" data-placeholder="Seçiniz" style="" class="form-control" tabindex="8" style="margin-bottom: 5px;">
				<option value="0">Hesap Seçiniz</option>
				<?php $sql=mysqli_query($conn, "select * from t5"); while($rsm=mysqli_fetch_assoc($sql)){?>
					<option value="<?php echo $rsm["id"];?>" title="<?php echo $rsm["t1"];?> {<?php echo v3d($rsm["t2"]);?>}" style="color:#6699FF" <?php if ($rsm["id"]==$rsf["s1"]) {?>Selected<?php }?>><?php echo $rsm["t1"];?></option>
				<?php }?>
			</select>
		</div>
		<div class="v3-col-xs-2">
			<select name="lang" data-placeholder="Seçiniz" style="" class="form-control" tabindex="8" style="margin-bottom: 5px;">
				<option value="">Tr</option>
				<option value="tr|en">Tr-En</option>
				<option value="tr|ar">Tr-Ar</option>
			</select>
		</div>
		<div class="v3-col-xs-12" style="margin-top:15px;">
			<button type="submit" class="v3-btn v3-btn-warning" style="float:right">Oluştur</button>
		</div>
	</div>
</form>
<p>* Tüm kalemler eklendi, kdv durumu forma göre düzenlendi</p>
</div>
<script>
	jQuery(document).ready(function() {
	  jQuery('.summernote').summernote();
	});
</script>
<?php echo $footer;?>
<?php }else{?>
<div class="" style="padding:15px;">
<table style="font-size:12px !important;">
	<tr>
		<td class="notranslate"><?php echo get_info($rs_temp["n8"],$_REQUEST["User_ID"]);?></td>
		<?php if($_POST["lang"]<>""){?>
		<script src="//code.jquery.com/jquery-latest.js" type="text/javascript"></script>
		<?php include("../../../deppo/tools/script/translate.php");?>
		<script>
			jQuery(document).ready(function(){
				Translate('<?php echo $_POST["lang"]?>');return false;
			});
		</script>
		<td><?php echo get_info($rs_temp["n8"],$_REQUEST["User_ID"]);?></td>
		<?php }?>
	</tr>
</table>	
</div>
<?php }?>