<!DOCTYPE html>
<html>
    
    <head>
		<?php
		include("../includes/header-links.php");
		?>
    </head>
    
    <body>
        <?php include '../includes/header.php'; ?>
        <div class="container-fluid">
		
            <div class="row-fluid">
                <?php include '../includes/sidebar.php'; ?>
                <!--/span-->
                <div class="span9" id="content">
					

                     <div class="row-fluid">
                        <!-- block -->
                        <div class="block">
						
                            <div class="navbar navbar-inner block-header">
                                <div class="muted pull-left"> <a href="stock.php"><button class="btn btn-warning">Back to stock</button> </a></div>
                                <div class="muted pull-left" > &nbsp&nbsp&nbsp<br> <h4>Stock Reconciliation</h4></div>
                            </div>
                            <div class="block-content collapse in">
							
                              

                            
                                   
                                                                       <?php
                                    include '../includes/connection.php';
                                                                       // Create connection
                                    $sql = mysqli_query($con,"SELECT id, (SELECT product_name from products where id=stock.product_name)as product_name, quantity, buying_price, selling_price, (select symbol from units where UnitID=(select Units from products where id=stock.product_name))as unitf, Actual_quantity from stock where status=1 && branch_id='$branch'");
                                    //$result = mysqli_query($con, $sql);

                                    if (mysqli_num_rows($sql) > 0) {
                                        // output data of each row
    


                                   ?>
        
                                    <table cellpadding="0" cellspacing="0" border="0" class="table  table-bordered" id="example2">
                                        <thead>
                                            <tr>
                                                <th>S/NO</th>
                                                <th>Product Name</th>
                                               
                                                <th>Quantity</th>

                                                <th>Actual Quantity</th>
                                                <th>Action</th>
                                                
                                                

                                            </tr>
                                        </thead>
                                        <tbody>
                                        
                                        <?php
                                        $n=0;
while($row = mysqli_fetch_assoc($sql)) {
	$pid=$row['id'];
  $n++;
 
    ?>
<tr class="gradeU">
   


                                                <td><?php echo $n; ?></td>
                                                <td><?php echo $row['product_name']; ?></td>
                                                <td> 

                                                    <?php echo $row['quantity']." ".$row['unitf']; ?></td>
                                                <td> <?php echo $row['Actual_quantity'];?></td>
                                                    
                                                <td>
                                                    <form method="POST" action="">
                                                     <input type="hidden" value="<?php echo $row['Actual_quantity'];?>" name="actual" >

                                                    <input type="hidden" name="rid" value="<?php echo $pid;?>" required="required">
                                             <input type="number"  name="addm">
                                                <button class="btn btn-primary" type="submit" name="save">Add </button> 
                                            </form>
                                            </td>
                                                
                                                
                                                
                                              
                                       </tr>
                                            
                                            <?php


    }
    ?>
    
                                        </tbody>
                                    </table>
      <?php                              
} else {
    echo "0 results";
}


?>
<div class="form-actions">
                                        <a href="reconcile_fully.php">  <button  class="btn btn-primary">Save Changes </button></a>
                                          
                                        </div>  

<?php
if (isset($_POST['save'])) {
    $rid=$_POST['rid'];
    $actual=$_POST['actual'];
    $addm=$_POST['addm'];
    $newactual=(int)$actual+(int)$addm;
    $updateactual = mysqli_query($con,"UPDATE stock set Actual_quantity='$newactual' where id='$rid' ");
    if ($updateactual) {
        ?>
        <meta http-equiv="refresh" content="0;URL='reconcile.php'" />
        <?php
    }else{
        echo "Error".mysqli_error($con);
    }

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

        <!--==========Footer js======-->
		<?php require_once("../includes/footerjs.php");?>
        <!--==========Footer js======-->
       
    </body>


 
</html>
