<!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 ordr001 WHERE OLOCK=0 ORDER BY ODATE 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="addInvoiceForm">';
		echo "<table class='wd'><caption>" ;     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
		echo "<h1>รายการใบสั่งซื้อสินค้า(Order List for Invoice)</h1>";
		echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span></caption>";				
					 
		echo "<tr id='headq' >";      //ส่วนหัวตาราง(ชื่อฟิลด์)
		echo "<th>Add Inv</th>";
		//echo "<th style='width:8%;'>action</th>";
		echo "<th id='QC_NAME'>name</th>";
		echo "<th id='QC_DISC'>ส่วนลด</th>";
		echo "<th id='QC_ADRS'>ที่อยู่</th>";
		echo "<th id='QPJNAME'>Proj. Name</th>";
		echo "<th id='QPDNAME'>รายการ</th>";
		echo "<th id='QQTY'>จำนวน</th>";
		echo "<th id='QSLEPRC'>บาท/หน่วย</th>";
	    echo "<th id='QSLEPRC'>รวม(บาท)</th>";
		echo "<th id='QSLEPRC'>ทั้งสิ้น</th>";
		echo "</tr>";		
	 
		while($data=mysqli_fetch_array($rs))
		{			
			echo "<tr>";
			//echo '<td><input type="checkbox" name="NO[]" value=" ' .$data['NO'].' "></td>';
			echo "<td><a href=\"actionController.php?
			                                        action=seller/addInvoiceAction&no={$data['ONO']}\">เพิ่ม</a>
					</td>";//เวลานำไปใช้ $no=$_GET['no'];
			/*echo "<td><a href=\"page-content/seller/addOrder.php?no={$data['NO']}\">เพิ่ม</a>
					 </td>";//เวลานำไปใช้ $no=$_GET['no'];*/
			
			$t1=($data['OQQTY1']*$data['OQSLEPRC1']);
			$t2=($data['OQQTY2']*$data['OQSLEPRC2']);
			$t3=($data['OQQTY3']*$data['OQSLEPRC3']);
			$t4=($data['OQQTY4']*$data['OQSLEPRC4']);
			$t5=($data['OQQTY5']*$data['OQSLEPRC5']);
			$t6=($data['OQQTY6']*$data['OQSLEPRC6']);
			$t7=($data['OQQTY7']*$data['OQSLEPRC7']);
			$t8=($data['OQQTY8']*$data['OQSLEPRC8']);
			$t9=($data['OQQTY9']*$data['OQSLEPRC9']);
			$t10=($data['OQQTY10']*$data['OQSLEPRC10']);
			
			$s1=($data['OQQTY1']*$data['OQSLEPRC1'])-(($data['OQQTY1']*$data['OQSLEPRC1'])*$data['OQC_DISC']/100);
			$s2=($data['OQQTY2']*$data['OQSLEPRC2'])-(($data['OQQTY2']*$data['OQSLEPRC2'])*$data['OQC_DISC']/100);
			$s3=($data['OQQTY3']*$data['OQSLEPRC3'])-(($data['OQQTY3']*$data['OQSLEPRC3'])*$data['OQC_DISC']/100);
			$s4=($data['OQQTY4']*$data['OQSLEPRC4'])-(($data['OQQTY4']*$data['OQSLEPRC4'])*$data['OQC_DISC']/100);
			$s5=($data['OQQTY5']*$data['OQSLEPRC5'])-(($data['OQQTY5']*$data['OQSLEPRC5'])*$data['OQC_DISC']/100);
			$s6=($data['OQQTY6']*$data['OQSLEPRC6'])-(($data['OQQTY6']*$data['OQSLEPRC6'])*$data['OQC_DISC']/100);
			$s7=($data['OQQTY7']*$data['OQSLEPRC7'])-(($data['OQQTY7']*$data['OQSLEPRC7'])*$data['OQC_DISC']/100);
			$s8=($data['OQQTY8']*$data['OQSLEPRC8'])-(($data['OQQTY8']*$data['OQSLEPRC8'])*$data['OQC_DISC']/100);
			$s9=($data['OQQTY9']*$data['OQSLEPRC9'])-(($data['OQQTY9']*$data['OQSLEPRC9'])*$data['OQC_DISC']/100);
			$s10=($data['OQQTY10']*$data['OQSLEPRC10'])-(($data['OQQTY10']*$data['OQSLEPRC10'])*$data['OQC_DISC']/100);
				
			$total=$s1+$s2+$s3+$s4+$s5+$s6+$s7+$s8+$s9+$s10;
			
			echo "<td>$data[OQC_NAME]</td>";
			echo "<td class=rt>$data[OQC_DISC]</td>";	
			echo "<td>$data[OQC_ADRS]</td>";
			echo "<td>$data[OQPJNAME]</td>";
			echo "<td>$data[OQPDNAME1]</td>";
			echo "<td class=rt>".number_format($data['OQQTY1'])."</td>";
			echo "<td class=rt>".number_format($data['OQSLEPRC1'])."</td>";
			echo "<td class=rt>".number_format($s1)."</td>";
			echo "<td class=rt; color:red; font-weight: bold;>".number_format($total)."</td>";
			echo "<tr>";
			if ($data['OQPDNAME2'] != "" & $data['OQQTY2'] != 0){
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME2]</td>";
				echo "<td class=rt>".number_format($data['OQQTY2'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC2'])."</td>";
				echo "<td class=rt>".number_format($s2)."</td>";
				echo "<tr>";
			}
				
			if($data['OQPDNAME3'] != "" OR $data['OQQTY3'] != 0){
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";				
				echo "<td>$data[OQPDNAME3]</td>";
				echo "<td class=rt>".number_format($data['OQQTY3'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC3'])."</td>";
				echo "<td class=rt>".number_format($s3)."</td>";
				echo "<tr>";
			}			
		if($data['OQPDNAME4'] != "" & $data['OQQTY4'] != 0){
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";			
				echo "<td>$data[OQPDNAME4]</td>";
				echo "<td class=rt>".number_format($data['OQQTY4'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC4'])."</td>";
				echo "<td class=rt>".number_format($s4)."</td>";
			   echo "<tr>";
		}
				
		if($data['OQPDNAME5'] != "" & $data['OQQTY5'] != 0){	
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";	
				echo "<td>$data[OQPDNAME5]</td>";
				echo "<td class=rt>".number_format($data['OQQTY5'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC5'])."</td>";
				echo "<td class=rt>".number_format($s5)."</td>";
			   echo "<tr>";
		} 
				
		if($data['OQPDNAME6'] != "" & $data['OQQTY6'] != 0){	
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME6]</td>";
				echo "<td class=rt>".number_format($data['OQQTY6'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC6'])."</td>";
			   echo "<td class=rt>".number_format($s6)."</td>";
				echo "<tr>";
		}
		if($data['OQPDNAME7'] != "" & $data['OQQTY7'] != 0){	
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME7]</td>";
				echo "<td class=rt>".number_format($data['OQQTY7'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC7'])."</td>";
			   echo "<td class=rt>".number_format($s7)."</td>";
				echo "<tr>";
		}
		if($data['OQPDNAME8'] != "" & $data['OQQTY8'] != 0){		
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME8]</td>";
				echo "<td class=rt>".number_format($data['OQQTY8'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC8'])."</td>";
			   echo "<td class=rt>".number_format($s8)."</td>";
				echo "<tr>";
		}
		if($data['OQPDNAME9'] != "" & $data['OQQTY9'] != 0){		
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME9]</td>";
				echo "<td class=rt>".number_format($data['OQQTY9'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC9'])."</td>";
			   echo "<td class=rt>".number_format($s9)."</td>";
				echo "<tr>";
		}
		if($data['OQPDNAME10'] != "" & $data['OQQTY10'] != 0){		
				echo "<td></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td></td>";
				echo "<td></td>";
			   echo "<td></td>";
			   echo "<td></td>";
				echo "<td>$data[OQPDNAME10]</td>";
				echo "<td class=rt>".number_format($data['OQQTY10'])."</td>";
				echo "<td class=rt>".number_format($data['OQSLEPRC10'])."</td>";
				echo "<td class=rt>".number_format($s10)."</td>";
				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>