<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
	<meta charset="UTF-8">
	<title>Edit Quotation Form</title>
	<style>
		* {
			font: 12px tahoma;
		}

		#all {
			margin: auto;
			width: 833px;
			padding: 5px;
			background: #ddf;
		}

		body {
			background: url(images/bg.jpg);
			min-width: 700px;
		}

		select {
			background: #eee none repeat scroll 0 0;
			border: 1px solid gray;
		}

		input {
			background: #eee none repeat scroll 0 0;
		}
	</style>
</head>

<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 {
			echo "<h3>ข้อมูลบันทึกแล้ว</h3>";
			back(); //ฟังค์ชั่นนี้อยู่ในขั้นตอน  1					  
		}	//$sql1="UPDATE quot002 SET QQTY1=$q1,QSLEPRC1=$sle1,QPDDISC1=$disc1";
		//$replace1=mysqli_query($con,$sql1); 	 
	}

	//--------------			
	if (isset($_GET['action'])) {
		$action = $_GET['action'];
		//ถ้าเป็นเพิ่มข้อมูล ก็ไม่ต้องทำอะไร เพื่อให้ฟอร์มนั้นว่างเปล่าสำหรับรับข้อมูลใหม่
		//if($action=="insert")
		if ($action == "seller/editQuotationAction") //ถ้าเป็นการแก้ไข ต้องอ่านข้อมูลเดิมมาเติมลงในฟอร์ม
		{
			$id = $_GET['NO'];
			$h = "แก้ไขข้อมูล";
			$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=\"assetList.php\">ย้อนกลับ</a></p></body></html>");
		exit("<p><a href=\"actionController.php?action=seller/retrieveQuotationAction\">
											ย้อนกลับ</a>
				  </p></body></html>");
	}

	mysqli_close($con);
	?>

	<!-- <?php echo $h; ?></legend> -->
	<div id="headq" style='font-size:18px; color:red;'>แบบฟอร์ม<?php echo $h; ?>Quotation</div>
	<div id="all" align="center">
		<form name="formQ" method="post">

			<table width="833">
				<tr>
					<td style='font-size:14px; color:blue;'><strong>รายละเอียด</strong></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="71"><input name="NO" type="hidden" </td>
					<td width="71" style='text-align:right'>Q No. :</td>
					<td width="81"><input name="QNO" type="text" value="<?php echo $data['QNO']; ?>" placeholder="ไม่ต้องระบุ" readonly size="10"></td>
					<td width="40" style='text-align:right'>วันที่ :</td>
					<td width="621"><input name="QDATE" type="text" size="19" value="<?php echo $data['QDATE']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="68" style='text-align:right'>หมายเลข :</td>
					<td><input name="QC_NO" type="text" value="<?php echo $data['QC_NO']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="69" style='text-align:right'>Name :</td>
					<td width="52"><input name="QC_SUR" type="text" size="8" value="<?php echo $data['QC_SUR']; ?>"></td>
					<td width="696"><input name="QC_NAME" type="text" size="50" value="<?php echo $data['QC_NAME']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="75" style='text-align:right'>ผู้ติดต่อ :</td>
					<td width="302"><input name="QC_CONTRCT" type="text" size="35" value="<?php echo $data['QC_CONTRCT']; ?>"></td>
					<td width="59" style='text-align:right'>Tax No. :</td>
					<td width="125"><input name="QC_TAX_NO" type="text" size="13" value="<?php echo $data['QC_TAX_NO']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="75" style='text-align:right'>ส่วนลด :</td>
					<td width="302"><input name="QC_DISC" type="text" size="16" style="text-align: right" value="<?php echo $data['QC_DISC']; ?>"> % </td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="75" style='text-align:right'>ที่อยู่ :</td>
					<td width="302"><input name="QC_ADRS" type="text" size="50" value="<?php echo $data['QC_ADRS']; ?>"></td>
					<td width="59" style='text-align:right'>อำเภอ :</td>
					<td width="125"><input name="QC_DSTRT" type="text" size="20" value="<?php echo $data['QC_DSTRT']; ?>"></td>
					<td width="56" style='text-align:right'>จังหวัด :</td>
					<td width="188"><input name="QC_PRVN" type="text" size="25" value="<?php echo $data['QC_PRVN']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="71" style='text-align:right'>Tel. :</td>
					<td width="90"><input name="QC_TEL" type="text" size="14" value="<?php echo $data['QC_TEL']; ?>"></td>
					<td width="45" style='text-align:right'>Fax. :</td>
					<td width="100"><input name="QC_FAX" type="text" size="14" value="<?php echo $data['QC_FAX']; ?>"></td>
					<td width="100" style='text-align:right'>Proj. :</td>
					<td width="399"><input name="QPJNAME" type="text" size="40" value="<?php echo $data['QPJNAME']; ?>"></td>
				</tr>
			</table>

			<table width="782">
				<tr align="center">
					<td width="82">รายการ</td>
					<td width="234">ชื่อสินค้า</td>
					<td width="129">จำนวน</td>
					<td width="117">ราคาตั้ง</td>
					<td width="82">ส่วนลด</td>
					<td width="110">ราคาขาย</td>
				</tr>

				<tr>
					<td width="82"><input name="QPDNO1" type="text" size="10" value="<?php echo $data['QPDNO1']; ?>"></td>
					<td width="234"><input name="QPDNAME1" type="text" size="35" value="<?php echo $data['QPDNAME1']; ?>"></td>
					<td width="129"><input name="QQTY1" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY1']); ?>"></td>
					<td width="117"><input name="QSLEPRC1" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC1']); ?>"></td>
					<td width="82"><input name="QPDDISC1" type="text" size="12" style="text-align: right" value="<?php $tdisc1 = ($data['QQTY1'] * $data['QSLEPRC1'] * $data['QC_DISC'] / 100);
																													echo number_format($tdisc1, 2); ?>"></td>
					<td width="110" style="text-align: right"><?php $tsle1 = ($data['QQTY1'] * $data['QSLEPRC1'] - $tdisc1);
																echo number_format($tsle1, 2); ?></td>
					<!--<?php $arrQty1 = explode(',', $data['QQTY1']);
						$arrSleprc1 = explode(',', $data['QSLEPRC1']);
						$arrPddisc1 = explode(',', $data['QPDDISC1']);
						foreach ($arrQty1 as $qty1) {
							$q1 .= $qty1;
						}
						foreach ($arrSleprc1 as $sleprc1) {
							$sle1 .= $sleprc1;
						}
						foreach ($arrPddisc1 as $pddisc1) {
							$disc1 .= $pddisc1;
						}
						?>-->
				</tr>

				<tr>
					<td><input name="QPDNO2" type="text" size="10" value="<?php echo $data['QPDNO2']; ?>"></td>
					<td><input name="QPDNAME2" type="text" size="35" value="<?php echo $data['QPDNAME2']; ?>"></td>
					<td><input name="QQTY2" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY2']); ?>"></td>
					<td><input name="QSLEPRC2" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC2']);  ?>"></td>
					<td><input name="QPDDISC2" type="text" size="12" style="text-align: right" value="<?php $tdisc2 = ($data['QQTY2'] * $data['QSLEPRC2'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc2, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle2 = ($data['QQTY2'] * $data['QSLEPRC2'] - $tdisc2);
													echo number_format($tsle2, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO3" type="text" size="10" value="<?php echo $data['QPDNO3']; ?>"></td>
					<td><input name="QPDNAME3" type="text" size="35" value="<?php echo $data['QPDNAME3']; ?>"></td>
					<td><input name="QQTY3" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY3']); ?>"></td>
					<td><input name="QSLEPRC3" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC3']); ?>"></td>
					<td><input name="QPDDISC3" type="text" size="12" style="text-align: right" value="<?php $tdisc3 = ($data['QQTY3'] * $data['QSLEPRC3'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc3, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle3 = ($data['QQTY3'] * $data['QSLEPRC3'] - $tdisc3);
													echo number_format($tsle3, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO4" type="text" size="10" value="<?php echo $data['QPDNO4']; ?>"></td>
					<td><input name="QPDNAME4" type="text" size="35" value="<?php echo $data['QPDNAME4']; ?>"></td>
					<td><input name="QQTY4" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY4']); ?>"></td>
					<td><input name="QSLEPRC4" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC4']); ?>"></td>
					<td><input name="QPDDISC4" type="text" size="12" style="text-align: right" value="<?php $tdisc4 = ($data['QQTY4'] * $data['QSLEPRC4'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc4, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle4 = ($data['QQTY4'] * $data['QSLEPRC4'] - $tdisc4);
													echo number_format($tsle4, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO5" type="text" size="10" value="<?php echo $data['QPDNO5']; ?>"></td>
					<td><input name="QPDNAME5" type="text" size="35" value="<?php echo $data['QPDNAME5']; ?>"></td>
					<td><input name="QQTY5" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY5']); ?>"></td>
					<td><input name="QSLEPRC5" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC5']); ?>"></td>
					<td><input name="QPDDISC5" type="text" size="12" style="text-align: right" value="<?php $tdisc5 = ($data['QQTY5'] * $data['QSLEPRC5'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc5, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle5 = ($data['QQTY5'] * $data['QSLEPRC5'] - $tdisc5);
													echo number_format($tsle5, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO6" type="text" size="10" value="<?php echo $data['QPDNO6']; ?>"></td>
					<td><input name="QPDNAME6" type="text" size="35" value="<?php echo $data['QPDNAME6']; ?>"></td>
					<td><input name="QQTY6" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY6']); ?>"></td>
					<td><input name="QSLEPRC6" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC6']); ?>"></td>
					<td><input name="QPDDISC6" type="text" size="12" style="text-align: right" value="<?php $tdisc6 = ($data['QQTY6'] * $data['QSLEPRC6'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc6, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle6 = ($data['QQTY6'] * $data['QSLEPRC6'] - $tdisc6);
													echo number_format($tsle6, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO7" type="text" size="10" value="<?php echo $data['QPDNO7']; ?>"></td>
					<td><input name="QPDNAME7" type="text" size="35" value="<?php echo $data['QPDNAME7']; ?>"></td>
					<td><input name="QQTY7" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY7']); ?>"></td>
					<td><input name="QSLEPRC7" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC7']);  ?>"></td>
					<td><input name="QPDDISC7" type="text" size="12" style="text-align: right" value="<?php $tdisc7 = ($data['QQTY7'] * $data['QSLEPRC7'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc7, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle7 = ($data['QQTY7'] * $data['QSLEPRC7'] - $tdisc7);
													echo number_format($tsle7, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO8" type="text" size="10" value="<?php echo $data['QPDNO8'];  ?>"></td>
					<td><input name="QPDNAME8" type="text" size="35" value="<?php echo $data['QPDNAME8']; ?>"></td>
					<td><input name="QQTY8" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY8']); ?>"></td>
					<td><input name="QSLEPRC8" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC8']); ?>"></td>
					<td><input name="QPDDISC8" type="text" size="12" style="text-align: right" value="<?php $tdisc8 = ($data['QQTY8'] * $data['QSLEPRC8'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc8, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle8 = ($data['QQTY8'] * $data['QSLEPRC8'] - $tdisc8);
													echo number_format($tsle8, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO9" type="text" size="10" value="<?php echo $data['QPDNO9']; ?>"></td>
					<td><input name="QPDNAME9" type="text" size="35" value="<?php echo $data['QPDNAME9']; ?>"></td>
					<td><input name="QQTY9" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY9']); ?>"></td>
					<td><input name="QSLEPRC9" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC9']); ?>"></td>
					<td><input name="QPDDISC9" type="text" size="12" style="text-align: right" value="<?php $tdisc9 = ($data['QQTY9'] * $data['QSLEPRC9'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc9, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle9 = ($data['QQTY9'] * $data['QSLEPRC9'] - $tdisc9);
													echo number_format($tsle9, 2); ?></td>
				</tr>

				<tr>
					<td><input name="QPDNO10" type="text" size="10" value="<?php echo $data['QPDNO10']; ?>"></td>
					<td><input name="QPDNAME10" type="text" size="35" value="<?php echo $data['QPDNAME10']; ?>"></td>
					<td><input name="QQTY10" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QQTY10']); ?>"></td>
					<td><input name="QSLEPRC10" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSLEPRC10']); ?>"></td>
					<td><input name="QPDDISC10" type="text" size="12" style="text-align: right" value="<?php $tdisc10 = ($data['QQTY10'] * $data['QSLEPRC10'] * $data['QC_DISC'] / 100);
																										echo number_format($tdisc10, 2); ?>"></td>
					<td style="text-align: right"><?php $tsle10 = ($data['QQTY10'] * $data['QSLEPRC10'] - $tdisc10);
													echo number_format($tsle10, 2); ?></td>
				</tr>

				<tr>
					<td></td>
					<td></td>
					<td width="129" style='text-align:right'>รวม :</td>
					<td width="117"><input name="QSUM" type="text" size="17" style="text-align: right" value="<?php echo number_format($data['QSUM']); ?>"></td>
					<td width="82"><input name="QSUMDISC" type="text" size="12" style="text-align: right" value="<?php echo number_format($data['QSUMDISC'], 2); ?>"></td>
					<td align="right"><?php $tsle = ($data['QSUM'] - $data['QSUMDISC']);
										echo number_format($tsle, 2); ?></td>
				</tr>
			</table>

			<table width="833">
				<tr>
					<td width="75" style='text-align:right'>ผู้ขาย :</td>
					<td width="146"><input name="QSMFNAME" type="text" value="<?php echo $data['QSMFNAME']; ?>"></td>
					<td><input name="QSMLNAME" type="text" size="30" value="<?php echo $data['QSMLNAME']; ?>"></td>
				</tr>
			</table>

			<table width="833">
				<tr>
					<td width="75" style='text-align:right'>ยืนราคา :</td>
					<td width="291"><input name="QPRCV" type="text" size="6" style="text-align: right" value="<?php echo $data['QPRCV']; ?>"> วัน </td>
				</tr>
				<tr>
					<td width="75" style='text-align:right'>กำหนดส่ง :</td>
					<td width="291"><input name="QSENT" type="text" size="6" style="text-align: right" value="<?php echo $data['QSENT']; ?>"> วัน </td>
				</tr>

				<tr>
					<td width="75" style="text-align: right">ล่วงหน้า :</td>
					<td width="291"><input name="QTERM1" type="text" size="17" style="text-align: right" value="<?php echo $data['QTERM1']; ?>"> % </td>
				<tr>
				<tr>
					<td width="75" style="text-align: right">คงเหลือ :</td>
					<td width="291"><input name="QTERM2" type="text" size="17" style="text-align: right" value="<?php echo $data['QTERM2']; ?>"> % </td>
				</tr>

				<tr>
					<td width="75" style="text-align: right">กำหนดชำระ :</td>
					<td width="291"><input name="QAFTER" type="text" size="6" style="text-align: right" value="<?php echo $data['QAFTER']; ?>"> วัน </td>
				</tr>

				<tr>
					<td width="75" style="text-align: right">ค่าออกแบบ :</td>
					<td width="291"><input name="QSPEC" type="text" size="8" style="text-align: right" value="<?php echo $data['QSPEC']; ?>"> บาท </td>
					<td width="222"></td>
					<td width="225"></td>
				</tr>

				<tr>
					<td width="75" style='text-align:right'>ผู้ออกแบบ :</td>
					<td width="291"><input name="QSPECNAME" type="text" size="30" value="<?php echo $data['QSPECNAME']; ?>"></td>
				</tr>
			</table>

			<table>
				<tr>
					<td width="75" style='text-align:right'>Note :</td>
					<td width="746"><input name="QNOTE" type="text" size="90" value="<?php echo $data['QNOTE']; ?>"></td>
				</tr>
			</table>

			<table>
				<td><input name="QPDATE" type="hidden" value=""></td>
				<td><input name="QLOCK" type="hidden" value=""></td>
			</table>

			<p>&nbsp;</p>
			<!-- <label>&nbsp :</label>  
  			  <td><button>ส่งข้อมูล</button> &nbsp;&nbsp;<a href="home.php">ย้อนกลับ</a></td> -->
			<td><button>ส่งข้อมูล</button> &nbsp;&nbsp;<a href="actionController.php?action=seller/retrieveQuatationAction">ย้อนกลับ</a></td>
		</form>
	</div>
	<?php include "addOrderForm.php"; ?>
	<!-- </fieldset> -->
</body>

</html>