<?php session_start();?>
<?php require_once('open_connection.php');?>
<link href='css/imagetable.css' rel='stylesheet' type='text/css' />
<link href="css/gridtable.css" rel="stylesheet" type="text/css" />

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
	<script src="//code.jquery.com/jquery-1.10.2.js"></script>
	<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
	<link rel="stylesheet" href="/resources/demos/style.css">
	<script>
	$(function() {
		$("#invoice_date").datepicker({ dateFormat: 'yy-mm-dd' });
		$( "#format" ).change(function() {
		 var minValue = $(this).val();
		  minValue = $.datepicker.parseDate("yy-mm-dd", minValue);
            minValue.setDate(minValue.getDate()+1);
			$( "#invoice_date").datepicker( "option", "dateFormat", $( this ).val() );
		});
	});
	</script>  
	<script type="text/javascript">
		function validateForm(oForm)
		{
			var reinvoice_amount = /\d+/gi;
			//var reitem_unit_price = /\d+/gi;
			if(!reinvoice_amount.test(oForm.invoice_amount.value))
			{
				alert("Please key in price in the invoice amount");
				return false;
			}
			return true;
		}
		</script>
		
		
<?php
       $vendor_id = $_GET['vendor_id'];	 
	    //$vendor_name = $_GET['vendor_name'];	
		     $vendor = "select * from tbl_dir_evendor where vendor_id='$vendor_id'";
		  $result = mysql_query($vendor);
			 $row = mysql_fetch_array($result);
	   $vendor_id = $row['vendor_id'];	
	   $vendor_name = $row['vendor_name'];	
	   
	   echo  $vendor_id;
	   echo $vendor_name
		?>

<!DOCTYPE html>
<html>
<head>
      <title>PICCSB e-Directory System</title>

</head>
<body bgcolor="#333333"> 
<table width="100%" border="0" align="center">
<tr>
<td width="15%" bgcolor="#333333">&nbsp;</td>
<td width="70%" align="center" bgcolor="#FFFFFF" > 

<table width="100%" border="0" align="center">

<!-- row for header picc 1 -->
<tr>  
     <th width="100%" colspan="4"><img src="images/header-cox.jpg" width="100%" height="30%"></th>
</tr>

<!-- row for header picc 2 -->
<tr>
     <th width="100%" colspan="4"><img src="images/eoffice-cox.jpg" width="100%" height="15%"></th>
</tr>
<!-- calling frame -->	
<tr>
    <td colspan="1" width="10%" align="center"><?php include("header.php");?></td>
	
</tr>
<tr>

<td colspan="3" width="90%" align="center" >
<tr><td>&nbsp;</td></tr>
<tr><td align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<?php
								echo 'Welcome: ' . $_SESSION['username'];
								?>
							<a href="vendor_AdminSection_login.php"><img src="images/logout3.gif" align="right"></a>

							</td>
</tr>
<tr><td>
<!--h2 align="center">STAFF ADMIN PAGE</h2-->

<form method="post" onSubmit="return validateForm(this);">
<table align="center" class="gridtable" >
<tr>
		  		<th width="20%" scope="col">Vendor </th>
		  		<th width="20%" scope="col">Invoice Ref.No</th>
          		<th width="20%" scope="col">Date<br />(YYYY-MM-DD)</th>
		  		<th width="20%" scope="col">Amount</th>
			<!--th width="21%" scope="col">Quotation No: </th-->
               </tr>
			   <tr>
		  			<td><label><?php echo $row['vendor_name']?></label></td>
		  			<td><input type="text" value="<?php echo htmlentities($_REQUEST['invoice_ref_id']); ?>" name="invoice_ref_id"required></td>
           	 		<td>
			 		<label class="control-label" for="invoice_date"><input type="text" id="invoice_date"  value="<?php echo htmlentities($_REQUEST['invoice_date']); ?>" name=		                    "invoice_date"required></label>
					</td>
					<td><input type="text" value="<?php echo htmlentities($_REQUEST['invoice_amount']); ?>" name="invoice_amount"required></td>
			
          		</tr>
</table><div align="center"><button name="save" class="button">Save</button>
		<input type="button" value = "Back" onClick="history.go(-1);return true;" class="button">
		<input type="button" value = "Vendor's List" onClick="window.location.href='vendor_fnb_view.php'" class="button"></div>
</form>
<br>

<!--hr /-->
<div align="right">
<form method="post">
<?php
            if (isset($_POST['save'])){
			            
			                  $vendor_id=$row['vendor_id'];
							  //$vendor_name=$_POST['vendor_name'];
					   $invoice_ref_id=$_POST['invoice_ref_id'];
				        $invoice_date =$_POST['invoice_date'];
				      $invoice_amount =$_POST['invoice_amount'];   
					  
					  $query = mysql_query("SELECT * FROM tbl_dir_fnb_invoice WHERE invoice_ref_id = '". $invoice_ref_id ."' "); 
						if (mysql_num_rows($query) > 0) 
						{ 
     						echo 'Invoice with the same reference no already exist.'; 
						}
						else
						{
				             $Quo="insert into tbl_dir_fnb_invoice (invoice_ref_id,vendor_id,invoice_date,invoice_amount) 
                  				   values ('$invoice_ref_id','$vendor_id','$invoice_date','$invoice_amount')";
		
			$result= mysql_query($Quo);
		 
		 if ($result){
		 		echo "<script language='javascript'>window.location='vendor_fnb_invoice.php?vendor_id=$vendor_id'</script>";}
			else{
				echo 'Unsuccessful, please try again';}
    }     
	}
?>
<?php

			$rowsPerPage =10; 
				$pageNum = $_REQUEST['page']; 
				if(empty($pageNum))
						{
					$offset =0;
					$pageNum=1;
						}
				else
						{
					$offset = ($pageNum - 1) * $rowsPerPage;
						}	
					$result3=mysql_query("SELECT * from tbl_dir_fnb_invoice WHERE vendor_id='$vendor_id' ORDER BY invoice_ref_id ASC  LIMIT $offset, $rowsPerPage");
		            $i=$offset;
					echo "<center><table border=1 align=center class=gridtable>";
					echo"<tr><th  width=60>No</th><th  width=150>invoice_ref_id</th><th width=150>Date</th><th width=150>Amount</th><th width=100 colspan=1>Action</th>
						 </tr>";
						
					while(@$row1=mysql_fetch_array($result3))
						{
				    $invoice_ref_id=$row1['invoice_ref_id'];
					//$vendor_name = $row1['vendor_name'];
		 	            $vendor_id = $row['vendor_id'];
		             $invoice_date = $row1['invoice_date'];
		           $invoice_amount = $row1['invoice_amount'];
			 	 
					$i++;
					echo"<tr>";
					echo "<td align= center >".$i."</td>";
					//echo"<td width=100 align=center><a href='untitled3.php?quotation_id=".$row1['quotation_id']."'>".$row1['quotation_id']."</a></td>";
					echo "<td align=center width=100>".$row1['invoice_ref_id']."</td>";
					echo "<td align=center width=100>".$row1['invoice_date']."</td>";
					echo "<td align=center width=100>".$row1['invoice_amount']."</td>";	
					
					echo"<td align=center width=200> <a href='fnb_edit_invoice.php?invoice_ref_id=".$row1['invoice_ref_id']."'>EDIT</a>
						 <a href='fnb_delete_invoice.php?invoice_ref_id=".$row1['invoice_ref_id']."'>DELETE</a></td>";
					echo"</tr>";
					echo"<tr>";
						}			
					echo "</table>";				
 ?>
 
</form> 
  <!--tr><td>
   <div id="divButtons" name="divButtons" align="center">
<input type="button" value = "Print this page" onclick="printPage()" style="font:bold 11px verdana;color:#FF0000;background-color:#FFFFFF;"> &nbsp;
<input type="button" value = "Back" onClick="history.go(-1);return true;" style="font:bold 11px verdana;color:#FF0000;background-color:#FFFFFF;">
  </td></tr-->
  
  </div>
  </td></tr>
<!-- row for footer -->	
<tr>
	<th align="center" colspan="4">
	<?php include('footer.php');?>
		
	</th>
</tr>

<!--- end for ruang kerja 80% -->
</table>

</td>

<td width="20%" bgcolor="#333333">&nbsp;</td>

</tr>

<!--- end for ruang kerja 100% -->
</table>

</body>
</html>

