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

<?php
 					
				$invoice_ref_id = $_GET['invoice_ref_id'];
				
                    $edit_query=mysql_query("select tbl_dir_evendor.vendor_id,tbl_dir_evendor.vendor_name,tbl_dir_fnb_invoice.invoice_ref_id,tbl_dir_fnb_invoice.invoice_date,tbl_dir_fnb_invoice.invoice_amount from tbl_dir_evendor left join tbl_dir_fnb_invoice on  tbl_dir_evendor.vendor_id=tbl_dir_fnb_invoice.vendor_id where tbl_dir_fnb_invoice.invoice_ref_id='$invoice_ref_id'")or die(mysql_error());
					 
                    $row1=mysql_fetch_array($edit_query);
                    $invoice_ref_id=$row1['invoice_ref_id'];
					$vendor_id=$row1['vendor_id'];
					$vendor_name=$row1['vendor_name'];
					
                ?>
				<h2>Add item_id to <?php echo  $invoice_ref_id?><br><?php echo $vendor_name?></h2>
		<?php 
			   $invoice_ref_id = $_REQUEST['invoice_ref_id'];
			   
			    /*$result1 = mysql_query("SELECT  tbl_dir_fnb_quotation.quotation_id,tbl_dir_fnb_item.item_id, tbl_dir_fnb_item.item_description,tbl_dir_fnb_item.item_qty,
					                        tbl_dir_fnb_item.item_unit_price,tbl_dir_fnb_item.item_total,tbl_dir_fnb_item.item_total_value
                                            FROM tbl_dir_fnb_quotation
                                            LEFT JOIN tbl_dir_fnb_item ON tbl_dir_fnb_quotation.quotation_id = tbl_dir_fnb_item.quotation_id where  tbl_dir_fnb_item.item_id=".$item_id);*/  
			  
			   $result1 = mysql_query ("select tbl_dir_evendor.vendor_id,tbl_dir_fnb_invoice.invoice_ref_id,tbl_dir_fnb_invoice.invoice_date,tbl_dir_fnb_invoice.invoice_amount from tbl_dir_evendor left join tbl_dir_fnb_invoice on  tbl_dir_evendor.vendor_id=tbl_dir_fnb_invoice.vendor_id where tbl_dir_fnb_invoice.invoice_ref_id=".$invoice_ref_id);
		     while($row = mysql_fetch_array($result1))
		{
		?>
		<form method="post">
		<table width="56%" style="margin-top:15%" align="center" class="gridtable">
            <tr >
              <td width="100"><div align="center"><strong>Invoice Ref.No</strong></div></td-->
              <td width="64"><div align="center"><strong>Date</strong></div></td>
              <td width="84"><div align="center"><strong>Amount</strong></div></td>
            </tr>
            <tr>
			<td><label><?php echo  $row['invoice_ref_id']; ?></label></td>
              <td><div align="center">
                <label class="control-label" for="invoice_date"><input type="text" size="10" maxlength="10" id="invoice_date" name="invoice_date" value="<?php echo  $row['invoice_date']; ?>"></label>
              </div></td>
              <td><div align="center">
                <input type="text" size="5" maxlength="10" name="invoice_amount" value="<?php echo  $row['invoice_amount']; ?>">
              </div></td>
              <!--td><div align="center">
                <input type="text" size="10" maxlength="10" name="item_unit_price" value="<!?php echo  $row['item_unit_price']; ?>">
              </div></td-->
            </tr>
          </table>
		            
						
					<tr><td colspan=2><center><button name="save" class="button">Update</button> &nbsp;<button name="save" on class="button">Back</button>
					</center></td></tr>
			 </fieldset>
                </form>
            </div>
        </div>

<?php } ?>
<?php
                if (isset($_POST['save'])){

                    $invoice_date=$_POST['invoice_date'];
                            $invoice_amount=$_POST['invoice_amount'];
					 //$item_unit_price=$_POST['item_unit_price'];
					 //$item_total=$item_qty*$item_unit_price;
                   

                    $result3=mysql_query("update tbl_dir_fnb_invoice set invoice_date='$invoice_date',
                        invoice_amount='$invoice_amount'
                        where invoice_ref_id='$invoice_ref_id' ")or die(mysql_error());
				
		 
		 if ($result3){
		 		echo "<script language='javascript'>window.location='vendor_fnb_invoice.php?vendor_id=$vendor_id'</script>";}
			else{
				echo 'Unsuccessful, please try again';}
    }     
            ?>
</body>
