<?php
error_reporting(0);

?>
<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/quotationreport.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%;
  }
}
</style>
<script>
  function printDiv() 
{

  var divToPrint=document.getElementById('printdiv');

  var newWin=window.open('','Print-Window');

  newWin.document.open();

  newWin.document.write('<html><head><link rel="stylesheet" href="tablestyle/tablereport.css"></head><body onload="window.print()">'+divToPrint.innerHTML+'</body></html>');
  newWin.document.close();
}
  $(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 ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3>Expense Report</h3>
<br>

<!-- search collaspe -->

<!-- date -->
<form action="expense_report.php" method="post">
<div class="row daterow" style="overflow:auto">  
                <div class="col-sm-1"></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 class="col-sm-1"><button class="btn btn-info" type="submit"><i class="fas fa-calendar-check" style="font-size:23px;"></i></button></div> 
              <div class="col-sm-1"><button type="button" class="btn btn-primary" onClick="printDiv()">Download</button></div>       
            </div>
            </form>
           

 



    <br>
    
    <div  id="printdiv">
  <div class="row">
    <div class="col-md-12">
   
   
   <table class="table table-bordered table-sm">
             <thead>
        <tr>
            <th>Date</th>
            <th>Particulars</th>
            <th>Amount</th>
            <th>Balance / Credit</th>
        </tr>
    </thead>
	
	<tbody>
	<?php
	$fromdate=$_POST['fromdate'];
	$todate=$_POST['todate'];
	//echo "select sum(given_amount)as receivedamount from cash_handling where status !='deleted' and givento='Office Expence' and date<='$fromdate'";
	$givenamount = mysqli_query($connect,"select sum(given_amount)as receivedamount from cash_handling where status !='deleted' and givento='Office Expence' and date<='$fromdate'");
		 $ramount=mysqli_fetch_assoc($givenamount);
		 
		 $expamount = mysqli_query($connect,"select sum(given_amount)as expamount from cash_expense where status !='deleted' and date<='$fromdate'");
		 $eamount=mysqli_fetch_assoc($expamount);
		 
		 $opening=$ramount['receivedamount']-$eamount['expamount'];
		 $fdate=date_create($fromdate);
		 $tdate=date_create($todate);
	
	?>
        <tr>
            <td><strong><?php echo date_format($fdate,"d-m-Y ");?></strong></td>
            <td><strong>Closing Balance</strong></td>
            <td class="amount" align="right">-</td>
            <td class="amount" align="right"><strong><?php echo number_format($opening,2,'.','');?></strong></td>
        </tr>

<?php

$expe=mysqli_query($connect,"select * from cash_expense where status='' and date between '$fromdate' and '$todate'");
$exp=0;
while($rowexp=mysqli_fetch_array($expe))
{
$date=date_create($rowexp['date']);
?>
        <tr>
            <td><?php echo date_format($date,"d-m-Y ");?></td>
            <td><?php echo $rowexp['expense_name'];?></td>
            <td class="amount" align="right"><?php echo number_format($rowexp['given_amount'],2,'.','');?></td>
            <td align="right">-</td>
        </tr>
		<?php
		$exp+=$rowexp['given_amount'];
		}
		?>
		 
		 <tr>
            <td>&nbsp;</td>
            <td><strong>Total Expenses</strong></td>
            <td class="amount" align="right"><strong><?php echo number_format($exp,2,'.','');?></strong></td>
            <td align="right">-</td>
        </tr>

        <tr>
            <td><strong><?php echo date_format($tdate,"d-m-Y ");?></strong></td>
            <td><strong>Closing Balance</strong></td>
            <td align="right">-</td>
            <td class="amount" align="right"><strong><?php echo number_format(($opening-$exp),2,'.','');?></strong></td>
        </tr>
    </tbody>

            
        </table>
           </div>
		   
		   <div>&nbsp;</div><br>
		   
		   
		   
		   
		   
		   </div>
           <div>&nbsp;</div>
		   
		  
		   
           
           </div><!--print-->

</div>
</div>


<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>
 <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>
</body>
</html>