<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Seller List</title>
<style>
	td, th {border-left: 1px solid #DBDBDB;
			vertical-align: top;
		   }
	#headq {background: green; color: aliceblue;}
	.wd{
			table-layout: fixed;
			width: 100%;
		}
</style>
</head>

<body>
	<?php
 		
		error_reporting(0);
 		include "pagination.php";   
		include "functions/dblink.php";	   

		$find = "ทั้งหมด";
		$condition = 1;	
		
		//กรณี chkbox แล้วโพสกลับขึ้นมา	
		
		$sql="SELECT * FROM quot002 WHERE (QLOCK=0 OR QLOCK IS NULL) ORDER BY QDATE DESC";
		$result=mysqli_query($con,$sql);
		
		$rs = page_query($con, $sql,17);
	
		$first = page_start_row();
		$last = page_stop_row();
		$total = page_total_rows();
		if($total == 0) {$first = 0;}	
			
		//<a href='form.php?action=insert'>เพิ่มข้อมูล</a>
		echo '<form method="post" name="addOrderForm">';
		echo "<table class='wd'><caption>" ;     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
		echo "<h1>รายการใบเสนอราคา สำหรับออกใบสั่งซื้อ</h1>";
		echo "<h1>(Quotation List for Order)</h1>";
		echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span></caption>";				
					 
		echo "<tr id='headq' >";      //ส่วนหัวตาราง(ชื่อฟิลด์)
		echo "<th width=' 9%'>Act.</th>";
		echo "<th width='10%'>Q.No.</th>";
		echo "<th width='10%'>Q.Date</th>";
		echo "<th width='19%'>name</th>";
		echo "<th width='8%'>% ลด</th>";
		echo "<th width='22%'>Desc.</th>";
		echo "<th width='3%'>Qty</th>";
		echo "<th width='9%'>จำนวน(บาท)</th>";
		echo "<th width='10%'>รวมเงินทั้งสิ้น</th>";
		echo "</tr>";		
	 
		while($data=mysqli_fetch_array($rs))
		{			
			echo "<tr>";
			if($data['QTERM1']>0){
				echo "<td>
						<a href=\"actionController.php?
			                    action=seller/addOrderAction&no={$data['QNO']}\">[เพิ่ม]
					  	</a>
						<a href=\"actionController.php?
									action=seller/addOrderDwnAction&no={$data['QNO']}\">[Dwn]
						</a>
				     </td>";
			}else{
				echo "<td>
						<a href=\"actionController.php?
			                    action=seller/addOrderAction&no={$data['QNO']}\">[เพิ่ม]
					  	</a>	  
				      </td>";
			}
			//echo '<td><input type="checkbox" name="NO[]" value=" ' .$data['NO'].' "></td>';
			//เวลานำไปใช้ $no=$_GET['qno'];
			/*echo "<td><a href=\"page-content/seller/addOrder.php?no={$data['QNO']}\">เพิ่ม</a>
					 </td>";//เวลานำไปใช้ $no=$_GET['no'];*/
			
			$t1=($data['QQTY1']*$data['QSLEPRC1']);
			$t2=($data['QQTY2']*$data['QSLEPRC2']);
			$t3=($data['QQTY3']*$data['QSLEPRC3']);
			$t4=($data['QQTY4']*$data['QSLEPRC4']);
			$t5=($data['QQTY5']*$data['QSLEPRC5']);
			$t6=($data['QQTY6']*$data['QSLEPRC6']);
			$t7=($data['QQTY7']*$data['QSLEPRC7']);
			$t8=($data['QQTY8']*$data['QSLEPRC8']);
			$t9=($data['QQTY9']*$data['QSLEPRC9']);
			$t10=($data['QQTY10']*$data['QSLEPRC10']);
			
		if($data['QC_DISC']<=100){
			$s1=$t1-($t1*$data['QC_DISC']/100);
			$s2=$t2-($t2*$data['QC_DISC']/100);
			$s3=$t3-($t3*$data['QC_DISC']/100);
			$s4=$t4-($t4*$data['QC_DISC']/100);
			$s5=$t5-($t5*$data['QC_DISC']/100);
			$s6=$t6-($t6*$data['QC_DISC']/100);
			$s7=$t7-($t7*$data['QC_DISC']/100);
			$s8=$t8-($t8*$data['QC_DISC']/100);
			$s9=$t9-($t9*$data['QC_DISC']/100);
			$s10=$t10-($t10*$data['QC_DISC']/100);
			$total=$s1+$s2+$s3+$s4+$s5+$s6+$s7+$s8+$s9+$s10;
		}else{
					$s=$t1+$t2+$t3+$t4+$t5+$t6+$t7+$t8+$t9+$t10;
					$total=$s-$data['QC_DISC'];
				}
			
			echo "<td>$data[QNO]</td>";
			echo "<td>$data[QDATE]</td>";
			echo "<td>$data[QC_NAME]</td>";
			echo "<td class=rt>".number_format($data['QC_DISC'],2)."</td>";	
			//echo "<td style='width:15%;'>$data[QC_ADRS]</td>";
			//echo "<td>$data[QPJNAME]</td>";
			echo "<td>$data[QPDNAME1]</td>";
			echo "<td class=rt>".number_format($data['QQTY1'])."</td>";
			echo "<td class=rt>".number_format($data['QSLEPRC1']*$data['QQTY1'])."</td>";
			//echo "<td style='width:7%;' class=rt>".number_format($s1)."</td>";
			echo "<td style='color:red; font-weight: bold;' class=rt>".number_format($total)."</td>";
			echo "<tr>";
			for($i=2;$i<=10;$i++){
				$blank=NULL;
				if ($data{"QPDNAME{$i}"} != "" OR $data{"QQTY{$i}"} != 0 OR $data{"QQTY{$i}"} != is_null($blank)){
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					echo "<td></td>";
					//echo "<td></td>";
					echo "<td>".$data{"QPDNAME{$i}"}."</td>";
					echo "<td class=rt>".number_format($data{"QQTY{$i}"})."</td>";
					echo "<td class=rt>".
						number_format($data{"QSLEPRC{$i}"}*$data{"QQTY{$i}"})."</td>";
					//echo "<td style='width:7%;' class=rt>".number_format($s2)."</td>";
					echo "<tr>";
				}
			}
			echo "<tr>";
			echo "<th width=' 9%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='10%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='10%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='19%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 8%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='22%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 3%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 9%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='10%'><hr color='#DBDBDB' size='.1'></th>";
			echo "</tr>";
		}
		echo "</table>";
		echo "</form>";
		
		//ต่อไปให้แสดงหมายเลขเพจเฉพาะเมื่อมีมากกว่า 1 เพจ 
		if(page_total() > 1)
	    { 	
			echo '<p id="pagenum">';
			page_echo_pagenums();
			echo '</p>';
	    }
		mysqli_close($con);
	?>
</body>
</html>