<!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 invc001 WHERE ILOCK=0 ORDER BY IDATE 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">';
		echo "<table class='wd'><caption>" ;     //อ่านข้อมูล result set มาแสดงในรูปแบบตาราง
		echo "<h1>รายการใบแจ้งหนี้(Invoice List for Delivery)</h1>";
		echo "<span id=\"result\">รายการที่ : $first - $last จากทั้งหมด $total</span></caption>";				
					 
		echo "<tr id='headq' >";      //ส่วนหัวตาราง(ชื่อฟิลด์)
		echo "<th style='width:5%;'>Add Deliv</th>";
		//echo "<th style='width:8%;'>action</th>";
		echo "<th id='QC_NAME' style='width:17%;'>name</th>";
		echo "<th id='QC_DISC' style='width:5%;'>% ลด</th>";
		echo "<th id='QC_ADRS' style='width:15%;'>ที่อยู่</th>";
		echo "<th id='QPJNAME' style='width:15%;'>Proj. Name</th>";
		echo "<th id='QPDNAME' style='width:15%;'>รายการ</th>";
		echo "<th id='QQTY' style='width:5%;'>จำนวน</th>";
		echo "<th id='QSLEPRC' style='width:7%;'>@</th>";
	    echo "<th id='QSLEPRC' style='width:7%;'>รวม</th>";
		echo "<th id='QSLEPRC' style='width:10%;'>ทั้งสิ้น</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/addDeliveryAction&no={$data['INO']}\">เพิ่ม</a>
					</td>";//เวลานำไปใช้ $no=$_GET['no'];
			/*echo "<td><a href=\"page-content/seller/addOrder.php?no={$data['NO']}\">เพิ่ม</a>
					 </td>";//เวลานำไปใช้ $no=$_GET['no'];*/
			$t1=($data[IDQTY1]*$data[IDSLEPRC1]);
			$t2=($data[IDQTY2]*$data[IDSLEPRC2]);
			$t3=($data[IDQTY3]*$data[IDSLEPRC3]);
			$t4=($data[IDQTY4]*$data[IDSLEPRC4]);
			$t5=($data[IDQTY5]*$data[IDSLEPRC5]);
			$t6=($data[IDQTY6]*$data[IDSLEPRC6]);
			$t7=($data[IDQTY7]*$data[IDSLEPRC7]);
			$t8=($data[IDQTY8]*$data[IDSLEPRC8]);
			$t9=($data[IDQTY9]*$data[IDSLEPRC9]);
			$t10=($data[IDQTY10]*$data[IDSLEPRC10]);
			
			$s1=($data[IDQTY1]*$data[IDSLEPRC1])-(($data[IDQTY1]*$data[IDSLEPRC1])*$data[IDC_DISC]/100);
			$s2=($data[IDQTY2]*$data[IDSLEPRC2])-(($data[IDQTY2]*$data[IDSLEPRC2])*$data[IDC_DISC]/100);
			$s3=($data[IDQTY3]*$data[IDSLEPRC3])-(($data[IDQTY3]*$data[IDSLEPRC3])*$data[IDC_DISC]/100);
			$s4=($data[IDQTY4]*$data[IDSLEPRC4])-(($data[IDQTY4]*$data[IDSLEPRC4])*$data[IDC_DISC]/100);
			$s5=($data[IDQTY5]*$data[IDSLEPRC5])-(($data[IDQTY5]*$data[IDSLEPRC5])*$data[IDC_DISC]/100);
			$s6=($data[IDQTY6]*$data[IDSLEPRC6])-(($data[IDQTY6]*$data[IDSLEPRC6])*$data[IDC_DISC]/100);
			$s7=($data[IDQTY7]*$data[IDSLEPRC7])-(($data[IDQTY7]*$data[IDSLEPRC7])*$data[IDC_DISC]/100);
			$s8=($data[IDQTY8]*$data[IDSLEPRC8])-(($data[IDQTY8]*$data[IDSLEPRC8])*$data[IDC_DISC]/100);
			$s9=($data[IDQTY9]*$data[IDSLEPRC9])-(($data[IDQTY9]*$data[IDSLEPRC9])*$data[IDC_DISC]/100);
			$s10=($data[IDQTY10]*$data[IDSLEPRC10])-(($data[IDQTY10]*$data[IDSLEPRC10])*$data[IDC_DISC]/100);
				
			$total=$s1+$s2+$s3+$s4+$s5+$s6+$s7+$s8+$s9+$s10;
			
			echo "<td style='width:17%;'>$data[IDC_NAME]</td>";
			echo "<td style='width:5%;' class=rt>$data[IDC_DISC]</td>";	
			echo "<td style='width:15%;'>$data[IDC_ADRS]</td>";
			echo "<td style='width:15%;'>$data[IDPJNAME]</td>";
			echo "<td style='width:15%;'>$data[IDPDNAME1]</td>";
			echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY1])."</td>";
			echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC1])."</td>";
			echo "<td style='width:7%;' class=rt>".number_format($s1)."</td>";
			echo "<td style='width:10%; color:red; font-weight: bold;' class=rt>".number_format($total)."</td>";
			echo "<tr>";
			if ($data[IDPDNAME2] != "" & $data[IDQTY2] != 0){
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME2]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY2])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC2])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($s2)."</td>";
				echo "<tr>";
			}
				
			if($data[IDPDNAME3] != "" & $data[IDQTY3] != 0){
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";				
				echo "<td style='width:15%;'>$data[IDPDNAME3]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY3])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC3])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($s3)."</td>";
				echo "<tr>";
			}			
		if($data[IDPDNAME4] != "" & $data[IDQTY4] != 0){
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";			
				echo "<td style='width:15%;'>$data[IDPDNAME4]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY4])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC4])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($s4)."</td>";
			    echo "<tr>";
		}
				
		if($data[IDPDNAME5] != "" & $data[IDQTY5] != 0){	
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";	
				echo "<td style='width:15%;'>$data[IDPDNAME5]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY5])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC5])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($s5)."</td>";
			    echo "<tr>";
		} 
				
		if($data[IDPDNAME6] != "" & $data[IDQTY6] != 0){	
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME6]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY6])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC6])."</td>";
			    echo "<td style='width:7%;' class=rt>".number_format($s6)."</td>";
				echo "<tr>";
		}
		if($data[IDPDNAME7] != "" & $data[IDQTY7] != 0){	
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME7]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY7])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC7])."</td>";
			    echo "<td style='width:7%;' class=rt>".number_format($s7)."</td>";
				echo "<tr>";
		}
		if($data[IDPDNAME8] != "" & $data[IDQTY8] != 0){		
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME8]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY8])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC8])."</td>";
			    echo "<td style='width:7%;' class=rt>".number_format($s8)."</td>";
				echo "<tr>";
		}
		if($data[IDPDNAME9] != "" & $data[IDQTY9] != 0){		
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME9]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY9])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC9])."</td>";
			    echo "<td style='width:7%;' class=rt>".number_format($s9)."</td>";
				echo "<tr>";
		}
		if($data[IDPDNAME10] != "" & $data[IDQTY10] != 0){		
				echo "<td style='width:5%;'></td>";
				//echo "<td style='width:8%;'></td>";
				echo "<td style='width:17%;'></td>";
				echo "<td style='width:5%;'></td>";
			    echo "<td style='width:15%;'></td>";
			    echo "<td style='width:15%;'></td>";
				echo "<td style='width:15%;'>$data[IDPDNAME10]</td>";
				echo "<td style='width:5%;' class=rt>".number_format($data[IDQTY10])."</td>";
				echo "<td style='width:7%;' class=rt>".number_format($data[IDSLEPRC10])."</td>";
				echo "<td style='width:7%;' 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>