<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');
endif;
$cval=0;
$grn_no=0;
$edate=date("Y-m-d"); 
$fdate=$edate;
$tdate=$edate;

$fcus=0;
$tcus=0;


if(isset($_POST['SubmitButton'])){ //check if form was submitted
  $fdate = $_POST['fdate'];
  $tdate = $_POST['tdate'];
  $cus_id = $_POST['cus_id'];
  $emp_id= $_POST['emp_id'];


    if ($cus_id==0){  $fcus=0; $tcus='99999999'; }
    else {  $fcus=$cus_id ; $tcus=$cus_id ; }

}






?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>SalesHub | Sales Management </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
 <div class="content-wrapper">

     <div class="page-header">
     <h3 class="page-title">
     Invoice Listing
     </h3>
     </div> 
     <div class="col-22 grid-margin">
     <div class="card">
     <div class="card-body">
       <form class="needs-validation" novalidate method="post"  enctype="multipart/form-data" onsubmit="return validateForm()">                   
                    <div class="row">                     
                      <div class="col-md-4">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">From Date: </label>
                          <div class="col-sm-9">
                             <input type="date" class="form-control" id="fdate" name="fdate" >
                          </div>
                        </div>


                      </div>
                      <div class="col-md-4">                  
                          <div class="form-group row">
                          <label class="col-sm-3 col-form-label">To Date </label>
                          <div class="col-sm-9">
                               <input type="date" class="form-control" id="tdate" name="tdate" >
                          </div> 

                          </div>  

                      </div>                            
                  <div class="col-md-4">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Sales Type: </label>
                          <div class="col-sm-8">
                      
                             <select class="form-control select2" style="width: 100%;" name="stype" id="stype"  >
           <option value="0">~~~ All ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from salestype  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['sid'];?>"><?php echo $rowd['sdes'];?></option>        
          <?php }?>
          </select> 
                          </div>
                        </div>

                    </div> <!-------End of first form raw------->

            

</div>



  <div class="row">                     
  <div class="col-md-4">
  <div class="form-group row">
   <label class="col-sm-3 col-form-label">Invoice Type </label>
  <div class="col-sm-9">
 <select class="form-control select2" style="width: 100%;" name="invtype" id="invtype"  >
         
          <?php            
          $querydoc=mysqli_query($con,"select * from invoice_types  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['invtype_id'];?>"><?php echo $rowd['des'];?></option>        
          <?php }?>
          </select> 
 </div>

</div>
</div>
                <div class="col-md-8">                  
                          <div class="form-group row">
                          <label class="col-sm-2 col-form-label">Customer :</label>
                          <div class="col-sm-9">           

                              <select class="form-control select2" style="width: 100%;" name="cus_id" id="cus_id"  >
           <option value="0">~~~All ~~~~</option>  
          <?php            
          $querydoc=mysqli_query($con,"select * from customer_master  ")or die(mysqli_error());
          
          while($rowd=mysqli_fetch_array($querydoc)){
          ?>
          <option value="<?php echo $rowd['cus_id'];?>"><?php echo $rowd['cus_name'];?></option>        
          <?php }?>
          </select> 

                          </div>
                        </div>
                      </div>
</div>
            

  <div class="row">                     
  <div class="col-md-4">
  <div class="form-group row">
   <label class="col-sm-3 col-form-label">Employee </label>
  <div class="col-sm-9">
    <select class="form-control select2" style="width: 100%;" name="emp_id" id="emp_id"  >
           <option value="0">~~~All ~~~~</option>  
          <?php            
          $queryemp=mysqli_query($con,"SELECT * FROM employee_master  ")or die(mysqli_error());
          
          while($rowemp=mysqli_fetch_array($queryemp)){
          ?>
          <option value="<?php echo $rowemp['emp_id'];?>"><?php echo $rowemp['emp_name'];?></option>        
          <?php }?>
          </select> 
 
 </div>
</div>
</div>



  <div class="col-md-4">
  <div class="form-group row">




</div>

</div>
        <div class="col-md-4">
                        <div class="form-group row">

          </div>
          </div>

                    
                     <button type="submit"  name="SubmitButton"class="btn btn-primary">View</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
     </div><!-----End of <div class="card-body">--~~~~~~---->
     </div><!-----End of <div class="card">--~~~~~~---->
     </div><!-----End of  <div class="col-22 grid-margin">--~~~~~~---->

 
     <div class="col-22 grid-margin" >
     <div class="card" >      
             <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back                    
                  </button>
                  </p>
     <div class="card-body">
                  <div class="table-responsive">
                   <table class="table table-sm">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>No</th>
                          <th>Date</th>
                          <th>Location</th>
                          <th>Customer</th>
                           <th>Amount</th>
                          <th>View</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;

$ll="SELECT inv_id,inv_date ,customer_master.cus_name,stock_locations.loc_name,
seheader.amount
FROM inv_header
LEFT JOIN customer_master ON customer_master.cus_id=inv_header.cus_id
LEFT JOIN stock_locations ON stock_locations.loc_id=inv_header.loc_id
LEFT JOIN seheader ON inv_header.inv_id=seheader.docid where inv_date between '$fdate' and '$tdate'";
//echo $ll;

$query=mysqli_query($con,"SELECT inv_header.inv_id,inv_header.inv_date ,customer_master.cus_name,stock_locations.loc_name,
seheader.amount,item_master.item_name
FROM inv_header
LEFT JOIN customer_master ON customer_master.cus_id=inv_header.cus_id
LEFT JOIN stock_locations ON stock_locations.loc_id=inv_header.loc_id
LEFT JOIN seheader ON inv_header.inv_id=seheader.docid
LEFT JOIN inv_detail ON inv_header.inv_id=inv_detail.inv_id
LEFT JOIN item_master ON inv_detail.item_id=item_master.item_id where inv_date between '$fdate' and '$tdate' and inv_header.cus_id between $fcus and $tcus  ")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $inv_id=$row['inv_id'];
                $inv_date=$row['inv_date']; 
                $loc_name=$row['loc_name'];
                $cus_name=$row['cus_name'];
              

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['inv_id'];?></td>
                         <td><?php echo  date("Y-m-d",strtotime( $row['inv_date'])) ;?></td> 
                        
                         <td><?php echo $row['loc_name'];?></td>
                         <td><?php echo $row['cus_name'];?></td>
                          <td><?php echo $row['amount'];?></td>
                         <td> <form method="post" action="#" enctype="multipart/form-data">
                            <input type="hidden" class="form-control pull-right" id="inv_no" name="inv_no"  value=" <?php echo $inv_id; ?>">
         <button type="submit" formaction="invoice.php?inv_no=<?php echo $inv_id; ?>" class="btn btn-outline-secondary btn-rounded btn-icon">
                        <i class="fas fa-edit text-danger"></i>
                      </button>


     



                    </form></td>
 

</tr>

 <?php }  ?>

                      </tbody>
                    </table>
                  </div>
     </div><!-----End of <div class="card-body">--~~~~~~---->
     </div><!-----End of <div class="card">--~~~~~~---->
     </div><!-----End of  <div class="col-22 grid-margin">--~~~~~~---->




     </div><!-----End of   <div class="content-wrapper">--~~~~~~---->
       



 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
</div>
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 
  




 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



