<!doctype html>
<html class="no-js" lang="en">
<?php

session_start();
$branch=$_SESSION['branch_id'];

?>
<head>
<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">
    <?php 
	<?php 
    include '../includes/connection.php';
  
    ?>
	?>

<script type="text/javascript">
      window.onload = function() { window.print();
        var is_chrome = function () { return Boolean(window.chrome); }
            if(is_chrome) 
            {
            setTimeout(function(){document.location.href = "new_order.php";}, 0); 
            //give them 10 seconds to print, then close
            }
            else
            {
           setTimeout(function(){document.location.href = "new_order.php";}, 0);
            }
        }
   
 </script>
</head>
<body>
        <div class="row">
        <div class="col-lg-1 col-md-1 col-sm-1 col-xs-1">
        </div>
        <div class="col-lg-10 col-md-10 col-sm-10 col-xs-10" style="margin-top:40px;">
        <?php
        // include "../fincludes/receipt_header.php";
        ?>
        <hr></br>
        <h3 style="text-align:center;">Fees payment receipt</h3>
        <div align="right">
        <?php
          $sql = "SELECT full_name FROM staff where staff_code='$staffcode'";
$result = mysqli_query($conn, $sql);
           $result = mysqli_query($conn, $sql);
           if (mysqli_num_rows($result) > 0) {
   $row = mysqli_fetch_assoc($result);
   $staffname=$row['full_name'];
   
    
} else {
  $staffname="";
    echo "0 results";
}

$sql = "SELECT id, (select max(id) from sales)as salesid, (select receipt_no from sales where id=salesid)as receiptnoo, (select product_name from products where id=sales_details.product_id)as product_name, (select sum(quantity) from sales_details where order_id=salesid)as quantityy, quantity,  (select price from products where id=sales_details.product_id) as unit, (select paid from sales where id=sales_details.order_id)as total FROM sales_details where order_id=(select max(order_id) from sales_details where branch_id='$branch')";

$sql2 = "SELECT id, (select max(id) from sales)as salesid, (select receipt_no from sales where id=salesid)as receiptnoo, (select product_name from products where id=sales_details.product_id)as product_name, (select count(id) from sales_details where order_id=salesid)as quantityy, quantity,  (select price from products where id=sales_details.product_id) as unit, (select paid from sales where id=sales_details.order_id)as amtpaid,(select changebal from sales where id=sales_details.order_id)as changebal,(select total_price from sales where id=sales_details.order_id)as total,selling_price FROM sales_details where order_id=(select max(order_id) from sales_details where branch_id='$branch')";
$result = mysqli_query($conn, $sql);
 $roww = mysqli_fetch_assoc($result);
          ?>

        </div>
        
        <div class="row">
            <div class="col-lg-6 col-md-4 col-sm-4 col-xs-4">
            Rec No:  <?php echo $roww['receiptnoo'] ?>
            </div>
            <div class="col-lg-6 col-md-8 col-sm-8 col-xs-8">
            Date:  <?php echo date('d/m/Y')?>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <h5>Study time:</h5>
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <h5>Year <?php echo$row3['StudyYear'];?></h5>
            <h5>Term <?php echo$row3['Semester'];?></h5>
            </div>
        </div>
        <div class="row">
            <table width="100%" style="border-style: dotted; border: 2px;">
          <thead style="text-align: left;">
            <th width="40%">ITEM</th>
            <th width="20%">QTY</th>
           
            <th width="20%">PRICE</th>
            <th width="20%">AMOUNT</th>
          </thead>
          <tbody>
          <?php
          $result2 = mysqli_query($conn, $sql2);
          while($row = mysqli_fetch_assoc($result2)) {
            ?>
            <tr>
              <td width="40%"><?php echo $row['product_name'];?></td>
              <td width="20%"><?php echo $row['quantity']?></td>
              <td width="20%"><?php echo number_format($row['selling_price']);?></td>
              <td width="20%"><?php echo number_format($row['selling_price']*$row['quantity']);?></td>
            </tr>
            <?php
           $sum=$row['total'];
           $amtpaid=$row['amtpaid'] + $row['changebal'];
           $changebal=$row['changebal'];
          }
          ?>
            
          </tbody>
        
        </table>
        </div>
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <h4><h5>Total:</h5></h4>
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <h3><?php echo number_format($row2['Amount']);?></h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <h5>Amount Paid:</h5>
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <h5><?php echo number_format($amtpaid);?></h5>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <h5>Balance:</h5>
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <h5><?php echo number_format($sum-$amtpaid);?></h5>
            </div>
        </div>
        <?php if($row2['Payment_mode']=="bank"){?>
            <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <h5>Change:</h5>
            
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <h5><?php echo number_format($changebal);?><br>SERVED BY: <?php echo $staffname;?>
            </h5>
            
            </div>
        </div>
        
            <div class="row">
            <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4">
            <?php include'../sales/rec_footer.php' ;?>
            </div>
            <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
            <<p align="center">POS Software By:<br> <?php $dev_select=mysqli_fetch_array(mysqli_query($con,"select * from developer")); echo $dev_select['developer_name']; ?>(<?php echo $dev_select['tel'];?>)
          </p>
            </div>
        </div>
        
        
        </div>
       
        </div>
</body>

</html>