 <?php 
if(isset($_POST['vno'])){
extract($_POST);
require 'connection.php';

   $qry = "SELECT posted FROM sales where saleid = $vno";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   $rowposted = mysqli_fetch_array($run);

$sr=1;
$tamt=0;


 $qry1 = "SELECT accid FROM sales where saleid = $vno";
   $run1 = mysqli_query($connect, $qry1) or die(mysqli_error($connect));
   $acidname = mysqli_fetch_array($run1);
   $acidn=$acidname['accid'];
$qry1 = "SELECT * FROM accreg where accid = $acidn";
   $run1 = mysqli_query($connect, $qry1) or die(mysqli_error($connect));
   $accname = mysqli_fetch_array($run1);



?>

  <tr>
 <td style="color: maroon;"> Account Name :  </td>

 <td style="color: maroon;"> <?php echo $accname['accname']; ?> </td>
 <td>   </td>
 <td>   </td>
 <td>   </td>
 <td>   </td>
 <td>   </td>
 
</tr>


  <tr>
                    <th>Sr. No.</th>
                    <th>ID</th>
                    <th>Product Name</th>
                    <th>Rate</th>
                    <th>Qty</th>
                    <th>Amount</th>
                    <th>Action</th>
                  </tr>
<?php

  
 $qry = "SELECT * FROM stockledger INNER JOIN itemreg ON stockledger.itemid = itemreg.itemid where vno = $vno and def='4'";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   while($row = mysqli_fetch_array($run)){
	?>


	<tr>
 <td> <?php echo $row['srno']; ?> </td>
 <td> <?php echo $row['itemid']; ?> </td>
 <td> <?php echo $row['itemname']; ?> </td>
<td> <?php echo $row['rateout']; ?> </td>
<td> <?php echo $row['stockout']; ?>  </td>
<td> <?php echo $row['costout']; ?>  </td>

<td> <button id="dltbtn" class="glyphicon glyphicon-trash" style="color: red;"></button>  </td>
</tr>
<?php
	$sr= $sr+1;
	$tamt=$tamt+$row['costout'];
}
?>

<?php
}


if(isset($_POST['vnopr'])){
extract($_POST);
require 'connection.php';

   $qry = "SELECT posted FROM purchase where prid = $vnopr";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   $rowposted = mysqli_fetch_array($run);


 $qry = "SELECT * FROM purchase where prid='$vnopr'";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   $row1 = mysqli_fetch_array($run);
   $acids=$row1['accid'];
 $qry = "SELECT accname FROM accreg where accid='$acids'";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   $row1 = mysqli_fetch_array($run);
$acnames=$row1['accname'];
?>
  <tr>
 <td style="color: brown; font-size: 14px; font-weight: bold;" colspan="7"> <?php echo 'Account Name: '.$acnames; ?> </td>


</tr>

 <tr>
                    <th>Sr. No.</th>
                    <th>ID</th>
                    <th>Product Name</th>
                    <th>Rate</th>
                    <th>Qty</th>
                    <th>Amount</th>
                    <th>Action</th>
                  </tr>
<?php


$sr=1;
$tamt=0;
 $qry = "SELECT * FROM stockledger INNER JOIN itemreg ON stockledger.itemid = itemreg.itemid where vno = $vnopr and def='5' order by srno asc";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   while($row = mysqli_fetch_array($run)){
	?>

	<tr>
 <td> <?php echo $row['srno']; ?> </td>
 <td > <?php echo $row['itemid']; ?> </td>
 <td> <?php echo $row['itemname']; ?> </td>
<td> <?php echo $row['ratein']; ?> </td>
<td> <?php echo $row['stockin']; ?>  </td>
<td> <?php echo $row['costin']; ?>  </td>
<td> <button id="dltbtn" class="glyphicon glyphicon-trash" style="color: red;"></button>  </td>

</tr>
<?php
	$sr= $sr+1;
	$tamt=$tamt+$row['costin'];
}
?>

<?php
}




if(isset($_POST['vnoslr'])){
extract($_POST);
require 'connection.php';

   $qry = "SELECT posted FROM saleret where slrid = $vnoslr";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   $rowposted = mysqli_fetch_array($run);

$sr=1;
$tamt=0;
 $qry = "SELECT * FROM stockledger INNER JOIN itemreg ON stockledger.itemid = itemreg.itemid where vno = $vnoslr and def='6'";
   $run = mysqli_query($connect, $qry) or die(mysqli_error($connect));
   while($row = mysqli_fetch_array($run)){
	?>

	<tr>
 <td> <?php echo $row['srno']; ?> </td>
 <td> <?php echo $row['itemname']; ?> </td>
<td> <?php echo $row['ratein']; ?> </td>
<td> <?php echo $row['stockin']; ?>  </td>
<td> <?php echo $row['costin']; ?>  </td>
<?php
if($rowposted['posted']!=='posted'){
?>
<td> <button id="dltbtn" class="glyphicon glyphicon-trash" style="color: red;"></button>  </td>
<?php } ?>
</tr>
<?php
	$sr= $sr+1;
	$tamt=$tamt+$row['costin'];
}
?>

<?php
}
	?>

	<script type="text/javascript">
	$("#tamt").val(<?php echo $tamt; ?>)

	</script>


