<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
include ('../inc/invfunctions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){    
$_SESSION['cuPages']='sel_sinvlist.php';   
$cuPage='sel_sinvlist.php';    
$aid=$_SESSION['uid'];
$brid=$_SESSION['abrid'];    
}else{
header('Location:../index.php');
exit;    
}
?>
<?php 
function get_prodliqty($invno){
global $con;
$invty=substr($invno,0,3);
if($invty=='CSD'){    
$sql="SELECT SUM(cldeli) AS rdata FROM tbl_cartraproduct WHERE invno='$invno'";
}else{
$sql="SELECT SUM(clrcv) AS rdata FROM tbl_cartraproduct WHERE invno='$invno'";    
}
$query=mysqli_query($con,$sql)or die(mysqli_error($con));    
$row=mysqli_fetch_array($query);
return $row['rdata'];    
}
?>
<?php 
if(isset($_POST['invid'])){
$piid=$_POST['invid'];
$type=$_POST['type'];    
$supid=$_POST['supid'];
$sql="SELECT tbl_carpdlirecord.id,tbl_carpdlirecord.invno,tbl_carpdlirecord.refinv,tbl_carpdlirecord.apdate FROM tbl_carpdlirecord LEFT JOIN tbl_carorder ON tbl_carorder.invno=tbl_carpdlirecord.refinv WHERE tbl_carorder.type='$type' AND tbl_carorder.supid='$supid' ORDER BY apdate DESC,id DESC";        
$query=mysqli_query($con,$sql)or die(mysqli_error($con));
while ($row=mysqli_fetch_array($query)){
$invno=$row['invno'];
$refinv=$row['refinv'];    
?>
<li <?php if($row['id']==$piid){echo 'class="invpiv active"';}else{echo 'class="invpiv"';}?> id="pi_<?php echo $row['id'];?>"><p><strong class="pino"><?php echo $row['invno'];?></strong><br><strong><?php echo date("d M Y", strtotime($row['apdate']));?></strong></p>
<div class="sname" style="margin-top: -52px;float: right; position: relative;top: 6px;"><strong><?php echo 'Deliver Qty: '.get_prodliqty($invno); ?></strong><br><strong><?php echo 'Total Qty: '.get_prodliqty($refinv); ?></strong></div>
</li>
<?php }} ?>