<html>

<head>
	<title>Edit 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;
		}

		.sur {
			margin-top: 0;
			margin-left: 84px;
		}

		.surname {
			margin-top: 0;
			margin-left: 0;
		}

		.sName {
			margin: 0
		}

		.name {
			margin: 3px;
			padding: 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);
		}

		#bg p {
			font-size: 20px;
		}

		#readonly p {
			color: red;
		}
	</style>

</head>
<script>
	var HttPRequest = false;

	function nextbox(e, id) {
		// อ่าน keycode (cross browser)
		var keycode = e.which || e.keyCode;
		// ตรวจสอบ keycode (13 คือ กด enter)
		if (keycode == 13) {
			// ย้ายโฟกัสไปยัง input ที่ id
			document.getElementById(id).focus();
			// return false เพื่อยกเลิกการ submit form
			return 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 term1 = parseFloat(document.frm.txtTerm1.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)) +
				((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.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)));
			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 term1 = parseFloat(document.frm.txtTerm1.value);
		document.frm.calTerm1.value = (term * term1 / 100).
		toLocaleString(undefined, {
			minimumFractionDigits: 2
		});
		document.frm.txtTerm2.value = 100 - term1;
		document.frm.calTerm2.value = (term * ((100 - term1) / 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)";
		$repl = mysqli_query($con, $sql);
		if (!$repl) {
			echo mysqli_error($con);
		} else { ?>
			<div id="bg" align="center">
				<!-- <p>Username and Password Incorrect !</p> -->
				<p>--- ข้อมูลบันทึกแล้ว ---</p>
				<br>
			<?php
			back();
		} //ฟังค์ชั่นนี้อยู่ในขั้นตอน  1	
			?>
			</div>
		<?php }
	//--------------			
	if (isset($_GET['action'])) {
		$action = $_GET['action'];
		//ถ้าเป็นเพิ่มข้อมูล ก็ไม่ต้องทำอะไร เพื่อให้ฟอร์มนั้นว่างเปล่าสำหรับรับข้อมูลใหม่
		//if($action=="insert")

		if ($action == "seller/editQuotationAction") {
			$id = $_GET['NO'];
			$h = "แก้ไขข้อมูลใบเสนอราคา(Quotation Correction)";
			$sql = "SELECT * FROM quot002 WHERE NO=$id";
			$result = mysqli_query($con, $sql);
			$data = mysqli_fetch_array($result);
		}
	}

	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 name="frm" method="POST">
			<table width="840">
				<tr>
					<td width="73" style='font-size:14px; color:blue;'><strong>รายละเอียด</strong></td>
					<td width="755" style="color: red;">
						<p>(อักษรสีแดง - Readonly)</p>
					</td>
				</tr>
			</table>
			<table width="840">
				<tr>
					<td width="74" style='text-align:right; color: red;'>
						<p>Record No. :</p>
					</td>
					<td width="239"><input type="text" name="NO" id="NO" size="15" value="<?php echo $data["NO"]; ?>"></td>
				</tr>
				<!-- </table> -->
				<?php
				$string = trim($data['QNO']);
				$findword = "R";
				$pos = strpos($string, $findword);
				if ($pos !== FALSE) {
					$nr = substr($string, $pos + 1, 3) + 1;
					$s = substr($string, 0, $pos) . "R" . trim($nr);
				} else {
					$s = $string . "R1";
				}

				?>
				<!-- <table width="840"> -->
				<tr>
					<td width="74" style='text-align:right; color: red;'>
						<p>Q No. :</p>
					</td>
					<td width="225"><input type="text" name="QNO" id="QNO" size="15" value="<?php echo $s; ?>" 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 $data["QDATE"]; ?>" onkeydown="return nextbox(event, 'C_SURNAME');"></td>
				</tr>
				<input type="hidden" name="QC_NO" id="QC_NO" size="10" style="text-align: right" readonly value="<?php echo $data["QC_NO"]; ?>">
				<!-- </tr> -->
			</table>
			<table width="840">
				<tr>
					<td style="padding-top: 5px;" width="74" align="right">ผู้ซื้อ :</td>
					<td style="padding-top: 4px;" width="52">
						<input type="hidden" name="C_SURNAME">
						<select class="surname" name="C_SURNAME" id="C_SURNAME" onkeydown="return nextbox(event, 'key');">
							<option><?php echo $data["QC_SUR"]; ?></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>
						<select class="name" name="cName" id="cName" 
								OnChange="JavaScript:doCustCallAjax('cName','cAdrs','cDstrt','cPrvn',
																	'cTel1','cTel2','cCont','cTax');" 
								onkeydown="return nextbox(event, 'QC_CONTRCT');">
							<option><?php
									echo $data["QC_NAME"];
									?>
							</option>
							<?php

							include "functions/dblink.php";

							$sql = "select * 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 } ?>
							<!-- <input type="hidden" disabled> -->
							<!--  </select> -->
					</td>
				</tr>
			</table>

			<table width="840">
				<tr>
					<td style="text-align: right" width="74">ผู้ติดต่อ :</td>
					<td width="226"><input type="text" name="cCont" id="cCont" size="35" value="<?php echo $data["QC_CONTRCT"]; ?>" onkeydown="return nextbox(event, 'cTax');"></td>

					<td style="text-align: right" width="71">Tax No. :</td>
					<td width="74"><input type="text" name="cTax" id="cTax" size="15" value="<?php echo $data["QC_TAX_NO"]; ?>" 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="<?php echo $data["QC_DISC"]; ?>" onkeydown="return nextbox(event,'cAdrs');" onClick="chk()"> % </td>
				</tr>
			</table>

			<table width="840">
				<tr>
					<td style="text-align: right" width="72">ที่อยู่ :</td>
					<td width="302"><input type="text" name="cAdrs" id="cAdrs" size="50" value="<?php echo $data["QC_ADRS"]; ?>" onkeydown="return nextbox(event, 'cDstrt');"></td>

					<td width="96" style="text-align: right">อำเภอ/จังหวัด :</td>
					<td width="146"><input type="text" name="cDstrt" id="cDstrt" value="<?php echo $data["QC_DSTRT"]; ?>" onkeydown="return nextbox(event, 'cPrvn');"></td>

					<td width="183"><input type="text" name="cPrvn" id="cPrvn" value="<?php echo $data["QC_PRVN"]; ?>" onkeydown="return nextbox(event, 'cTel1');"></td>
				</tr>
			</table>

			<table width="840">
				<tr>
					<td style="text-align: right" width="72">Tel. :</td>
					<td width="104"><input type="text" name="cTel1" id="cTel1" size="14" value="<?php echo $data["QC_TEL"]; ?>" onkeydown="return nextbox(event, 'cFax');"></td>

					<td style="text-align: right" width="36">Fax. :</td>
					<td width="183"><input type="text" name="cFax" id="cFax" size="14" value="<?php echo $data["QC_FAX"]; ?>" onkeydown="return nextbox(event, 'QPJNAME');"></td>

					<td style="text-align: right" width="114">Proj. :</td>
					<td width="278"><input type="text" name="QPJNAME" id="QPJNAME" size="40" value="<?php echo $data["QPJNAME"] ?>" onkeydown="return nextbox(event, 'txtProductID1');"></td>

					<td width="20"></td>
				</tr>
			</table>
			</select>

			<table width="840">
				<tr align="right">
					<th width="81">No.</th>
					<th width="48">รหัส</th>
					<th width="157">ชื่อสินค้า</th>
					<th width="153">จำนวน</th>
					<th width="70">ต่อหน่วย</th>
					<th width="79">ลด(บาท)</th>
					<th width="102">รวมขาย</th>
					<th width="114"></th>
				</tr>
			</table>

			<table>
				<tr>
					<?php for ($i = 1; $i <= 10; $i++) { ?>
						<th><?php echo $i . "."; ?></th>
						<!-- <th></th> -->
						<th>
							<input type="hidden" name="txtNum" value="<?php echo $i; ?>" disabled>
							<!-- <select> -->
							
							<select class="surname"  
									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 $data["QPDNO{$i}"]; ?></option>

								<?php

								include "functions/dblink.php";

								$sqlNo = "SELECT PDNO FROM prod001 ORDER BY PDNO ASC";
								//$sqlNo = "select * 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 } ?>

								<input type="hidden" name="txtProductNo<?php echo $i; ?>" 
														id="txtProductNo<?php echo $i; ?>" size="8" disabled
														value="<?php echo $data["QPDNO{$i}"]; ?>" 
														onClick="chk()">

						<th><input type="text" name="txtProductName<?php echo $i; ?>" 
												id="txtProductName<?php echo $i; ?>" size="35"
												value="<?php echo $data["QPDNAME{$i}"]; ?>" 
												onClick="chk()"></th>

						<th><input type="number" name="txtQty<?php echo $i; ?>" id="txtQty<?php echo $i; ?>" style="text-align: right" size="8" 
									value="<?php echo $data["QQTY{$i}"]; ?>" min=0 max=1000 
									onClick="chk()" 
									onkeydown="return 
									nextbox(event,'<?php if ($i <= 9) {echo 'txtProductNo($i+1)';} 
														else {echo 'txtSmFName';} ?>');"></th>

						<th><input type="text" name="txtPrice<?php echo $i; ?>" id="txtPrice<?php echo $i; ?>" style="text-align: right" size="10" 
									value="<?php echo $data["QSLEPRC{$i}"]; ?>" 
									onClick="chk()"></th>

							<input type="hidden" name="tdisc<?php echo $i; ?>" id="tdisc<?php echo $i; ?>" style="text-align: right" size="12" 
									value="<?php echo $data["QPDDISC{$i}"]; ?>" 
									onClick="chk()">

						<th><input type="text" name="tdiscd<?php echo $i; ?>" id="tdiscd<?php echo $i; ?>" style="text-align: right" size="12" 
									disabled value="<?php echo number_format(($data["QPDDISC{$i}"]), 2); ?>" 
									onClick="chk()"></th>

						<th><input type="text" name="tsle<?php echo $i; ?>" id="tsle<?php echo $i; ?>" style="text-align: right" 
									disabled readonly value=0 
									onClick="chk()"></th>
				</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="<?php echo $data["QSUMDISC"]; ?>" 
						onClick="chk()">

				<td><input type="text" name="tdiscd" id="tdiscd" size="12" style="text-align: right" 
							value="<?php echo number_format(($data["QSUMDISC"]), 2); ?>" 
							onClick="chk()" disabled></td>

				<input type="hidden" name="tsle" id="tsle" style="text-align: right" 
						value="<?php echo $data["QSUM"]; ?>" 
						onClick="chk()">

				<td><input type="text" name="tsled" id="tsled" style="text-align: right" disabled
							value="<?php echo number_format(($data["QSUM"]), 2); ?>" 
							onClick="chk()"></td>
			</tr>
			</table>
			</select>
			</table>

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

							<option><?php echo $data["QSMFNAME"]; ?></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 
									value="<?php echo $data["QSMFNAME"]; ?>"> &nbsp;

							<input type="text" name="txtSmLName" id="txtSmLName" size="30" 
									value="<?php echo $data["QSMLNAME"]; ?>" 
									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 name="QPRCV" id="QPRCV" type="text" size="6" 
											value="<?php echo $data["QPRCV"]; ?>" 
											onkeydown="return nextbox(event,'QSENT');"> วัน </td>
				</tr>
				<tr>
					<td style="text-align: right" width="81">กำหนดส่ง :</td>
					<td width="105"><input name="QSENT" id="QSENT" type="text" size="6" 
											value="<?php echo $data["QSENT"]; ?>" 
											onkeydown="return nextbox(event,'txtTerm1');"> วัน </td>
				</tr>
				<tr>
					<td style="text-align: right" width="81">ล่วงหน้า :</td>
					<td width="110"><input type="text" name="txtTerm1" id="txtTerm1" size="6" 
											value="<?php echo $data["QTERM1"]; ?>" 
											onClick="chk()" onkeydown="return nextbox(event,'QAFTER');"> % เป็นเงิน </td>

					<td><input type="text" name="calTerm1" id="calTerm1" readonly disabled 
								value=0 onClick="chk()"> บาท </td>
				</tr>
				<tr>
					<td style="text-align: right; color: red;" width="81">
						<p>คงเหลือ :</p>
					</td>
					<!-- <td width="291"><input name="QTERM1" type="text" size="17"> บาท </td> -->
					<td width="110"><input type="text" name="txtTerm2" id="txtTerm2" size="6" 
											value=0 style="color: red;" readonly 
											onClick="chk()" 
											onkeydown="return nextbox(event,'QAFTER');"> % เป็นเงิน </td>

					<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="<?php echo $data["QAFTER"]; ?>" 
											onkeydown="return nextbox(event,'QSPEC');"> วัน </td>
				</tr>
				<tr>
					<td style="text-align: right" width="80">ค่าออกแบบ :</td>
					<td width="105"><input type="text" name="QSPEC" id="QSPEC" size="8" 
											value="<?php echo $data["QSPEC"]; ?>" 
											onkeydown="return nextbox(event,'QSPECNAME');"> บาท </td>
				</tr>
			</table>

			<table width="840">
				<tr>
					<td style="text-align: right" width="80">ผู้ออกแบบ :</td>
					<td width="747"><input type="text" name="QSPECNAME" id="QSPECNAME" size="30" 
											value="<?php echo $data["QSPECNAME"]; ?>" 
											onkeydown="return nextbox(event,'QNOTE');"></td>
				</tr>
				<tr>
					<td style="text-align: right" width="80">Note :</td>
					<td width="747"><input type="text" name="QNOTE" id="QNOTE" size="90" 
											value="<?php echo $data["QNOTE"]; ?>" 
											onkeydown="return nextbox(event,'QDATE');"></td>
				</tr>
			</table>
			<table>
				<input type="hidden" name="QPDATE" value="<?php echo date('Y-m-d'); ?>">
				<input type="hidden" name="QLOCK" value="<?php echo "0"; ?>">
			</table>
			<!-- <label>&nbsp :</label> -->
			<td align="center"><button>บันทึกข้อมูล(Save)</button> &nbsp;&nbsp;
				<a href='actionController.php?action=seller/retrieveQuotationAction'>ย้อนกลับ</a>
			</td>
		</form>
		</div>
</body>

</html>