<!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 OR OLOCK='' OR OLOCK IS NULL) 
		               ORDER BY ODATE DESC,ONO DESC";
	
		$result=mysqli_query($con,$sql);
		$rs = page_query($con, $sql, 20);
	
		$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">';
		echo "<table class='wd'><caption>" ;     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
		echo "<h1>รายการใบสั่งซื้อ สำหรับออกใบส่งสินค้า</h1>";
		echo "<h1>(Order List for Delivery)</h1>";
		echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span></caption>";				
					 
		echo "<tr id='headq' >";      //ส่วนหัวตาราง(ชื่อฟิลด์)
		echo "<th width='4%'>Act.</th>";
		echo "<th width='9%'>วันที่</th>";
		echo "<th width='9%'>Ord.No.</th>";
		echo "<th width='13%'>name</th>";
		echo "<th width='8%'>ส่วนลด</th>";
		echo "<th width='9%'>Proj. Name</th>";
		echo "<th width='19%'>รายการ</th>";
		echo "<th width='3%'>#</th>";
		echo "<th width='7%'>@</th>";
	    echo "<th width='9%'>บาท</th>";
		echo "<th width='10%'>ทั้งสิ้น</th>";
		echo "</tr>";		
	 
		while($data=mysqli_fetch_array($rs))
		{			
			echo "<tr>";
			echo "<td><a href=\"actionController.php?
			                    action=seller/addDeliveryAction&ono={$data['ONO']}&olost={$data['OLOST']}&
								actionIs=insert\">[เพิ่ม]</a>
					</td>";
			
			$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'];
			
		if($data['OQC_DISC']<=100){	
			$s1=($t1)-($t1*$data['OQC_DISC']/100);
			$s2=($t2)-($t2*$data['OQC_DISC']/100);
			$s3=($t3)-($t3*$data['OQC_DISC']/100);
			$s4=($t4)-($t4*$data['OQC_DISC']/100);
			$s5=($t5)-($t5*$data['OQC_DISC']/100);
			$s6=($t6)-($t6*$data['OQC_DISC']/100);
			$s7=($t7)-($t7*$data['OQC_DISC']/100);
			$s8=($t8)-($t8*$data['OQC_DISC']/100);
			$s9=($t9)-($t9*$data['OQC_DISC']/100);
			$s10=($t10)-($t10*$data['OQC_DISC']/100);
			$total=$s1+$s2+$s3+$s4+$s5+$s6+$s7+$s8+$s9+$s10;
		}else{
			$s1=($t1);
			$s2=($t2);
			$s3=($t3);
			$s4=($t4);
			$s5=($t5);
			$s6=($t6);
			$s7=($t7);
			$s8=($t8);
			$s9=($t9);
			$s10=($t10);
			$s=$t1+$t2+$t3+$t4+$t5+$t6+$t7+$t8+$t9+$t10;
			$total=$s-$data['OQC_DISC'];
				}

			echo "<td>$data[ODATE]</td>";
			echo "<td>$data[ONO]</td>";
			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>";
				
		if($data['OLOST']=='Dwn'){
			echo "<td>".number_format($data['OQTERM1'])."%</td>";
			echo "<td>DwnP</td>";
			echo "<td class=rt>".number_format(($total * $data['OQTERM1']/100),2). "</td>";
		}else{		
			echo "<td class=rt>".number_format($data['OQSLEPRC1'])."</td>";
			echo "<td class=rt>".number_format($s1,2)."</td>";
			echo "<td class=rt style='color:red; font-weight: bold;'>".number_format($total,2)."</td>";
			echo "<tr>";
			
			//$data{"QPDNAME{$i}"}; ${"tsle{$i}"}
			for($i=2;$i<=10;$i++){
				$blank=NULL;
				if ($data{"OQPDNAME{$i}"} != "" OR $data{"OQQTY{$i}"} != 0 OR $data{"OQQTY{$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{"OQPDNAME{$i}"}."</td>";
					echo "<td class=rt>".number_format($data{"OQQTY{$i}"})."</td>";
					echo "<td class=rt>".number_format($data{"OQSLEPRC{$i}"})."</td>";
					echo "<td class=rt>".number_format(${"s{$i}"},2)."</td>";
					echo "<tr>";
				}
			}
			
		}



			echo "<tr>";
			echo "<th width=' 4%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 9%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 9%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='13%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 8%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 9%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width='19%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 3%'><hr color='#DBDBDB' size='.1'></th>";
			echo "<th width=' 7%'><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>