<?php
error_reporting(0);
$customer=$_POST['customer'];
$upi_number=$_POST['upi_number'];
		
		  $fromdate=$_POST['fromdate'];
		  $todate=$_POST['todate'];
		  
		  $fdate=date_create($fromdate);
		  $tdate=date_create($todate);
?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="datatable/data.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<link rel="stylesheet" href="calendar-15/calendar-15/fonts/icomoon/style.css">

<link rel="stylesheet" href="calendar-15/calendar-15/css/rome.css">
<link rel="stylesheet" href="calendar-15/calendar-15/css/style.css">
<!-- <script src = "ajax/loadoutreport1.js"></script>
<script src = "ajax/loadoutreport2.js"></script>
<script src = "ajax/loadoutreport3.js"></script> -->
<script src="js/loadoutreport.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:5px;
        padding-right:5px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
     
      padding:8px;
     border:1px solid rgba(24, 7, 173); 
      background-color:#FFFFE0;
      color:black;
    }
    th
    {
      background-color:rgba(24, 7, 173);
      text-align:center;
      padding:8px;
     border-bottom:1px solid #FFFFE0; 
     color:#FFFFE0;
    }
    li a 
    {
      color:black;
    }
    .page-item.active .page-link {
    
    background-color:yellow;
    border-color: #007bff;
}
.reportModal
{
  height:800px;
}
.searchfeilds input
{
height:30px;
}
.daterow
{
  margin-top:10px;
}
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}

#table-wrapper {
  position:relative;
}
#table-scroll {
  height:auto;
  overflow:auto;  
  margin-top:20px;
}
#table-wrapper table {
  width:100%;

}

#table-wrapper table thead th .text {
  position:absolute;   
  top:-20px;
  z-index:2;
  height:20px;
  width:35%;
  border:1px solid red;
}
</style>
<script>
  $(function () {

// INITIALIZE DATEPICKER PLUGIN
$('.datepicker').datepicker({
    clearBtn: true,
    format: "dd/mm/yyyy"
});


// FOR DEMO PURPOSE
$('#reservationDate').on('change', function () {
    var pickedDate = $('input').val();
    $('#pickedDate').html(pickedDate);
});
});

</script>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>

</head>
<body>
    
    <div id="fullbody"> 
<div id="navbar" class="bg-info"><?php include "navbar.php"?></div>
<div id="content">

<h3 align="center">Customer Report</h3>

<form action="credit_report.php" method="post" autocomplete="off">

<div>&nbsp;</div>


<div class="row searchfeilds" >
  
  <div class="col-sm-1"></div>  
  
  <div class="col-sm-4">
<select class="selectpro" id="customer" name="customer" >
    <option value="">--Select Customer--</option>
<?php 
$cus=mysqli_query($connect,"select * from customerdetails where status !='deleted' group by code");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>         
</select>

</div>


<div class="col-sm-2">
<select class="selectpro" id="upi_number" name="upi_number" >
    <option value="">--Select UPI/Number--</option>
<?php 
$upi_num=mysqli_query($connect,"select * from creditdetails where status !='deleted' group by upi_number");
while($upi = mysqli_fetch_array($upi_num))
{
?>
<option value="<?php echo $upi['upi_number'] ?>"><?php  echo $upi['upi_number'] ?></option>
        <?php }?>         
</select>

</div>


     <div class="col-sm-2">
                <input type="text" class="form-control" id="input_from" name="fromdate" autocomplete="off" placeholder="Start Date" ></div>
                <div class="col-sm-2">
                            
                <input type="text" class="form-control" id="input_to" name="todate" autocomplete="off" placeholder="To Date" >
              </div>             
            </div>
            <div>&nbsp;</div>
            
            <div class="row searchfeilds" >
  
  <div class="col-sm-1"></div>  
  <div class="col-sm-2"></div>  
  <div class="col-sm-1"><button type="submit" class="btn btn-primary" >Submit</button></div>  
  <div class="col-sm-1"><button type="button" class="btn btn-primary" onClick="tableToExcel('a', 'W3C Example Table')">Download</button></div>
 <!-- <div class="col-sm-1"><a href="print_customerreport.php?customer=<?php echo $customer;?>&&fromdate=<?php echo $fromdate;?>&&todate=<?php echo $todate;?>" class="btn btn-primary" target="_blank">Print</a></div>-->
  
  </div>
  </form>
   <div id="a">
  

  <?php
  
		?>
        <div class="row searchfeilds" >
       
        <div class="col-sm-3">
           
  
  
 
 
 
 
<!--  <div id="table-wrapper">
  <div id="table-scroll">-->
  
  <table  class="table table-striped table-bordered " cellspacing="0" width="100%">
              <thead>
                 <th>Sno</th>
                 <th>Date</th>
                 <th>Customer</th>
                 <th>Sales&nbsp;Code</th>
                 <th>Bill&nbsp;Amount</th>
                 <th>Collected&nbsp;Amount</th>
                 <th>Cash</th>
                 
                 <th>Bank/UPI</th>
                 <th>Mode</th>
                 <th>UPI</th>
                 
                 
                 <th>Ref.No</th>
                 
                 <th>Remarks</th>
              
             </thead>
             <?php
			 
			  $sql_query="select sh.date,sh.customer,sh.sales_code,sh.totalamount,sh.pendingamount,sh.amount,sh.otheramount,sh.paymentmethod,sh.upi_number,sh.remark,sh.cheque,sh.code,cm.name from creditdetails as sh inner join customerdetails as cm on cm.code=sh.customer where sh.status='' and cm.status<>'deleted'";
			  
			 
			  
			  if($customer=="" && $upi_number=="" && $fromdate!="" && $todate!="")
			  {
			  $sql_query.= "and sh.date BETWEEN '".$fromdate."' AND '".$todate."' order by sh.date ASC ";
			  
			  }
			  
			  else if($customer!="" && $upi_number=="" && $fromdate!="" && $todate!="")
			  {
			  $sql_query.= "and sh.customer='".$customer."' and sh.date BETWEEN '".$fromdate."' AND '".$todate."' order by sh.date ASC ";
			  
			  }
			  
			  else if($customer=="" && $upi_number!="" && $fromdate!="" && $todate!="")
			  {
			  $sql_query.= "and sh.upi_number='".$upi_number."' and sh.date BETWEEN '".$fromdate."' AND '".$todate."' order by sh.date ASC ";
			  
			  }
			  
			  else if($customer=="" && $upi_number!="" && $fromdate=="" && $todate=="")
			  {
			  $sql_query.= "and sh.upi_number='".$upi_number."'  order by sh.date ASC ";
			  
			  }
			  
			  else if($customer!="" && $upi_number=="" && $fromdate=="" && $todate=="")
			  {
			  $sql_query.= "and sh.customer='".$customer."'  order by sh.date ASC ";
			  
			  }
			  
			 			$query_result=mysqli_query($connect, $sql_query) or die("brandgriddata.php: get brand Data step 1".$sql_query);
			$sno=0;
			$cash=0;
			$bank=0;
			$total=0;
			while($row_query=mysqli_fetch_array($query_result))
{
			 ?>
             <tbody >
<tr>
<td><?php echo ++$sno;?></td>
<td><?php echo $row_query['date'];?></td>

<td><?php echo $row_query['name'];?></td>
<td><?php echo $row_query['sales_code'];?></td>
<td><?php echo $row_query['pendingamount'];?></td>
<td><?php echo $row_query['totalamount'];?></td>
<td><?php echo $row_query['amount'];?></td>
<td><?php echo $row_query['otheramount'];?></td>
<td><?php echo $row_query['paymentmethod'];?></td>
<td><?php echo $row_query['upi_number'];?></td>
<td><?php echo $row_query['remark'];?></td>
<td><?php echo $row_query['cheque'];?></td>

</tr>
             </tbody>
             <?php
			 $total+=$row_query['totalamount'];
			$cash+=$row_query['amount'];
			$bank+=$row_query['otheramount'];
			 }
			 ?>
             <tr>
             <td colspan="5" align="right"><strong>Total</strong></td>
             <td><strong><?php echo number_format($total,2,'.','');?></strong></td>
             <td align="right"><strong><?php echo number_format($cash,2,'.','');?></strong></td>
             <td align="right"><strong><?php echo number_format($bank,2,'.','');?></strong></td>
             </tr>
           </table>
  </div></div>
  
  
            
         </div>  
 <!-- </div>



</div>
-->

    <link href = "https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"
         rel = "stylesheet">

<script >
var tableToExcel = (function() {
  var uri = 'data:application/vnd.ms-excel;base64,'
    , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
    , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
    , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
  return function(table, name) {
    if (!table.nodeType) table = document.getElementById(table)
    var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
    window.location.href = uri + base64(format(template, ctx))
  }
})()

</script>


<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="calendar-15/calendar-15/js/rome.js"></script>

<script src="calendar-15/calendar-15/js/main.js"></script>
<script src="js/jsontoexcel.js"></script>
</body>
</html>