<?php include("parent/callMe.php"); ?>
<?php  include("sessioncheck.php"); ?>
<?php

  $pageName = basename($_SERVER['PHP_SELF']);

 $m->where("page_name", $pageName);
 $pageNameAccess=$m->get("eduportal_modules_pages_detail");


$m->where("user_id", $_SESSION['user_id']);
$m->where ("branch_id", $_SESSION['branch']);
$m->where("page_id", $pageNameAccess[0]['page_id']);
$access = $m->get("users_privilege_detail");



$from;
$to;

if($_REQUEST['from']!=" " && $_REQUEST['from']!=NULL ) {
        $from=date("Y-m-d",strtotime($_REQUEST['from']));  

      }else {
        $from=date("Y-m-01");  
      }
     
      if($_REQUEST['to']!=" " && $_REQUEST['to']!=NULL   ) {
        $to=date("Y-m-d",strtotime($_REQUEST['to']));
      }else {
        $to=date("Y-m-t");  
      } 

 
     ?>

<!DOCTYPE html>
<html lang="en">
  <head>
    
    <title>Sales Bill List | EduPortal</title>
    <?php include('RootMe/css_links.php');?>
  
<script type="text/javascript">

function getSubCat(id){
  //alert(id);

    if (window.XMLHttpRequest) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    } else { // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
      if (xmlhttp.readyState==4 && xmlhttp.status==200) {

        document.getElementById("subcatgory").innerHTML=xmlhttp.responseText;
       //alert(xmlhttp.responseText);

      }

    }
    xmlhttp.open("GET","get_exp_subcategory.php?id="+id,true);
    xmlhttp.send();
  }
</script> 
  </head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- <script>
$(document).ready(function(){
  
    $("#div1").fadeOut();
    $("#div2").fadeOut("slow");
    $("#div3").fadeOut(3000);
 
});
</script> -->
  <style>
#snackbar {
  visibility: hidden;
  min-width: 250px;
  margin-left: -125px;
  background-color: #1E90FF;
  color: #fff;
  text-align: right;
  border-radius: 2px;
  padding: 16px;
  position: fixed;
  z-index: 1;
  left: 80%;
  bottom: 30px;
  font-size: 17px;
}

#snackbar.show {
  visibility: visible;
  -webkit-animation: fadein 0.5s, fadeout 0.5s 2.5s;
  animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@-webkit-keyframes fadein {
  from {bottom: 0; opacity: 0;} 
  to {bottom: 30px; opacity: 1;}
}

@keyframes fadein {
  from {bottom: 0; opacity: 0;}
  to {bottom: 30px; opacity: 1;}
}

@-webkit-keyframes fadeout {
  from {bottom: 30px; opacity: 1;} 
  to {bottom: 0; opacity: 0;}
}

@keyframes fadeout {
  from {bottom: 30px; opacity: 1;}
  to {bottom: 0; opacity: 0;}
}
</style>
  <body class="nav-md">
    <div class="container body">
      <div class="main_container">
        <div class="col-md-3 left_col">
     
            <?php include('RootMe/sidebar.php');?>

              <?php include('RootMe/header.php');?>
     
        <!-- page content -->
          <div class="right_col" role="main">

            <a href="<?php echo $_SESSION['dashboard'];?>">Dashboard </a> &nbsp; <i style="" class="fa fa-angle-double-right"></i>  &nbsp; 
            View Canteen Sales Bill List

            <a href="pos_datewise_discount_report.php" class="btn btn-success" style="float:right;margin-top:-3px;">Datewise Discount Report</a>

             <a href="pos_datewise_commitment_report.php" class="btn btn-success" style="float:right;margin-top:-3px;">Datewise Commitment Report</a>

          <br><br>
          
          <div class="row" style="background-color: white;">
           
  <section class="add_sub_agent" id="table_sub_agent">
  <div class="container">

 <div class="" style="margin-top:10px;">
   <form action="view_canteen_salesbill.php">
   <div class="col-md-12">
            
              

              <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col1">
                 <div class="form-group ">

                 <label class="required"> From Date</label>
                 <input name="from"  id="from" value="<?php echo $from;?>" type="date" class="form-control"  >
                       
                  </div>
                  </div>                      
             

                  <div class="col-md-3 col-sm-12 col-xs-12" style="padding:8px; float:left;"  id="col2">

                       <div class="form-group ">

                          <label class="required"> To Date</label>
                              <input name="to" id="to" value="<?php echo $to;?>" type="date" class="form-control"  >
                       
                          </div>
                  </div>
              
              
                           
           <div class="col-md-3" style="padding:8px;margin-top: 22px;">
                <div class="form-group ">
                
                <button type="submit" class="btn btn-primary">Search</button>

                     <a  href="canteen_sale_bill_export_excel.php?a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156a61oe8lqc1oclfi4llgnioo156&amp;from=<?php echo $_REQUEST['from'];?>&to=<?php echo $_REQUEST['to'];?>" class="fa fa-print btn btn-success" style="padding: 10px;">&nbsp;Export Excel
            
          </a>
                </div>
              </div>

             
            </div>
           </form>                 

  </div>
  <div class="clearfix"></div>
</section>           

<?php
   $branch=$_SESSION['branch']; 
   $sql = "SELECT * FROM eduportal_canteen_salebills_config as cnfg ";

   $sql .= "where cnfg.branch_id='$branch' and cnfg.invoice_date BETWEEN '" .$from. "' AND '" .$to. "' ";  

   $sql .= " Order by bill_id desc";          
      
    $salesbills = $m->query($sql);

// print_r($sql);
     ?>


     <div class="t col-md-12 col-sm-12 col-xs-12">
                <h3>Sale Bill List<small> (<?php echo count($salesbills);?> records)</small></h3>
              </div>


<table id="datatable" class="table table-striped table-bordered"style="background-color: white;">
                      <thead>
                        <tr>
                          <th width="1%">S.No</th>
                          <th width="15%">Customer Name</th>
                          <th width="10%">Month</th>
                          <th width="8%">Bill No</th>
                          <th width="8%">Bill Date</th>                        
                          <th width="8%">Net Amount</th>                         
                          <th width="10%">Action</th>
                         

                        </tr>
                      </thead>
                      <tbody>

                        
<?php  $count1=1;
$date= date("Y-m-d");

foreach($salesbills as $salesbill){

  $m->where("student_id", $salesbill['student_id']);
  $studentName=$m->get("edu_student_details");

  $m->where("Month_Id", $salesbill['month_id']);
  $months=$m->get("eduportal_month_config");

  $m->where("revenue_id", $revenue['revenue_id']);
  $PaidBy=$m->get("eduportal_revenue_details");

  
$totalAmount+=$salesbill['total_amount'];
//echo $count1++;
?>
<tr>
<td style="text-align:center;"><?php echo $count1++;?></td>
<td> <?php  if ($studentName[0]['first_name']!=NULL) {
  echo $studentName[0]['first_name'];
} else {
  echo "Other";
} ?></td>
<td><?php echo $months[0]['Month_Name'];?></td>
<td><?php echo $salesbill['bill_id'];?></td>
<td><?php echo date("d-M-Y",strtotime($salesbill['invoice_date']));?></td>
<td><?php echo $salesbill['total_amount'];?></td>




<td>


<a style="padding: 0px 5px; font-size:14px;"  href="canteen_sales.php?<?php echo session_id().session_id().session_id().session_id().session_id();?>&id=<?php echo $salesbill['bill_id'];?>" style="cursor:pointer;"  class="btn btn-success"> <i class="fa fa-pencil" aria-hidden="true"></i></a> 



<a href="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php?billDelete=<?php echo $salesbill['bill_id'];?>&action=DeleteProductBill" style="padding: 0px 5px; font-size:14px;" onClick="return confirm('Are you sure you want to delete this record');"  class="btn btn-danger"><i class="fa fa-remove"></i> </a>



<!-- <a  style="padding: 0px 5px; font-size:14px;" href="canteen_voucher.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&id=<?php echo $salesbill['bill_id']; ?>" target="_blank" class="btn btn-success">     
<i class="fa fa-print"></i> 
</a> -->

<a  style="padding: 0px 5px; font-size:14px;"  data-toggle="modal" data-target="#viewProduct<?php echo $salesbill['bill_id'];?>" class="btn btn-success">     
<i class="fa fa-eye"></i> 
</a>


<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-warning dropdown-toggle btn-sm" style="padding:1px;" type="button" aria-expanded="true">Print <span class="caret"></span>
</button>
<ul role="menu" class="dropdown-menu">


<li><a href="canteen_voucher.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&id=<?php echo $salesbill['bill_id']; ?>" target="_blank">Single Voucher</a></li>

<li><a href="canteen_voucher_triple.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&id=<?php echo $salesbill['bill_id']; ?>" target="_blank">Triple Voucher</a></li>


</ul>
</div>


<!-- start popup code stdent struck off -->

<div id="viewProduct<?php echo $salesbill['bill_id'];?>" class="modal fade" role="dialog">
<div class="modal-dialog">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="border-bottom:none;">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title" style="text-align:center;"> View Product List (<?php echo $studentName[0]['first_name'];?>)  </h4>
</div>

<div class="modal-body">

<table id="example" class="table table-striped table-bordered"style="background-color: white;">
<thead>
<tr>
<th width="1%">S.No</th>
<th width="10%">Product Name</th>
<th width="10%">Product Qty</th>

</tr>
</thead>
<tbody>
<?php  $count=1;
$date= date("Y-m-d");

$m->where("bill_id", $salesbill['bill_id']);
$m->where("branch_id", $_SESSION['branch']);
$Bills=$m->get(" eduportal_canteen_salebills_details");
//print_r($Bills);
foreach($Bills as $data){

$m->where("product_id", $data['product_id']);
$m->where("branch_id", $_SESSION['branch']);
$ProductName=$m->get(" eduportal_product_config");

?>

<tr>
<td style="text-align:center;"><?php echo $count; $count++;?></td>
<td><?php echo $ProductName[0]['product_name'];?></td>
<td style="text-align: center;"><?php echo $data['product_qty'];?></td>


</tr>
<?php } ?>


</tbody>
</table>

</div>

</div>

</div>
</div>

<!-- Student result popup ending -->
</td>

</tr>
<?php } ?>
<tr style="background-color:lightgray; font-size: 14px;">
<td colspan="5" style="text-align:center;"> Total</td>
<td colspan="2"><?php echo $totalAmount;?></td>
</tr>                  

                      </tbody>
                    </table>
           
          </div>
        </div>

            </div>
          </div>
        </div>
        <!-- /page content -->
  

    
  <?php include('RootMe/js_linksscript.php');?>
  </body>
</html>
<script>
function toastFunction() {
  var x = document.getElementById("snackbar");
  x.className = "show";
  setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
}
</script>