<!DOCTYPE html>
<?php 
$newid=$_GET['id'];
$staffcode=$_GET['staffcode'];
?>
<html>
    
    <head>
        <title>Tables</title>
        <!-- Bootstrap -->
        <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="../bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
        <link href="../assets/styles.css" rel="stylesheet" media="screen">
        <link href="../assets/DT_bootstrap.css" rel="stylesheet" media="screen">
        <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
        <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <script src="../vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span5" id="content">

                        <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left">Orders</div>
                                <div class="muted pull-right"><button class="btn btn-primary"> Process Order</button></div>
                            </div>
                            <div class="block-content collapse in">
                                <div class="span12">
                                    <?php
include '../includes/connection.php';


$sql = "SELECT id,unit_price,  (select product_name from products where id=temp.product_id)as product_name, quantity, (select price from products where id=temp.product_id)as unit from temp where branch_id='$branch'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
   ?>
  									<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
										<thead>
											<tr>
												<th>Id</th>
												<th>Product Name</th>
												<th>Quantity</th>
												<th>Unit Price</th>
												<th>Total Price</th>
                                                <th>Action</th>
											</tr>
										</thead>
										<tbody>
                                        <?php
                                         // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        ?>
        <tr class="odd gradeX">
        
                                                <td><?php echo $row['id']; ?></td>
                                                <td><?php echo $row['product_name']; ?></td>
                                                <td><?php echo $row['quantity']; ?></td>
                                                <td class="center"> <?php echo $row['unit_price']; ?></td>
                                                <td class="center"><?php echo $row['unit_price']*$row['quantity']; ?></td>
                                                <td class="center">
                                                    
                                                </td>
                                            </tr>
                                            <?php
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>
											
											
										</tbody>
									</table>
                                </div>
                            </div>
                        </div>
                        <!-- /block -->
                    </div>

         
                </div>
                <div class="span4">
                <?php include 'edit_values.php'; ?>
                                     <form class="form-horizontal" action="" method="POST"> 
                                      <fieldset>
                                        <legend>Edit Order</legend>
                                        <div class="control-group">
                                          <label class="control-label" for="selectError">Product</label>
                                          <div class="controls">
                                          <input class="input-xlarge focused" name="product" id="focusedInput" type="text" value="<?php echo $prod_name; ?>" readonly>
                                          <input type="hidden" name="product_id" value="<?php echo $prod_id; ?>">

                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label"  for="focusedInput">Quantity</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" name="quantity" min="0.25" id="focusedInput" type="number" value="<?php echo $qty; ?>" step="any">
                                          </div>
                                        </div>
                                        <div class="control-group">
                                          <label class="control-label"  for="focusedInput">Unit Price</label>
                                          <div class="controls">
                                            <input class="input-xlarge focused" name="unitprice" id="focusedInput" type="number" value="<?php echo $unitprice; ?>">
                                          </div>
                                        </div>
                                       
                                        
                                        <div class="form-actions">
                                          <button type="submit" class="btn btn-primary" name="update"><i class="icon-plus "></i>Update</button>
                                          <a href="new_order.php"><button type="submit" class="btn">Cancel</button></a>
                                        </div>
                                      </fieldset>
                                    </form>
                                    <?php
                                        include '../includes/connection.php';

                                        if(isset($_POST['update'])){
                                            $productid=$_POST['product_id'];
                                            $product=$_POST['product'];
                                            $quantity=$_POST['quantity'];
                                            $unitpricex=$_POST['unitprice'];
                                            // Create connection
                                       

                                        $sql = " UPDATE temp set quantity='$quantity', unit_price='$unitpricex' where id='$id'";
                                    

                                        if (mysqli_query($conn, $sql)) {
                                           ?><meta http-equiv="refresh" content="0;URL='new_order.php?staffcode=<?php echo $staffcode; ?>'" /><?php
                                        } else {
                                            echo "Error: " . $sql . "<br>" . mysqli_error($conn);
                                        }

                                        mysqli_close($conn);
                                        }
                                        
                                        ?>

                                </div>
            </div>
            <hr>
            <?php include '../includes/footer.php'; ?>
        </div>
        <!--/.fluid-container-->

        <script src="../vendors/jquery-1.9.1.js"></script>
        <script src="../bootstrap/js/bootstrap.min.js"></script>
        <script src="../vendors/datatables/js/jquery.dataTables.min.js"></script>


        <script src="../assets/scripts.js"></script>
        <script src="../assets/DT_bootstrap.js"></script>
        <script>
        $(function() {
            
        });
        </script>
    </body>

</html>