<?php
	header('Content-Type: text/html; charset=utf-8');
	error_reporting(0);
	$path="../../";
	include("../../map.php");
	include("../../scripts.php");
	include("../../secure.php");
	//findDirectoryPath("deppo")
//-------------------/Fatura Düzenle/-------
if($_GET["id"]<>""){
	$sqlf=mysqli_query($conn, "select * from t4 where id=".$_GET["id"].""); $rsf=mysqli_fetch_assoc($sqlf);
	$notify = array ('desktop' => '1','browser' => '1','nbrowser' => '1');
	$rjsn = json_encode($notify, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$Rs = mysqli_query($conn, "update t4 set n12='".addslashes(stripslashes($rjsn))."' where id=".$_GET["id"].""); $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);
	$fcariID=$rsf["s1"]; $fcariGsm=$rs5["t4"]; $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/-------
?>
    <div class="qmodal">
        <div class="qmodal-content">
            <!-- Header with Action Buttons -->
            <div class="qmodal-header">
				<div class="header-title">
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php echo $weburl?>" target="_blank"><i class="fa fa-home"></i></a></li>
                            <li class="breadcrumb-item"><a href="#"><?php echo $sdil[23]; //Muhasebe?></a></li>
                            <li class="breadcrumb-item active" aria-current="page"><?php echo $t36; //Servis?></li>
                        </ol>
                    </nav>
                </div>
                <button type="button" class="btn btn-warning" onclick="AjaxKaydet('','');"><i class="fas fa-save"></i> Kaydet</button>
				<?php if($_GET["id"]<>"" and $rsf["t4"]=="delivery"){?><button type="button" class="btn btn-default" href="../print/print_waybill<?php if($module["muhasebe_fatura_type"]=="2"){echo "_gb";}?>.php?id=<?php echo $_GET["id"]?>&islem=<?php echo $_GET["islem"]?>" target="_blank"><i class="fa fa-truck"></i></button><?php }?>
					<!--
						<a href="#" class="card-action card-action-toggle" data-card-toggle=""></a>
						<a href="#" class="card-action card-action-dismiss" data-card-dismiss=""></a>
					-->
				<?php if($jsi["isablon"]<>0 and $fcariID<>""){?>
					<button type="button" class="btn btn-success mfrm" style="color:white;" data-toggle="modal" data-target="#myModal" data-url="../public/agreement.php?id=<?php echo $_GET["id"];?>"><strong><i class="fa fa-file" aria-hidden="true"></i> <?php echo translate("Sözleşme")?></strong></button>
				<?php }?>
					<button type="button" class="btn btn-success" style="color:white; cursor:pointer;" onclick="copyToClipboard('#link')"><i class="fa fa-copy"></i> <?php echo translate("Kopyala")?></button>
					<div class="dn" id="link"><?php echo $weburl."/offer/".$rsf["t1"];?></div>
				<?php if(file_exists("../../../deppo/dosya/offer_".$rsf["t1"].".pdf")){?>
					<button type="button" class="btn btn-success" style="color:white;" href="../../../deppo/dosya/offer_<?echo $rsf["t1"]?>.pdf" target="_blank"><i class="fa fa-file-pdf-o"></i> <?php echo translate("Pdf")?></button>
					<button type="button" class="btn btn-danger" style="color:white;" onclick="location.href='?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=dpdf'"><i class="fa fa-file-pdf-o"></i> <?php echo translate("Pdf Sil")?> <i class="fa fa-trash" style="position: absolute; top: 0px;"></i></button>
				<?php }?>
					<button type="button" class="btn btn-success mfrm" onclick="location.href='#&tab-resim'" data-toggle="modal" data-target="#myModal" data-url="../upload/upload_image.php?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>"><i class="fa fa-picture-o" aria-hidden="true"></i> <i class="fa fa-plus" style="position: absolute; top: 0px;"></i></button>
					<button type="button" class="btn btn-warning mfrm" onclick="location.href='#&tab-dosya'" data-toggle="modal" data-target="#myModal" data-url="../upload/upload_file.php?ne=<?php echo $_GET["ne"];?>&islem=<?php echo $_GET["islem"];?>&id=<?php echo $_GET["id"]; ?>"><i class="fa fa-file-pdf-o" aria-hidden="true"></i> <i class="fa fa-plus" style="position: absolute; top: 0px;"></i></button>
					<button type="button" class="btn btn-info" onclick="window.open('../print/print_service<?php if($module["muhasebe_fatura_type"]=="2"){echo "_gb";}?>.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>')"><strong><i class="fa fa-print" aria-hidden="true"></i></strong></button>
					<button type="button" class="btn btn-info" onclick="if(confirm('#Teklif Gönderilecek! Onaylıyormusunuz?')) window.location.href='?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=pdf&s13=1';"><strong><i class="fa fa-envelope" aria-hidden="true"></i></strong></button>
					<button type="button" class="btn btn-danger" onclick="if(confirm('#Teklif Silinecek! Onaylıyormusunuz?')) window.location.href='?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>&durum=sservice';"><strong><i class="fa fa-times" aria-hidden="true"></i></strong></button>
					<div class="btn-group flex-wrap">
						<button data-toggle="dropdown" class="btn btn-warning" type="button" aria-expanded="false" style="padding: 12px; margin-left: 10px;">
							<i class="fa fa-ellipsis-v"></i>
						</button>
						<div class="dropdown-menu dropdown-menu-right" x-placement="top-end" style="">
							<?php if($rsf["t4"]=="" or $rsf["t4"]<>"order" and $rsf["t4"]<>"delivery" and $rsf["t4"]<>"invoice"){?>
								<a class="dropdown-item btn btn-warning" href="?ne=<?= $_GET["ne"] ?>&islem=<?= $_GET["islem"] ?>&id=<?= $_GET["id"] ?>&status=order">
									<i class="fas fa-store"></i> Siparişe Dönüştür
								</a>
							<?php } ?>
							<?php if($rsf["t4"]=="" or $rsf["t4"]<>"delivery" and $rsf["t4"]<>"invoice"){?>
								<a class="dropdown-item btn btn-success" href="?ne=<?= $_GET["ne"] ?>&islem=<?= $_GET["islem"] ?>&id=<?= $_GET["id"] ?>&status=delivery">
									<i class="fas fa-truck"></i> Sevkiyata Dönüştür
								</a>
							<?php } ?>
							<?php if($rsf["t4"]=="" or $rsf["t4"]<>"invoice"){?>
								<a class="dropdown-item btn btn-danger" href="?ne=<?= $_GET["ne"] ?>&islem=<?= $_GET["islem"] ?>&id=<?= $_GET["id"] ?>&status=invoice">
									<i class="fas fa-file-invoice"></i> Faturaya Dönüştür
								</a>
							<?php } ?>
						</div>
					</div>
				</div>
			<form class="form" id="asave" name="aform" method="post" action="?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"];?><?php if($_GET["id"]<>""){?>&durum=kaydet&id=<?php echo $_GET["id"]?><?php }else{?>&durum=yservice<?php }?>" autocomplete="off">
			<div class="alert alert-info sdn"></div>
			<div class="alert alert-warning sdn" id="err"></div>
			<?php if($_GET["id"]<>""){ ?>
				<input type="hidden" name="subtotal" value="<?php echo number_format($ntutar,2)?>">
				<input type="hidden" name="tax" value="<?php echo number_format($gtoplam-$ntutar,2)?>">
				<input type="hidden" name="total" value="<?php echo number_format($gtoplam,2)?>">
			<?php } //end if?>
            <!-- Left Tab Menu -->
            <div class="v8-columns">
							<div class="v8-col200pxL-left">
								<ul class="v8-side-tabs v8-js-tabs v8-same-height">
									<li><a href="#tab-detay"><i class="fa fa-file" aria-hidden="true"></i><span> <?php echo $t36s[0]?> <?php echo $sdil[207]; //Detay?></span></a></li>
									<?php if($g9==3 or $g9==4){?>
										<li><a href="#tab-seans"><i class="fa fa-list-ul" aria-hidden="true"></i><span> Seanslar</span></a></li>
									<?php }?>
									<li><a href="#tab-resim"><i class="fa fa-file-image-o" aria-hidden="true"></i><span> <?php echo $sdil[209]; //Resimler?></span></a></li>
									<li><a href="#tab-dosya"><i class="fa fa-file-archive-o" aria-hidden="true"></i><span> <?php echo $sdil[211]; //Dosyalar?></span></a></li>
									<?php if($rsf["t2"]=="Taksit"){?>
										<li><a href="?ne=muhasebe&islem=senet&id=<?php echo $rsf["id"]?>&uid=<?php echo $rsf["s1"]?>" target="_blank"><i class="fa fa-list-ul" aria-hidden="true"></i><span> <?php echo $sdil[227]; //Taksit?></span></a></li>
									<?php }?>
									<li><a href="#tab-plan"><i class="fa fa-calendar" aria-hidden="true"></i><span> <?php echo translate("Hesap Planı")?></span></a></li>
									<li class="ddn"><a href="#" onclick="show('switchs');window.scrollTo(0, 0);"><i class="fa fa-chevron-right" aria-hidden="true"></i></a></li>
								</ul>
								<div id="switchs">
									<div class="v3-alert v3-alert-warning ddn">
										<i class="fas fa-arrow-right" onclick="hide('switchs')"></i>
									</div>
									<fieldset class="side-by-side">
										<legend><?php echo translate("Teklif Durumu")?> <span style="font-size:8px; color:#ccc;">(s13)</span></legend>
										<select name="s13"  style="" class="form-control">
											<option value="0" <?php if($rsf["s13"]=="0"){echo "selected";}?>>Hazırlanıyor</option>
											<option value="1" <?php if($rsf["s13"]=="1"){echo "selected";}?>>Gönderildi</option>
											<option value="2" <?php if($rsf["s13"]=="2"){echo "selected";}?>>Okundu</option>
											<option value="3" <?php if($rsf["s13"]=="3"){echo "selected";}?>>Onaylandı</option>
											<option value="5" <?php if($rsf["s13"]=="5"){echo "selected";}?>>Tamamlandı</option>
											<option value="4" <?php if($rsf["s13"]=="4"){echo "selected";}?>>İptal</option>
										</select>
										<div style="font-size:11px; width:100%; text-align:right;"><?php if($rsf["t11"]<>""){echo $rsf["t11"];}else{echo translate("Henüz Kullanıcı Okumadı");}?></div>
									</fieldset>
									<fieldset class="side-by-side">
										<legend><?php echo translate("İşlem Sorumlusu")?> <span style="font-size:8px; color:#ccc;">(s19)</span></legend>
										<select size=1 name="s19[]" class="form-control chosen-select" tabindex="8" multiple>
                                            <option value="0" <?php echo ($rsf["s19"] == '0' || in_array('0', multivalues($rsf["s19"]))) ? 'selected' : '';?>>Admin</option>
                                            <?php $sql=mysqli_query($conn, "select s2,id,t1 from t5 where (s9=1 or s1=1) $luye"); while($rsm=mysqli_fetch_assoc($sql)){?>
                                                <option class="" value="<?php echo $rsm["id"];?>" title="<?php echo $rsm["t1"];?>" alt="<?php echo $rsm["t1"];?>" <?php echo in_array($rsm["id"], multivalues($rsf["s19"])) ? 'selected' : '';?>><?php echo $rsm["t1"];?></option>
                                            <?php }?>
                                        </select>
									</fieldset>
									<fieldset class="side-by-side">
										<legend><?php echo $sablonlar //sablonlar?> <span style="font-size:8px; color:#ccc;">(isablon)</span></legend>
										<select name="isablon" data-placeholder="Seçiniz" style="" class="form-control populate" data-plugin-selecttwo="" tabindex="8">
											<option value="0">...</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>
									</fieldset>
									<fieldset class="side-by-side">
										<legend><?php echo $t36s[0]?> <?php echo $sdil[168]; //Tip?> <span style="font-size:8px; color:#ccc;">(t4)</span></legend>
										<input type="text" list="lt2" name="t4" value="<?php if($rsf["t4"]==""){echo $t36s[0];}else{echo $rsf["t4"];};?>" style="" class="form-control">
										<datalist id="lt2" style="display:none;">
											<?php $sqlt=mysqli_query($conn, "select Distinct t4 FROM t4 where ne='service'"); while($tip=mysqli_fetch_assoc($sqlt)){?>
												<option value="<?php echo $tip["t4"];?>"><?php echo $tip["t4"];?></option>
											<?php }?>
										</datalist>
									</fieldset>
									<fieldset class="side-by-side e dn">
										<legend><?php echo translate("Aylık Bedelleri Göster")?> <span style="font-size:8px; color:#ccc;">(s5)</span></legend>
										<select name="s5"  class="form-control" tabindex="8">
											<option value="0" <?php if($rsf["s5"]=="0"){echo "Selected";};?>>Gizli</option>
											<option value="1" <?php if($rsf["s5"]=="1"){echo "Selected";};?>>Göster</option>
										</select>
									</fieldset>
									<fieldset class="side-by-side">
										<legend>Kurlar <span style="font-size:8px; color:#ccc;">(t3)</span></legend>
										<?php $rarr =  array ('usd' => $usd, 'eur' => $eur, 'gpb' => $gbp); $rate=json_encode($rarr);?>
										<input type="text" name="t3" class="form-control" style="width:100%;" value='<?php if($rsf["t3"]<>""){echo $rsf["t3"];}else{echo $rate;}?>' placeholder="Kur">
									</fieldset>
									</div>
								</div>
								<div class="v8-col200pxL-right" ts1="<?php echo dtarih($rsf["ts1"],"gg.ka.yy time");?>" ts2="<?php echo dtarih($rsf["ts2"],"gg.ka.yy time");?>" ts3="<?php echo dtarih($rsf["ts3"],"gg.ka.yy time");?>">
									<div id="tab-detay" class="v8-tabs-content" style="display: flow-root;">
										<div class="v3-row">
											<div class="v3-col-md-<?php if($_GET["id"]<>""){?>8<?php }else{?>12<?php }?>" style="padding:0px; ">
												<fieldset class="v3-col-md-12">
													<legend><?php echo $t36s[0]?> Konu <span style="font-size:8px; color:#ccc;">(n2)</span></legend>
													<input type="text" name="n2" class="form-control"  value="<?php echo $rsf["n2"];?>" placeholder="<?php echo $t36s[0]?> Açıklama">
												</fieldset>
												<fieldset class="v3-col-md-6" style="position:relative;">
													<legend><b><?php echo $t25s[0]; //Cari?> </b> <span style="font-size:8px; color:#ccc;">(s1)</span></legend>
													<?php if($fcariID<>""){?>
													<div style="position:absolute; right: 0px; top: -32px;">
														<i class="cp btn btn-info fa fa-eye fr p8 mp8  e mr5 mmr5 mfrm" data-toggle="modal" data-width="90%" data-target="#myModal" data-url="../clients/client.php?islem=duye&ne=uye&id=<?php echo $fcariID;?>" title="+90<?php echo $fcariGsm?>"></i>
														<i class="cp btn btn-info fa fa-envelope fr p8 mp8 mr5 mmr5 " onclick="window.open('?ne=cmail&islem=mailbox&mID=&alici=<?php echo v3d($rs5["t2"]);?>')" title="<?php echo v3d($rs5["t2"]);?>"></i>
														<i class="cp btn btn-info fa fa-cc fr p8 mp8 mr5 mmr5 " onclick="toggle('#cc');toggle('.v3-col-md-6 .select2');" title="cc"></i>
														<i class="cp btn btn-info fa fa-whatsapp fr p8 mp8 mr5 mmr5 " onclick="window.open('<?php echo $wlink;?>+90<?php echo telefon($fcariGsm)?>&text=Merhaba; teklifi malinize, bir kopyasınıda aşağıda size ilettik, aklınıza takılan bir konu olursa +90(532) 200 98 52 numaralı telefondan veya buradan iletişime geçebilirsiniz, incelediğinizde olumlu/olumsuz geri bildirimde bulunmanızı rica ederiz, iyi çalışmalar...')" title="+90<?php echo $fcariGsm?>"></i>
														<i class="cp btn btn-info fa fa-phone fr p8 mp8 mr5 mmr5 " onclick="location.href='tel:+90<?php echo telefon($fcariGsm)?>'" title="+90<?php echo $fcariGsm?>"></i>
													</div>
													<?php }?>
													<input type="text" name="t6" id="cc" value="<?php echo $rsf["t6"]?>" class="form-control" style="display:none;" placeholder="Cc Email">
													<select name="s1" id="s1" data-placeholder="Seçiniz" style="" class="form-control populate" data-plugin-selecttwo="" tabindex="8">
														<option value="0">Lütfen Seçiniz</option>
														<?php $sql5=mysqli_query($conn, "select * from t5 where ne<>'' $luye order by t1 asc"); while($rs5=mysqli_fetch_assoc($sql5)){?>
															<option value="<?php echo $rs5["id"];?>" title="<?php echo $rs5["t1"];?> {<?php echo v3d($rs5["t2"]);?>}" style="color:#6699FF" <?php if($rs5["id"]==$fcariID){?>Selected<?php }?>><?php echo $rs5["t1"];?></option>
														<?php }?>
													</select>
													<?php if($fcariID==""){?>
														<!--<a class="btn btn-success majx" style="color:white;position: absolute; top: -20px; right: 0px;" data-toggle="modal" data-target="#ajaxModal" data-url="../public/addform.php?islem=uye&id=<?php echo $_GET["id"]?>"><i class="fa fa-plus" aria-hidden="true"></i></a>-->
														<a class="cp btn btn-warning fa fa-plus fr p5 mp5" style="position:absolute;right: 0px; top: -25px; z-index: 99;" onclick="toggle('#addClient');toggle('#chooseClient')"></a>
														<div id="addClient" style="display:none;position: absolute; margin-top: -30px; background: white; width: 98%;">
															<div class="row">
																<div class="col-md-4">
																	<input type="text" name="ut1" class="form-control"  value="" placeholder="Ad Soyad">
																</div>
																<div class="col-md-4">
																	<input type="text" name="ut2" class="form-control"  value="" placeholder="Email">
																</div>
																<div class="col-md-4">
																	<input type="text" name="ut4" class="form-control"  value="" placeholder="Gsm" data-plugin-masked-input="" data-input-mask="<?php echo $module["pmask"];?>">
																</div>
															</div>
														</div>
													<?php }?>
												</fieldset>
												<fieldset class="v3-col-md-6">
													<legend><?php echo $t36s[0]?> No <span style="font-size:8px; color:#ccc;">(t1)</span></legend>
													<input type="text" name="t1" class="form-control"  value="<?php if($fno<>""){echo $fno;}else{echo date('YmdHis');}?>" placeholder="<?php echo $t36s[0]?> No">
												</fieldset>
												<fieldset class="v3-col-md-6">
													<legend><?php echo translate("Teklif Tarihi")?> <span style="font-size:8px; color:#ccc;">(t9)</span></legend>
													<input type="date" name="ts1" id="simple-calendar" class="form-control datepicker" value="<?php if($rsf["t9"]==""){ echo date('Y-m-d'); }else{ echo $rsf["t9"]; }?>" placeholder="Fatura Tarihi">
												</fieldset>
												<fieldset class="v3-col-md-6">
													<legend><?php echo translate("Geçerlilik Tarihi")?> <span style="font-size:8px; color:#ccc;">(t10)</span></legend>
													<input type="date" name="ts2" id="simple-calendar" class="form-control datepicker" value="<?php if($rsf["t10"]==""){ echo date('Y-m-d', strtotime(date("Y-m-d"). ' 15 days')); }else{ echo $rsf["t10"]; }?>" placeholder="Fatura Tarihi">
												</fieldset>
												<?php if($rsf["t4"]=="delivery"){?>
													<fieldset class="v3-col-md-12">
														<legend><?php echo $sdil[105]; //adres?> <span style="font-size:8px; color:#ccc;">(n7)</span></legend>
														<textarea name="n7" class="form-control" placeholder="<?php echo $sdil[105]; //adres?>"><?php echo $rsf["n7"];?></textarea>
													</fieldset>
												<?php }?>
											</div>
											<?php if($_GET["id"]<>""){?>
												<fieldset class="v3-col-md-4" style="height:327px !important;padding-top: 6px;">
													<legend><?php echo $sdil[176]; //Toplam?></legend>
													<script type="text/JavaScript" language="JavaScript">
														jQuery(document).ready(function () {
															jQuery("#show_total").load("../accounting/accounting_calc.php?show_total=yes&id=<?php echo $_GET["id"]?>&durum=<?php echo $_GET["durum"]?>");
														});
														document.write("<div id=\"show_total\"></div>");
													</script>
												</fieldset>
											<?php }?>
										<div class="v3-row">
											<div class="v3-col-md-12" id="inputs">
												<img src="../../assets/img/loading.gif">
												<a class="v3-btn v3-btn-xs v3-btn-default sam" style="" target="_blank" href="?ne=ayarlar&islem=inputs&nedir=<?php echo $_GET["ne"]?>&kid=<?php echo $_GET["id"]?>"><i class="fa fa-wrench" aria-hidden="true"></i></a>
											</div>
											<script type="text/JavaScript" language="JavaScript">
												jQuery(document).ready(function () { loadFunction('../ajax/ajax_inputs.php','#inputs'); });
											</script>
										</div>
									</div>
									<div class="">
										<div class="v3-row">
										<fieldset class="collapsed" style="min-height:auto !important;">
											<legend style="min-width:100px;" class="cp"><a style="float: left;"><i class="fas fa-edit"></i> <?php echo $sdil[207]; //Detay?></a> <span style="font-size:8px; color:#ccc; float:right">(n1)</span></legend>
											<textarea name="n1" class="rte" id="rte" style="width:100%; height:auto;" placeholder="<?php echo $t36s[0]?> Detay"><?php if($rsf["n1"]==""){echo $rs_temp["n1"];}else{echo $rsf["n1"];}?></textarea>
										</fieldset>
										</div>
									</div>
									</form>
									<?php if($_GET["id"]<>""){?>
									<div class="v3-row">
										<div class="">
										<script type="text/JavaScript" language="JavaScript">
											jQuery(document).ready(function () {
												loadFunction('../public/products.php?ne=<?php echo $_GET["ne"]?>&islem=<?php echo $_GET["islem"]?>&id=<?php echo $_GET["id"]?>','#products'); });
											document.write("<div id=\"products\" style=\"overflow:auto;\"></div>");
										</script>
									</div>
								</div>
									<?php }?>
								</div>
								<?php if($g9==3 or $g9==4){?>
									<div id="tab-seans" class="v8-tabs-content" style="display: flow-root;">
										<?php include("../services/seans.php");?>
									</div>
								<?php }?>
								<div id="tab-resim" class="v8-tabs-content" style="min-height:500px">
									<fieldset id="uploadarea" class="v3-row" style="">
										<legend><?php echo $sdil[209]; //Resimler?></legend>
										<script type="text/JavaScript" language="JavaScript">
											jQuery(document).ready(function () {
												loadFunction('../ajax/ajax_medya.php','#mresim', 'resim'); });
											document.write("<div id=\"mresim\" class=\"medias\" style=\"width:100%\"></div>");
										</script>
									</fieldset>
								</div>
								<div id="tab-dosya" class="v8-tabs-content" style="min-height:500px">
									<fieldset class="v3-row">
										<legend><?php echo $sdil[211]; //Dosyalar?></legend>
										<script type="text/JavaScript" language="JavaScript">
											jQuery(document).ready(function(){
												loadFunction('../ajax/ajax_medya.php','#mdosya', 'dosya');});
												document.write("<div id=\"mdosya\" class=\"medias\" style=\"width:100%\"></div>");
										</script>
									</fieldset>
								</div>
								<div id="tab-plan" class="v8-tabs-content" style="min-height:500px">
									<fieldset class="v3-row">
										<legend><?php echo translate("Hesap Planı")?></legend>
										<script type="text/JavaScript" language="JavaScript">
											jQuery(document).ready(function (){
												loadFunction('../clients/ajax_client_service.php?id=1','#ihizmet', '');
											});
											document.write("<div id=\"ihizmet\"></div>");
										</script>
									</fieldset>
								</div>
							</div>
                 </div>
            </div>
<?php echo $footer?>
<script>
	var html;
	setInterval(function() {
		if(jQuery('#plist').html() != html){
			check_table();
			html = jQuery('#plist').html();
		}
	}, 500);
	function check_table(){
		var rowCount = jQuery('#products form').length;
		if(rowCount==1){
			jQuery('.alert-info').html('<i class="fa fa-exclamation-triangle text-danger" aria-hidden="true"></i> Lütfen Ürün/Hizmet Ekleyin');
		} else {
			jQuery('.alert-info').html('<i class="fa fa-exclamation-triangle text-danger" aria-hidden="true"></i> Kaydetmeyi unutmayın');
		}
		return false;
	}
</script>
<?php 
$s19 = implode(',', array_map(function($value) {return "{".$value."}";}, $_POST["s19"]));
//--/Fatura Ekle/-------
if($_GET["durum"]=="yservice"){
	if($_POST["s1"]=="0"){
		$sql5k=mysqli_query($conn, "select * from t5 where t4='".$_POST["ut4"]."'"); $rs5k=mysqli_fetch_assoc($sql5k);
		if(mysqli_num_rows($sql5k)==0 and $_POST["ut4"]<>""){
			$sqli5 = $conn->query("insert into t5(t1, t2, ne, s1, s4, s5, s19, t3, t4, t9, ts1) values ('".$_POST["ut1"]."', '".base64_encode($_POST["ut2"])."', 'uye', '0', '1', '0', '".$_SESSION["user_id"]."', '".base64_encode(generatePassword(8))."', '".$_POST["ut4"]."', '".$_POST["ts1"]."', now())");	
			$sql5=mysqli_query($conn, "select * from t5 order by id desc"); $rs5=mysqli_fetch_assoc($sql5);
		}else{
			$sql5=mysqli_query($conn, "select * from t5 where t4='".$_POST["ut4"]."'"); $rs5=mysqli_fetch_assoc($sql5);
		}
	}else{
		$sql5=mysqli_query($conn, "select * from t5 where id='".$_POST["s1"]."'"); $rs5=mysqli_fetch_assoc($sql5);
	}
	$iarr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$iarr = $iarr + array( $key => $value);
		}
	}
	$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$marr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$marr = $marr + array( $key => $value);
		}
	}
	$rjsm = json_encode($marr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$ts1 = explode('-',$_POST["ts1"]);
	//if($_POST["s1"]==0){echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&hata3",self,500,1);}
	$sqlk = mysqli_query($conn, "select * from t4 where ne='".$_GET["islem"]."' and s1=".$rs5["id"]." and t1=".$_POST["t1"]." order by id desc"); $rsk=mysqli_fetch_assoc($sqlk);	
	if(mysqli_num_rows($sqlk)>0){
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$rsk["id"]."",self,500,1);
	}else{
		$sql = $conn->query("insert into t4(ne,t1,t2,t3,t4,t5,t6,s1,s2,s3,s4,s13,pb1,pb2,pb3,pb4,n1,n2,n11,n17,n18,t9,t10,s19,ts1) values ('".$_GET["ne"]."', '".$_POST["t1"]."', '".$_POST["t2"]."', '".$_POST["t3"]."', '".$_POST["t4"]."', '".$_POST["t5"]."', '".$_POST["t6"]."', '".$rs5["id"]."', '".$ts1[2]."', '".$ts1[1]."', '".$ts1[0]."', '0', '0', '0', '0', '".$_POST["discount"]."', '".addslashes(stripslashes($_POST["n1"]))."', '".addslashes(stripslashes($_POST["n2"]))."', '".addslashes(stripslashes($_POST["n11"]))."', '".addslashes(stripslashes($rjsi))."','".addslashes(stripslashes($rjsm))."', '".$_POST["ts1"]."', '".$_POST["ts2"]."', '".$_POST["s19"]."', now())");
		$sql = mysqli_query($conn, "select * from t4 where ne='service' order by id desc"); $rs=mysqli_fetch_assoc($sql);
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$rs["id"]."&durum=ok",self,500,1);
	}

}elseif($_GET["durum"]=="kaydet"){
	$iarr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$iarr = $iarr + array( $key => $value);
		}
	}
	$rjsi = json_encode($iarr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$marr = array();
	foreach ($_POST as $key => $value){
		if(substr($key,0,1)=="i"){
			$marr = $marr + array( $key => $value);
		}
	}
	$rjsm = json_encode($marr, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
	$ts1 = explode('-',$_POST["ts1"]);
	echo $discount = empty($_POST["discount"]) ? 0 : $_POST["discount"];
	$subtotal = empty($_POST["subtotal"]) ? 0 : $_POST["subtotal"];
	$total = empty($_POST["total"]) ? 0 : $_POST["total"];
	$tax = empty($_POST["tax"]) ? 0 : $_POST["tax"];
	$Rs = mysqli_query($conn, "update t4 set t1='".$_POST["t1"]."', t2='".$_POST["t2"]."', t3='".$_POST["t3"]."', t4='".$_POST["t4"]."', t5='".$_POST["t5"]."', s5='".$_POST["s5"]."', s19='".$s19."', t7='".$_POST["tahsilat"]."', t9='".$_POST["ts1"]."', t10='".$_POST["ts2"]."', pb1='".sprice($subtotal)."', pb2='".sprice($total)."', pb3='".sprice($tax)."', pb4='".sprice($discount)."', s1='".$_POST["s1"]."', s2='".$ts1[2]."', s3='".$ts1[1]."', s4='".$ts1[0]."', s13='".$_POST["s13"]."', n1='".addslashes(stripslashes($_POST["n1"]))."', n2='".addslashes(stripslashes($_POST["n2"]))."', n7='".addslashes(stripslashes($_POST["n7"]))."', n11='".addslashes(stripslashes($_POST["n11"]))."', n17='".addslashes(stripslashes($rjsi))."', n18='".addslashes(stripslashes($rjsm))."', ts2=now() where id=".$_GET["id"]."");
	$sqlwk = mysqli_query($conn, "select * from t1 where ne='workflow' and s5=".$_GET["id"]." order by id desc"); $rsk=mysqli_fetch_assoc($sqlwk);
	if(mysqli_num_rows($sqlwk)==0){
		$sqlx=mysqli_query($conn, "select * from kategoriler where ne='wkategori' order by sira asc"); $rsx=mysqli_fetch_assoc($sqlx);
		$sql = $conn->query("insert into t1(ne,t1,s5,s2,s13,ts1) values ('workflow', '".$_POST["n2"]." > ".$total."', '".$_GET["id"]."', '".$rsx["Cat_ID"]."', '1', now())");
	}else{
		$Rs = mysqli_query($conn, "update t1 set t1='".$_POST["n2"]." > ".$total."', ts2=now() where s5=".$_GET["id"]."");
	}
	//echo '<body onload="window.opener.location.reload();">';
	echo $sdil[212];
	//echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);

}elseif($_GET["durum"]=="sservice"){
	unlink("../../../deppo/dosya/offer_".$rsf["t1"].".pdf");
	$sql = mysqli_query($conn, "delete from t4 where id=".$_GET["id"]." or s5=".$_GET["id"]." or s1=".$_GET["id"]."");
	$sql = mysqli_query($conn, "delete from t1 where s5=".$_GET["id"]."");
	//$sql = mysqli_query($conn, "delete from medya where t3='".$_GET["ne"]."' and s1=".$_GET["id"]."");
	//echo "<script> window.addEventListener('load', function() { parent.postMessage('closeModal', '*'); }); </script>";
	echo "<script> window.addEventListener('load', function () { parent.postMessage({ action: 'closeModalAndHideRow', rowId: ".$_GET["id"]." }, '*'); }); </script>";

}elseif($_GET["durum"]=="pdf"){
	$sqlx = mysqli_query($conn, "update t4 set s13='1', ts2=now() where id=".$_GET["id"]."");
	$url="".$weburl."/".$crmpath."/modules/print/print_service.php?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."";
/*
	$pdfname="offer_".$rsf["t1"].".pdf";
	$expath="../../../";
	if(!file_exists("../../../deppo/dosya/".$pdfname."")){
		$expdf=expdf($url,$pdfname,$expath);
	}
*/
	$mesaj	= "
		<h3>".$rsf["t1"]." ".translate("Nolu Teklif")."</h3>
		<b>".translate("Sayın")." ".$fcariName.";</b><br>".translate("offer_mail_text")."<br><br><br><br>
		<center>
			<a href=\"".$weburl."/offer/view/".$rsf["id"]."\" target=\"_blank\" style=\"padding: 10px; border: 1px solid #ccc; margin-right:5px; color:black;background: antiquewhite;\">".translate("İncele")."</a> 
			<a href=\"".$weburl."/offer/approved/".$rsf["id"]."\" target=\"_blank\" style=\"padding: 10px; border: 1px solid #ccc; margin-right:5px; color:black;background: aquamarine;\">".translate("Onayla")."</a> 
			<a href=\"".$weburl."/offer/cancel/".$rsf["id"]."\" target=\"_blank\" style=\"padding: 10px; border: 1px solid #ccc; color:black;background: coral;\">".translate("İlgilenmiyorum")."</a>
		</center>
		<br><br>
	";
	if(mysqli_num_rows($sqls)<>0){
		$design_top		= $rs_temp["n7"];
		$design_bottom = $rs_temp["n6"];
		$mgonderen		= $rs_temp["t10"];
		$gonderen			= $rs_temp["t11"];
	}
	$mesaj			= $design_top_temp.$design_top.$mesaj.$design_bottom.$design_bottom_temp;
	$konu			= "".$rsf["t1"]." ".translate("Nolu Teklif")."";
	$path			= "../../../";
	$malici			= $fcariEmail;
	//echo $mesaj;
	emailgonder($malici,$konu,$cc,rlang($mesaj));
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok_pdf",self,500,1);

}elseif($_GET["durum"]=="dpdf"){
	unlink("../../../deppo/dosya/offer_".$rsf["t1"].".pdf");
	echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok",self,500,1);

}elseif($_GET["status"]<>""){
	$Rs = mysqli_query($conn, "update t4 set t4='".$_GET["status"]."' where id='".$_GET["id"]."'");
	if($_GET["status"]=="order"){
		include("op2.php");
	}elseif($_GET["status"]=="delivery" or ($rsf["t4"]<>"delivery" and $_GET["status"]=="invoice")){
		include("op.php");
	}
	
	if($_GET["status"]=="invoice"){
		$Rs = mysqli_query($conn, "update t4 set ne='sfatura', t2='', ts1=now() where id='".$_GET["id"]."'");
		$Rs = mysqli_query($conn, "update t4 set t1='sfatura' where s1='".$_GET["id"]."'");
		echo location("?ne=muhasebe&islem=sfatura&id=".$_GET["id"]."",self,500,1);
	}else{
		echo location("?ne=".$_GET["ne"]."&islem=".$_GET["islem"]."&id=".$_GET["id"]."&durum=ok#&tab-extra",self,500,1);
	}
}
include("../public/log.php");
?>