<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/cartfunctions.php');
include ('../inc/repfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){   
    $aid=$_SESSION['uid'];
    $brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
?>
<?php if(isset($_POST['pdetails'])){ 
$id = $_POST['id'];
$sql= "SELECT tbl_item.id,tbl_item.code,tbl_item.name,tbl_item.modelno,tbl_item.wday,tbl_item.description,tbl_brand.name AS brand FROM tbl_item LEFT JOIN tbl_brand ON tbl_brand.id=tbl_item.brid WHERE tbl_item.id='$id'";
$result = mysqli_query($con,$sql) or die(mysqli_error($con));
$row = mysqli_fetch_array($result);                                    
?>
<div class="col-md-12 form-group">
    <table class="table table-bordered table-striped">
        <tr>
            <td width="150"><label>Name:</label></td>
            <td colspan="3"><?php echo $row['name'];?></td>
        </tr>
        <tr>
            <td width="150"><label>Brand:</label></td>
            <td colspan="3"><?php echo $row['brand'];?></td>
        </tr>
        
        <tr>
            <td width="150"><label>Model No:</label></td>
            <td colspan="3"><?php echo $row['modelno'];?></td>
        </tr>
        <tr>
            <td width="150"><label>Warranty Days:</label></td>
            <td colspan="3"><?php echo $row['wday'];?></td>
        </tr>
        <tr>
            <td width="150"><label>Location:</label></td>
            <td colspan="3">
<table class="table table-bordered table-striped">
<tr>
<td colspan="2">Name</td>
<td>Quantity</td>
<td>Purchase</td>
<td>Sale</td>   
</tr>    
<?php 
$sqld="SELECT cost,price,invno,brid AS locid,'BR' AS type,SUM(p_qty) AS pqty,SUM(s_qty) AS sqty FROM tbl_traproduct WHERE pid='$id' GROUP BY pid";
$resultd = mysqli_query($con,$sqld) or die(mysqli_error($con));
while($rowd = mysqli_fetch_array($resultd)){                        
?>

<tr>
<td colspan="2"><?php if($rowd['type']=='BR'){if($rowd['locid']=='0'){echo 'Main Branch';}else{echo get_fild_data('tbl_branch',$rowd['locid'],'name');}}else{echo get_fild_data('tbl_warehouse',$rowd['locid'],'name');}?></td>
<td><?php echo $rowd['pqty']-$rowd['sqty']; ?></td>  
<td><?php echo $rowd['cost']; ?></td>  
<td><?php echo $rowd['price']; ?></td>   
</tr>                
<?php } ?> 
</table>                
            </td>
        </tr>
        <tr>
          <td class="text-center" colspan="4"><label>Description</label></td>  
        </tr>
        <tr>
          <td colspan="4"><?php echo $row['description'];?></td>  
        </tr>
    </table>
</div>
<div class="clearfix"></div>
<?php } ?>