<?php

include_once("../connect.php");
include_once("../session.php");



?>
<!DOCTYPE html>
 <html lang="en">
   <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge">
	 <meta name="viewport" content="width=device-width, initial-scale=1">
    
     <title><?= $config['CompanyName'] ?></title>
 
     <!-- Bootstrap -->
     <link href="../css/bootstrap.min.css" rel="stylesheet">
     <link rel="stylesheet" href="../css/bootstrap-combobox.css" />
 
     <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
     <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
     <!--[if lt IE 9]>
       <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
       <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
       <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
           <!-- Include all compiled plugins (below), or include individual files as needed -->
           <script src="../js/bootstrap.min.js"></script>
       	 <script src="../js/bootstrap-combobox.js"></script>
         <script src="../js/functions.js"></script>
           <script type="text/javascript">
             $(document).ready(function(){
              // $('.combobox').combobox();
               
       //        $('.grpline').css("width", "100px");
				
             });
           </script>
     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
	<style>
		.tooltip-inner {
			white-space:pre-wrap;
		}
	</style>
   </head>
   <body>
       <?php
		include("navbar.php");
		//$customer = new Customer($_REQUEST['an']);
	   ?>     
   <!-- Stack the columns on mobile by making one full-width and the other half-width -->
     <div class="container " style="margin-top: -10px;">
		<div class="page-header">
		
		<center>
			<h2 class="visible-print-block"><?= $config['CompanyName'] ?></h2>
			<h3 class="visible-print-block center">A G I N G</h3>
		</center>
		<a class="btn btn-primary hidden-print pull-right" onclick="window.print();" href="#">Print</a>
       
		</div>
	</div>
     
	
    <div class="row">
		<div class="col-md-12">
          

		<table class="table table-condensed" id="">

			<thead id="">
				<tr>
				  <th style="width: 15%">AccountNumber</th>
				  <th style="width: 40%;">Name</th>
				  <th style="width: 5%;">Days</th>
				  <th style="width: 10%; text-align: right;">0 to 30 Days</th>
				  <th style="width: 10%; text-align: right;">31 to 60 Days</th>
				  <th style="width: 10%; text-align: right;">91 to 90 Days</th>
				  <th style="width: 10%; text-align: right;">Over 90 Days</th>
				  <th style="width: 10%; text-align: right;">Balance</th>
				</tr>
			</thead>

		<tbody id="paymentTableBody">
		<?php
		
		$query = "SELECT *, MAX(ElapsedDays) DueDays FROM `ACCOUNTS_RECEIVABLE_AGING` WHERE Balance != 0 GROUP BY AccountNumber ORDER BY AccountNumber";
		$result = mysqli_query($con, $query);
		$totalDue = 0;
		while($row = mysqli_fetch_array($result)){
			$totalDue += $row['Balance'];
		$customer = new Customer($row['AccountNumber']);
		?>
			<tr>
				<td><?= $customer->AccountNumber ?></td>
				<td><?= $customer->Name ?></td>
				<td><?= $row['DueDays'] ?></td>
				
				<td style="text-align: right;"><?= moneyFormat($row['0To30']) ?></td>
				<td style="text-align: right;"><?= moneyFormat($row['31To60']) ?></td>
				<td style="text-align: right;"><?= moneyFormat($row['61To90']) ?></td>
				<td style="text-align: right;"><?= moneyFormat($row['Over90']) ?></td>
				<td style="text-align: right;"><?= moneyFormat($row['Balance']) ?></td>
			</tr>
		<?php  
			
		}
		 ?>
			<tr>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td></td>
			   <td style="text-align: right;"><b><?= moneyFormat($totalDue) ?></b></td>
			</tr>
		   </tbody>
	   </table>
	
    <!--
	<input type="button" class="btn btn-primary" id="addNewInvoiceButton" value="Add New Invoice"/>
	-->
	
        </div>
    <hr />
 <script type="text/javascript">
 	
    $(document).ready(function () {
		
    });
	
 </script>

   </body>
 </html>