<html>
<head>
<title>Add Quotation Form</title>
<style>
	*{font: 12px tahoma;}
	#all {margin:auto;
			width:833px;		
			padding:5px;
			background:#ddf;}
	body {background: url(../../PHPTest/images/bg.jpg);
		     min-width: 700px;}
	.desc select{
		margin: 0;
		height: 20px;
	}
	select{background: #eee none repeat scroll 0 0;
			  border: 1px solid gray;
			  margin-left: 90px;
			  margin-bottom: 4px;
			  margin-top: 4px;
			  height: 20px;
			  float: left;}
	.Selpd{margin-left: 5px;
			  margin-top: 0;}
   .chosen{margin-left: 5px;
			  margin-top: 3px;} 
	.sur{margin-top: 0;
	       margin-left: 84px;}
	.surname{margin-top: 3px;
	               margin-left: 0;}
	.name{margin: 0}
	.cName{margin: 0;
	          padding: 0;}
   .sName{margin: 0}    
	/*input{background: #eee none repeat scroll 0 0;}*/
	#pro_id{width: 75px;}
	#bg{
		margin:auto;
		width:830px;		
		padding:5px;
		color: crimson;
		background:#ddf;
	   border:2px solid rgba(186,186,186,1.00);
	}
   #readonly p{color: red;}    
	#bg p{font-size: 16px;}
   span{font-size: 18px;
        color: cadetblue;} 
   .textHighlight p{
        width: 300px;
        color: wheat;}     
</style>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.min.js"></script>    
</head>    
    
<script>   
    
    var HttPRequest = false;
	function doCallAjax(fProductNo,fProductName,fPrice) {
		HttPRequest = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			HttPRequest = new XMLHttpRequest();
			if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			}
		} else if (window.ActiveXObject) { // IE
				try {
						HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
					 } catch (e) {
										try {
										HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
										} catch (e) {}	
									 }
				}
		if (!HttPRequest) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}	
		var url = 'page-content/seller/GetFill.php';
		var pmeters = 'tProductNo=' + encodeURI(document.getElementById(fProductNo).value);
		HttPRequest.open('POST',url,true);
		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
		HttPRequest.onreadystatechange = function()
		{
			//if(HttPRequest.readyState == 3)  // Loading Request
			//{
			//document.getElementById(fProductName).innerHTML = "..";
			//}
			if(HttPRequest.readyState == 4) // Return Request
			{
				var myProduct = HttPRequest.responseText;
				if(myProduct != "")
				{
					var myArr = myProduct.split("|");
						document.getElementById(fProductNo).value = myArr[0];          
						document.getElementById(fProductName).value = myArr[1];
						document.getElementById(fPrice).value = myArr[2];   						
				}
			}
		}
	}
	
	function doSalerCallAjax(smFName,smLName) {
		HttPRequest = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			HttPRequest = new XMLHttpRequest();
			if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			}
		} else if (window.ActiveXObject) { // IE
				try {
						HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
					 } catch (e) {
										try {
										HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
										} catch (e) {}	
									 }
				}
		if (!HttPRequest) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}	
		var url = 'page-content/seller/GetFillSaler.php';
		var pmeters = 'tsmName=' + encodeURI(document.getElementById(smFName).value);
		HttPRequest.open('POST',url,true);
		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
		HttPRequest.onreadystatechange = function()
		{
			//if(HttPRequest.readyState == 3)  // Loading Request
			//{
			//document.getElementById(fProductName).innerHTML = "..";
			//}
			if(HttPRequest.readyState == 4) // Return Request
			{
				var myName = HttPRequest.responseText;
				if(myName != "")
				{
					var myArr = myName.split("|");
					document.getElementById(smFName).value = myArr[0];
					document.getElementById(smLName).value = myArr[1];
				}
			}
		}
	}    
    
	//function doCustCallAjax(cName,cAdrs,cDstrt,cPrvn,cTelc1,cTel1) {
	function doCustCallAjax(cName,cAdrs,cDstrt,cPrvn,cTel1,cTel2,cCont,cTax) {
		HttPRequest = false;
		if (window.XMLHttpRequest) { // Mozilla, Safari,...
			HttPRequest = new XMLHttpRequest();
			if (HttPRequest.overrideMimeType) {
				HttPRequest.overrideMimeType('text/html');
			}
		} else if (window.ActiveXObject) { // IE
				try {
						HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
					 } catch (e) {
										try {
										HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
										} catch (e) {}	
									 }
				}
		if (!HttPRequest) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}	
		var url = 'page-content/seller/GetFillCustomer.php';
		var pmeters = 'tcName=' + encodeURI(document.getElementById(cName).value);
		HttPRequest.open('POST',url,true);
		HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		HttPRequest.setRequestHeader("Content-length", pmeters.length);
		HttPRequest.setRequestHeader("Connection", "close");
		HttPRequest.send(pmeters);
		HttPRequest.onreadystatechange = function()
		{
			//if(HttPRequest.readyState == 3)  // Loading Request
			//{
			//document.getElementById(fProductName).innerHTML = "..";
			//}
			if(HttPRequest.readyState == 4) // Return Request
			{
				var myName = HttPRequest.responseText;
				if(myName != "")
				{
					var myArr = myName.split("|");
					document.getElementById(cName).value = myArr[0];
					document.getElementById(cAdrs).value = myArr[1];
					document.getElementById(cDstrt).value = myArr[2];
					document.getElementById(cPrvn).value = myArr[3];
					document.getElementById(cTel1).value = myArr[4];
              		document.getElementById(cTel2).value = myArr[5];
              		document.getElementById(cCont).value = myArr[6];        
              		document.getElementById(cTax).value = myArr[7];        
				}
			}
		}
	}    
    
	function chk()
	{
		var num=parseFloat(document.frm.txtNum.value);
		var disc =parseFloat(document.frm.txtDisc.value);
		
		var qty1=parseFloat(document.frm.txtQty1.value);
		var sleprc1=parseFloat(document.frm.txtPrice1.value);
		var qty2=parseFloat(document.frm.txtQty2.value);
		var sleprc2=parseFloat(document.frm.txtPrice2.value);
		var qty3=parseFloat(document.frm.txtQty3.value);
		var sleprc3=parseFloat(document.frm.txtPrice3.value);
		var qty4=parseFloat(document.frm.txtQty4.value);
		var sleprc4=parseFloat(document.frm.txtPrice4.value);
		var qty5=parseFloat(document.frm.txtQty5.value);
		var sleprc5=parseFloat(document.frm.txtPrice5.value);
		var qty6=parseFloat(document.frm.txtQty6.value);
		var sleprc6=parseFloat(document.frm.txtPrice6.value);
		var qty7=parseFloat(document.frm.txtQty7.value);
		var sleprc7=parseFloat(document.frm.txtPrice7.value);
		var qty8=parseFloat(document.frm.txtQty8.value);
		var sleprc8=parseFloat(document.frm.txtPrice8.value);
		var qty9=parseFloat(document.frm.txtQty9.value);
		var sleprc9=parseFloat(document.frm.txtPrice9.value);
		var qty10=parseFloat(document.frm.txtQty10.value);
		var sleprc10=parseFloat(document.frm.txtPrice10.value);
		
		if(disc<=100){
			document.frm.tdisc1.value=(qty1*sleprc1)*(disc/100);
			document.frm.tdiscd1.value=((qty1*sleprc1)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle1.value=((qty1*sleprc1)-(qty1*sleprc1*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});

			document.frm.tdisc2.value=(qty2*sleprc2*disc/100);
			document.frm.tdiscd2.value=((qty2*sleprc2)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle2.value=((qty2*sleprc2)-(qty2*sleprc2*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc3.value=(qty3*sleprc3*disc/100);
			document.frm.tdiscd3.value=((qty3*sleprc3)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle3.value=((qty3*sleprc3)-(qty3*sleprc3*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc4.value=(qty4*sleprc4*disc/100);
			document.frm.tdiscd4.value=((qty4*sleprc4)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle4.value=((qty4*sleprc4)-(qty4*sleprc4*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc5.value=(qty5*sleprc5*disc/100);
			document.frm.tdiscd5.value=((qty5*sleprc5)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle5.value=((qty5*sleprc5)-(qty5*sleprc5*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc6.value=(qty6*sleprc6*disc/100);
			document.frm.tdiscd6.value=((qty6*sleprc6)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle6.value=((qty6*sleprc6)-(qty6*sleprc6*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc7.value=(qty7*sleprc7*disc/100);
			document.frm.tdiscd7.value=((qty7*sleprc7)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle7.value=((qty7*sleprc7)-(qty7*sleprc7*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc8.value=(qty8*sleprc8*disc/100);
			document.frm.tdiscd8.value=((qty8*sleprc8)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle8.value=((qty8*sleprc8)-(qty8*sleprc8*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc9.value=(qty9*sleprc9*disc/100);
			document.frm.tdiscd9.value=((qty9*sleprc9)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle9.value=((qty9*sleprc9)-(qty9*sleprc9*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			
			document.frm.tdisc10.value=(qty10*sleprc10*disc/100);
			document.frm.tdiscd10.value=((qty10*sleprc10)*(disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});
			document.frm.tsle10.value=((qty10*sleprc10)-(qty10*sleprc10*disc/100)).toLocaleString(undefined,{minimumFractionDigits:2});

			//document.frm.qsum.value=sleprc1+sleprc2+sleprc3+sleprc4+sleprc5+
												   //sleprc6+sleprc7+sleprc8+sleprc9+sleprc10;

			document.frm.tdisc.value=((qty1*sleprc1*disc/100)+(qty2*sleprc2*disc/100)+
												   (qty3*sleprc3*disc/100)+(qty4*sleprc4*disc/100)+
												   (qty5*sleprc5*disc/100)+(qty6*sleprc6*disc/100)+
												   (qty7*sleprc7*disc/100)+(qty8*sleprc8*disc/100)+
												   (qty9*sleprc9*disc/100)+(qty10*sleprc10*disc/100));
			
			document.frm.tdiscd.value=((qty1*sleprc1*disc/100)+(qty2*sleprc2*disc/100)+
												   (qty3*sleprc3*disc/100)+(qty4*sleprc4*disc/100)+
												   (qty5*sleprc5*disc/100)+(qty6*sleprc6*disc/100)+
												   (qty7*sleprc7*disc/100)+(qty8*sleprc8*disc/100)+
												   (qty9*sleprc9*disc/100)+(qty10*sleprc10*disc/100)).
												   toLocaleString(undefined,{minimumFractionDigits:2});

			/*document.frm.tsle.value=(((qty1*sleprc1)-(qty1*sleprc1*disc/100))+
												  ((qty2*sleprc2)-(qty2*sleprc2*disc/100))+
												  ((qty3*sleprc3)-(qty3*sleprc3*disc/100))+
												  ((qty4*sleprc4)-(qty4*sleprc4*disc/100))+
												  ((qty5*sleprc5)-(qty5*sleprc5*disc/100))+
												  ((qty6*sleprc6)-(qty6*sleprc6*disc/100))+
												  ((qty7*sleprc7)-(qty7*sleprc7*disc/100))+
												  ((qty8*sleprc8)-(qty8*sleprc8*disc/100))+
												  ((qty9*sleprc9)-(qty9*sleprc9*disc/100))+
												  ((qty10*sleprc10)-(qty10*sleprc10*disc/100)));*/
			document.frm.tsle.value=(((qty1*sleprc1))+
												  ((qty2*sleprc2))+
												  ((qty3*sleprc3))+
												  ((qty4*sleprc4))+
												  ((qty5*sleprc5))+
												  ((qty6*sleprc6))+
												  ((qty7*sleprc7))+
												  ((qty8*sleprc8))+
												  ((qty9*sleprc9))+
												  ((qty10*sleprc10)));									  
			
			document.frm.tsled.value=(((qty1*sleprc1)-(qty1*sleprc1*disc/100))+
												  ((qty2*sleprc2)-(qty2*sleprc2*disc/100))+
												  ((qty3*sleprc3)-(qty3*sleprc3*disc/100))+
												  ((qty4*sleprc4)-(qty4*sleprc4*disc/100))+
												  ((qty5*sleprc5)-(qty5*sleprc5*disc/100))+
												  ((qty6*sleprc6)-(qty6*sleprc6*disc/100))+
												  ((qty7*sleprc7)-(qty7*sleprc7*disc/100))+
												  ((qty8*sleprc8)-(qty8*sleprc8*disc/100))+
												  ((qty9*sleprc9)-(qty9*sleprc9*disc/100))+
												  ((qty10*sleprc10)-(qty10*sleprc10*disc/100))).
												  toLocaleString(undefined,{minimumFractionDigits:2});
			
				//var term = document.frm.tsle.value
				var term = ((qty1*sleprc1)-(qty1*sleprc1*disc/100))+((qty2*sleprc2)-(qty2*sleprc2*disc/100))+
								  ((qty3*sleprc3)-(qty3*sleprc3*disc/100))+((qty4*sleprc4)-(qty4*sleprc4*disc/100))+
								  ((qty5*sleprc5)-(qty5*sleprc5*disc/100))+((qty6*sleprc6)-(qty6*sleprc6*disc/100))+
								  ((qty7*sleprc7)-(qty7*sleprc7*disc/100))+((qty8*sleprc8)-(qty8*sleprc8*disc/100))+
								  ((qty9*sleprc9)-(qty9*sleprc9*disc/100))+((qty10*sleprc10)-(qty10*sleprc10*disc/100));
			
			}else{
				 document.frm.tdisc.value=disc;
				 document.frm.tdiscd.value=disc.toLocaleString(undefined,{minimumFractionDigits:2});

			  	 document.frm.tdisc1.value=0;
			  	 document.frm.tsle1.value=(qty1*sleprc1).toLocaleString(undefined,{minimumFractionDigits:2});
			  	 document.frm.tdisc2.value=0;
				 document.frm.tsle2.value=(qty2*sleprc2).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc3.value=0;
				 document.frm.tsle3.value=(qty3*sleprc3).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc4.value=0;
				 document.frm.tsle4.value=(qty4*sleprc4).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc5.value=0;
				 document.frm.tsle5.value=(qty5*sleprc5).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc6.value=0;
				 document.frm.tsle6.value=(qty6*sleprc6).toLocaleString(undefined,{minimumFractionDigits:2});
			  	 document.frm.tdisc7.value=0;
				 document.frm.tsle7.value=(qty7*sleprc7).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc8.value=0;
			     document.frm.tsle8.value=(qty8*sleprc8).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc9.value=0;
			     document.frm.tsle9.value=(qty9*sleprc9).toLocaleString(undefined,{minimumFractionDigits:2});
			     document.frm.tdisc10.value=0;
			     document.frm.tsle10.value=(qty10*sleprc10).toLocaleString(undefined,{minimumFractionDigits:2});
			
			 	 /*document.frm.tsle.value=(((qty1*sleprc1)+(qty2*sleprc2)+(qty3*sleprc3)+(qty4*sleprc4)+
											            (qty5*sleprc5)+(qty6*sleprc6)+(qty7*sleprc7)+(qty8*sleprc8)+
											            (qty9*sleprc9)+(qty10*sleprc10))-disc).
													    toLocaleString(undefined,{minimumFractionDigits:2});*/
				document.frm.tsle.value=((qty1*sleprc1)+(qty2*sleprc2)+(qty3*sleprc3)+(qty4*sleprc4)+
											            (qty5*sleprc5)+(qty6*sleprc6)+(qty7*sleprc7)+(qty8*sleprc8)+
											            (qty9*sleprc9)+(qty10*sleprc10));																				
				document.frm.tsled.value=(((qty1*sleprc1)+(qty2*sleprc2)+(qty3*sleprc3)+(qty4*sleprc4)+
											            (qty5*sleprc5)+(qty6*sleprc6)+(qty7*sleprc7)+(qty8*sleprc8)+
											            (qty9*sleprc9)+(qty10*sleprc10))-disc).
													    toLocaleString(undefined,{minimumFractionDigits:2});
				
				//var term = document.frm.tsle.value
				var term = (((qty1*sleprc1)+(qty2*sleprc2)+(qty3*sleprc3)+(qty4*sleprc4)+
											            (qty5*sleprc5)+(qty6*sleprc6)+(qty7*sleprc7)+(qty8*sleprc8)+
											            (qty9*sleprc9)+(qty10*sleprc10))-disc);
		}//Number.prototype.toString()
		
		var term1d=parseFloat(document.frm.txtTerm1d.value);

		document.frm.calTerm1.value=(term*term1d/100).toLocaleString(undefined,{minimumFractionDigits:2});
		
      	document.frm.txtTerm2.value=100-term1d;
      	document.frm.txtTerm2d.value=(100-term1d).toLocaleString(undefined,{minimumFractionDigits:2});
      	document.frm.calTerm2.value=(term*((100-term1d)/100)).toLocaleString(undefined,{minimumFractionDigits:2});    
	}
</script> 
    
<script language="JavaScript">
    document.onkeydown = chkEvent 
    function chkEvent(e) {
        var keycode;
        if (window.event) keycode = window.event.keyCode; //*** for IE ***//
        else if (e) keycode = e.which; //*** for Firefox ***//
        if(keycode==13)
        {
            return false;
        }
    }
</script>    
    
<body>
<?php	
error_reporting(0);	
include "functions/dblink.php";	
	
//ถ้าเป็นการ Postback เพื่อส่งข้อมูลกลับเข้ามา
if(isset($_POST['NO']))
{//นำข้อมูลจากตัวแปร $_POST ทีเหลือมาเรียงต่อเป็นสตริงเดียวกันโดยขั้นด้วย ' , '
	$values=implode("','",$_POST);     //ลักษณะผลลัพธ์เช่น  a',  'b',  'c', 'd	
      //ปิดหัว ท้าย ด้วย ' เพื่อให้ครบคู่ ลักษณะผลลัพธ์จะเป็น 	'a',  'b',  'c', 'd'
    $values="'".$values."'";  	
	
      //นำข้อมูลนั้นมาสร้างเป็น  SQL ในแบบคำสั่ง REPLACE
    $sql="REPLACE INTO quot002 VALUES($values); ";
    $replace=mysqli_query($con,$sql);
	 if(!$replace){echo mysqli_error($con);}
		else{ ?>
			<div id="bg" align="center" >	
					<!-- <p>Username and Password Incorrect !</p> -->
					<p>--- ข้อมูลบันทึกแล้ว ---</p>
					<br>
				<?php
				 backadd();}//ฟังค์ชั่นนี้อยู่ในขั้นตอน  1	
				?>
			</div>
<?php }
//--------------			
if(isset($_GET['action']))
{$action=$_GET['action'];
	//ถ้าเป็นเพิ่มข้อมูล ก็ไม่ต้องทำอะไร เพื่อให้ฟอร์มนั้นว่างเปล่าสำหรับรับข้อมูลใหม่
	//if($action=="insert")
 
	if($action=="seller/addQuotationAction")
		{   $h="เพิ่มข้อมูลใบเสนอราคา(Quotation)";
		 
			//$no = mysqli_query($con,"SELECT * FROM quot002");
			$sql="SELECT * FROM quot002 WHERE YEAR(QDATE)=YEAR(CURDATE())";
			$query=mysqli_query($con,$sql);
			$rows=mysqli_num_rows($query);//จำนวนข้อมูลที่มีทั้งหมดในปีปัจจุบัน

			$sql = "SELECT * FROM quot002 
				    WHERE year(`QDATE`)=DATE_FORMAT(curdate(),'%Y') 
				    ORDER BY QNO DESC LIMIT 1";//Record สุดท้ายของปีนี้
			$query=mysqli_query($con,$sql);
			$result=mysqli_fetch_assoc($query);
			$data=substr($result['QNO'],5,6);//หมายเลข Quotation สุดท้ายของปีนี้
			//หมายเลข Quotation สุดท้ายของปีนี้ บวก 1 เป็น Record ใหม่
			if($data>0){$num=$data+1;}else{$num=1;}

			$substr = DATE("y").DATE("m");
			if(strlen((string)$num)==1){$k="00000";}
				elseif(strlen((string)$num)==2){$k="0000";}
					elseif(strlen((string)$num)==3){$k="000";}
						elseif(strlen((string)$num)==4){$k="00";}
							elseif(strlen((string)$num)==5){$k="0";}
								else{$k="";}
			
	$x=$substr.$k.$num;
		 
		}else if($action=="seller/deleteQuotationAction")
		    {//ถ้าเป็นการลบ ก็นำค่า id ไปกำหนดเป็นเงื่อนใขการลบ
			  $id=$_GET['NO'];
              $select="SELECT * FROM quot002 WHERE NO=$id"; 
              $search=mysqli_query($con,$select);
              while($data = mysqli_fetch_array($search)){
                  $no=$data['QNO'];
                  $date=$data['QDATE'];
                  $name=$data['QC_NAME'];
              } ?>
              
        <div id="bg" align="center">
            <form method="post" id="confirm" action="#">
                <div class="textHighlight" align="center" 
                     style="border: double; font-size: 18px; background: #1836B1">
                    <br>
                    <p>ต้องการลบข้อมูลใบเสนอราคา</p><br>
                    <span style="color: red;">Q No. </span>
                    <span style="color: cornsilk;"><?php echo $no; ?></span>
                    <span style="color: red;"> วันที่ </span>
                    <span style="color: cornsilk;"><?php echo date('d-m-Y',$date);?></span>
                    <span style="color: red;"> ชื่อ/บริษัท </span>
                    <span style="color: cornsilk;"><?php echo $name; ?></span>
                    <p></p><br>
                </div>    
                <br>
                <p><span style="font-size: 20px; color: red;">ใช่</span>
                        (Yes - 'Y' ; 'y') <span style="color: black; font-size: 18px;">หรือ</span>
                        <span style="font-size: 20px; color: red;">ไม่</span>
                        (No - 'N' ; 'n') ?</p>
                <p>=>
                <input type="text" name="conf" size="2" pattern="[nyNY]" 
                       style="border: double;" required></p>
                <input type="submit" value="Confirm" style="color: red;">
                 <?php
                    if($_POST['conf']=='Y' OR $_POST['conf']=='y'){
                        $sql="DELETE FROM quot002 WHERE NO=$id"; 
                        $delete=mysqli_query($con,$sql);}
                    if(!$delete) {echo  mysqli_error($con);}else{?>
                        <div class="textHighlight" align="center">
                            <p style="border: double; font-size: 18px; background: #1836B1">
                                ข้อมูลใบเสนอราคาถูกลบแล้ว
                            </p>
                        </div>
                    <?php } 

                    if($_POST['conf']=='N' OR $_POST['conf']=='n'){?>
                       <div class="textHighlight" align="center">
                            <p style="border: double; font-size: 18px; background: #1836B1">
                                ยกเลิกการลบข้อมูลใบเสนอราคา
                            </p>
                       </div>       
                <?php } 
                back();?>
        </form>    
        </div>
<?php }
}  
    
   function backadd()
	{
		global $con;
		mysqli_close($con);
		exit("<p><a href='actionController.php?action=seller/addQuotationAction'>
					ย้อนกลับ</a></p></body></html>");
	}    
    
	function back()
	{
		global $con;
		mysqli_close($con);
		exit("<p><a href='actionController.php?action=seller/retrieveQuotationAction'>
					ย้อนกลับ</a></p></body></html>");
	}
mysqli_close($con);	

?>
<div style='font-size:18px; color:red; text-align: center'><?php echo $h; ?></div>
<div id="all" align="center">

<form class="form-inline" name="frm" id="readonly" method="post">
<table width="840">
    	<tr><td width="73" style='font-size:14px; color:blue;'><strong>รายละเอียด</strong></td>
    		   <td width="755"><p>(อักษรสีแดง - Readonly)</p></td>
    	</tr>
</table>
<table width="840">	  	
		<tr><td width="239"><input name="NO" type="hidden" value=0></td></tr>
</table>
<table width="840">	  		  	
  	  	<tr><td width="74" style='text-align:right'><p>Q No. :</p></td>
		     <td width="225"><input name="QNO" type="text" size="10" style="color: red;"
		  	   					             value="<?php echo $x; ?>" readonly></td> 

			  <td width="110" style='text-align:right'>วันที่ :</td>
			  <td width="411"><input type="date" name="QDATE" id="QDATE" size="19"
		  			                      value="<?php echo date('Y-m-d'); ?>"
                                    onkeydown="return nextbox(event, 'C_SURNAME');"></td>
		</tr>
		
  		<tr>
			  <td style="text-align: right" width="74"><p>ข้อมูลทั้งหมด :</p></td>
			  <td><input type="text" name="QC_NO" id="QC_NO" size="10"  
                      style="text-align: right; color: red;" readonly
			              value="<?php echo $rows; ?>"></td>		                               
		</tr>
</table>
<table width="840">					
		<tr>
			<td width="81" align="right">ผู้ซื้อ :</td>
			<td width="49">
				<input type="hidden" name="C_SURNAME"> 
				<select class="surname" name="C_SURNAME" id="C_SURNAME"
                   onkeydown="return nextbox(event, 'cName');">
					<option><?php echo "" ?></option>
					<?php
							include "functions/dblink.php";

							$sql = "select DISTINCT C_SURNAME from cust001 ORDER BY C_SURNAME ASC";
							$query = mysqli_query($con,$sql);

							while($result = mysqli_fetch_array($query)){
								if($strDefault == $result["C_SURNAME"]){$sel = "selected";}
									else{$sel = "";}		
						?>
						<option value="<?php echo $result["C_SURNAME"];?>">
							<?php echo $result["C_SURNAME"]; ?>
						</option>
						<?php } ?>
				</select>
			</td>
			
			<td width="505">
           <select class="chosen" name="search" id="cName" style="width:500px;"       
				   OnChange="JavaScript:doCustCallAjax('cName','cAdrs','cDstrt','cPrvn',
                                                         'cTel1','cTel2','cCont','cTax');"
                   onkeydown="return nextbox(event, 'cCont');">  
				        <option><?php echo ""; ?></option>      
					  <?php
					  		include "functions/dblink.php";
   
							$sql = "select DISTINCT C_NAME FROM cust001 ORDER BY C_NAME ASC";
							$query = mysqli_query($con,$sql);
							while($result = mysqli_fetch_array($query)){
								if($strDefault == $result["C_NAME"]){$sel = "selected";}
									else{$sel = "";}
						?>
						<option value="<?php echo $result["C_NAME"]; ?>">
                                <?php echo $result["C_NAME"]; ?></option>
                <?php } ?> 
                <td width="8"><input type="hidden" name="cName" id="cName" size="50" disabled>
                    
           </select>
           <script type="text/javascript">$(".chosen").chosen();</script>        
                   
			<td width="190"></td>		  	                     
		</tr>
</table>

<table width="840">
	<tr>		                               
			  <td style="text-align: right" width="75">ผู้ติดต่อ :</td>
			  <td width="226"><input type="text" name="cCont" id="cCont" size="35"
                                   onkeydown="return nextbox(event, 'cTax');"></td>
        
			  <td style="text-align: right" width="71">Tax No. :</td>
			  <td width="84"><input type="text" name="cTax" id="cTax" size="13"
                                  onkeydown="return nextbox(event, 'txtDisc');"></td>
			  
			  <td width="174" style="text-align: right">ส่วนลด(บาท หรือ %) :</td>
		      <td width="177"><input type="text" name="txtDisc" id="txtDisc" size="16" 
		  							      style="text-align: right" value=0 
			  							    onkeydown="return nextbox(event,'cAdrs');"
                               onClick="chk()"> % </td>							  		
	</tr>
</table>

<table width="840">
	<tr>
		<td style="text-align: right" width="82">ที่อยู่ :</td>
		<td width="311"><input type="text" name="cAdrs" id="cAdrs" size="50"
                               onkeydown="return nextbox(event, 'cDstrt');"></td>
        
		<td width="104" style="text-align: right">อำเภอ/จังหวัด :</td>
		<td width="146"><input type="text" name="cDstrt" id="cDstrt"                                
                               onkeydown="return nextbox(event, 'cPrvn');"></td>
        
		<td width="191"><input type="text" name="cPrvn" id="cPrvn"
                               onkeydown="return nextbox(event, 'cTel1');"></td>
	</tr>
</table>

<table width="840">	
	  <tr>
	   <td style="text-align: right" width="74">Tel. 1 :</td>
	   <td width="93"><input type="text" name="cTel1" id="cTel1" size="14"
                             onkeydown="return nextbox(event, 'cTel2');"></td> 
          
	   <td style="text-align: right" width="42">Tel. 2 :</td>
	   <td width="204"><input type="text" name="cTel2" id="cTel2" size="14"
                              onkeydown="return nextbox(event, 'QPJNAME');"></td> 
          
	   <td style="text-align: right" width="88">Proj. :</td>
	   <td width="304"><input type="text" name="QPJNAME" id="QPJNAME" size="40"
                              onkeydown="return nextbox(event, 'txtProductID1');"></td>     
	  </tr>
</table>
</select>

<table>	
	<tr align="left">
		<th width="64">No.</th>
		<th width="79">รหัส</th>
		<th width="225">ชื่อสินค้า</th>
		<th width="60">จำนวน</th>
		<th width="87">ต่อหน่วย</th>
		<th width="114">ลด(บาท)</th>
		<th width="89">รวมขาย</th>
	</tr>
</table>
    
<table>
	<tr>
		<?php for($i=1;$i<=10;$i++){ ?>
		<td><?php echo $i."." ; ?></td>
     <input type="hidden" name="txtNum" value="<?php echo $i; ?>" disabled>        
		<td>         
		<!-- <select> class="chosen" class="Selpd"-->         
		<select class="chosen" style="width: 120px;"
                id="txtProductNo<?php echo $i; ?>" name="txtProductNo<?php echo $i; ?>"
				OnChange="JavaScript:doCallAjax('txtProductNo<?php echo $i; ?>',
									            'txtProductName<?php echo $i; ?>',
									            'txtPrice<?php echo $i; ?>')"
                onkeydown="return nextbox(event,'txtQty<?php echo $i; ?>')">
            <option><?php echo ""; ?></option>
			   
		<?php
			include "functions/dblink.php";
			            
			$sqlNo = "SELECT PDNO FROM prod001 ORDER BY PDNO ASC";
			$queryNo = mysqli_query($con,$sqlNo);
				  
			while($resultNo = mysqli_fetch_array($queryNo)){
					if($pdno == $resultNo["PDNO"]){$sel = "selected";}
					else{$sel = "";}		
		?>
				<option value="<?php echo $resultNo["PDNO"];?>">
					           <?php echo $resultNo["PDNO"];?>
				</option>
		<?php } ?>
     </td> 
            
		<input type="hidden" name="txtProductNo<?php echo $i; ?>"
	                         id="txtProductNo<?php echo $i; ?>" size="8" disabled
	                         onClick="chk();">
		                                	
		<td><input type="text" name="txtProductName<?php echo $i; ?>" 
	                           id="txtProductName<?php echo $i; ?>" size="35"
                               onClick="chk();"></td>
	                                             
		<td><input type="number" name="txtQty<?php echo $i; ?>" id="txtQty<?php echo $i; ?>"
                   style="text-align: right" size="8"
	     		   value=0 min=0 max=1000
	     		   onClick="chk();"
				   onkeydown="return
				   nextbox(event, '<?php if($i<=9){echo 'txtProductID($i+1)';} 
				                         else{echo 'txtSmFName';} ?>')"></td>
                 	 
		<td><input type="text" name="txtPrice<?php echo $i; ?>" id="txtPrice<?php echo $i; ?>" 
	                           style="text-align: right" size="10" value=0
                               onClick="chk();"></td>
	                     		          
		<input type="hidden" name="tdisc<?php echo $i; ?>" id="tdisc<?php echo $i; ?>" 
			                 style="text-align: right" size="12" value=0 
				             onClick="chk();">      
		<td><input type="text" name="tdiscd<?php echo $i; ?>" id="tdiscd<?php echo $i; ?>" 
			                   style="text-align: right" size="12" value=0 disabled 
                               onClick="chk();"></td>	          		          
				          		          
		<td><input type="text" name="tsle<?php echo $i; ?>" id="tsle<?php echo $i; ?>"
	                           style="text-align: right" disabled readonly value=0
                               onClick="chk();"></td>					   			          
	</tr>
	<?php } ?>
	
	<tr>
		<td></td><td></td><td></td>	
	    <td width="56" style='text-align:right'>รวม :</td>
	    <td></td>		  					  		  
		<input type="hidden" name="tdisc" id="tdisc" size="12" style="text-align: right" 
                             value=0
				  			 onClick="chk();">    
		<td><input type="text" name="tdiscd" id="tdiscd" size="12" style="text-align: right" 
			  			       value=0
                               onClick="chk();" disabled></td>
				  			       		  			       
		<input type="hidden" name="tsle" id="tsle" style="text-align: right"
                             value=0
				             onClick="chk()">  
		<td><input type="text" name="tsled" id="tsled" style="text-align: right"
			                   value=0
                               onClick="chk()" disabled></td>		                    
	</tr>
</select>
<script type="text/javascript">$(".chosen").chosen();</script>   
</table>

<table width="840">	
 	<tr>
    <td width="81" align="right">ผู้ขาย : </td>
    <td width="759">  
	  <select class="sName" name="txtSmFName" id="txtSmFName"
		      OnChange="JavaScript:doSalerCallAjax('txtSmFName','txtSmLName');" 
              onkeydown="return nextbox(event,'QPRCV');">
			<option><?php echo ""; ?></option>
			<?php
					include "functions/dblink.php";

					$sqlsn = "select * FROM sale001 ORDER BY SMFNAME ASC";
						    
					$querysn = mysqli_query($con,$sqlsn);
					while($resultsn = mysqli_fetch_array($querysn)){
								if($strDefault == $resultsn["SMFNAME"]){$sel = "selected";}
									else{$sel = "";}		
			?>
        <option value="<?php echo $resultsn["SMFNAME"];?>">  
							<?php echo $resultsn["SMFNAME"]; ?>
        </option>											
			<?php } ?>						   	 															
			  <input type="hidden" name="txtSmFName" id="txtSmFName" disabled> &nbsp;
			  <input type="text" name="txtSmLName" id="txtSmLName" size="30"
                     onkeydown="return nextbox(event,'QPRCV');">	  					
		  </select>
		</td>    
	</tr>		   		 					
</table>

<table width="840">
	  <tr>
			  <td style="text-align: right" width="81">เครดิต :</td>
			  <td width="105"><input type="text" name="QPRCV" id="QPRCV" size="6" 
                                     value=0
                                     onkeydown="return nextbox(event,'QSENT');"> วัน </td>
	  </tr>	
	  <tr>  									  
			  <td style="text-align: right" width="81">กำหนดส่ง :</td>	                              
			  <td width="105"><input type="text" name="QSENT" id="QSENT" size="6" 
                                     value=0
                                     onkeydown="return nextbox(event,'txtTerm1d');"> วัน </td>
	  </tr>
	  <tr>
			  <td style="text-align: right" width="81">ล่วงหน้า :</td>
			  <td width="110"><input type="text" name="txtTerm1d" id="txtTerm1d" 
		                             size="6" value=0
			                         onClick="chk()"
                                     onkeydown="return nextbox(event,'QAFTER');"> % เป็นเงิน </td>
          
          <td><input type="text" name="calTerm1" id="calTerm1" readonly disabled
                     value=0
                     onClick="chk()"
                     onkeydown="return nextbox(event,'QAFTER');"> บาท </td>
      </tr>	
	   <tr>	  		                              
			  <td style="text-align: right" width="81"><p>คงเหลือ :</p></td>
			  <!-- <td width="291"><input name="QTERM1" type="text" size="17"> บาท </td> -->
			  <td width="110"><input type="text" name="txtTerm2d" id="txtTerm2d" 
		                             size="6" value=0 style="color: red;" disabled readonly
			                         onClick="chk()"
                                     onkeydown="return nextbox(event,'QAFTER');"> % เป็นเงิน </td>
           
			                  <input type="hidden" name="txtTerm2" id="txtTerm2"
                                     value=0        
			                         onClick="chk()"
                                     onkeydown="return nextbox(event,'QAFTER');">
           
			  <td><input type="text" name="calTerm2" id="calTerm2" readonly disabled
						 value=0     
						 onClick="chk()"
						 onkeydown="return nextbox(event,'QAFTER');"> บาท </td> 
	  </tr>
  	  <tr>
			  <td style="text-align: right" width="81">กำหนดชำระ :</td>
			  <td width="105"><input type="text" name="QAFTER" id="QAFTER" size="6" 
                                     value=0
                                     onkeydown="return nextbox(event,'QSPEC');"> วัน </td>
      </tr>
	   <tr>				                            
	    <td style="text-align: right" width="81">ค่าออกแบบ :</td>
			  <td width="105"><input type="text" name="QSPEC" id="QSPEC" size="8" 
                                     value=0
                                     onkeydown="return nextbox(event,'QSPECNAME');"
                                   > บาท </td>                               
	   </tr>
	   
  </table> 
  <table width="840">
      <tr> 	  			                            
			  <td style="text-align: right" width="81">ผู้ออกแบบ :</td>
			  <td width="747"><input type="text" name="QSPECNAME" id="QSPECNAME" size="30"
                                     onkeydown="return nextbox(event,'QNOTE');"></td>
	  </tr>
      <tr>
	    <td style="text-align: right" width="81">Note :</td>
			  <td width="747"><input type="text" name="QNOTE" id="QNOTE" size = "90"
                                     onkeydown="return nextbox(event,'QDATE');"></td>
	  </tr>
  </table>
    
			  <input type="hidden" name="QPDATE" value="<?php echo date('Y-m-d'); ?>">
			  <input type="hidden" name="QLOCK" value="<?php echo '0'; ?>">
				
  		<!-- <td align="center"><button>บันทึกข้อมูล(Save)</button> &nbsp;&nbsp;
				<a href='actionController.php?action=seller/retrieveQuotationAction'>ย้อนกลับ</a>
        </td> -->
	<br>	
		<input type="submit" value="บันทึกข้อมูล(Save)">
		<input type="reset" value="Reset">
		<button type="button" 
	        	onclick="location.href='actionController.php?action=seller/retrieveQuotationAction' ">
				ย้อนกลับ
		</button>
</form>
</div>
</body>
</html>