<?php 
include_once("../connect.php");
global $con;
include_once("../session.php");

if(isset($_REQUEST['id'])){
	$id = $_REQUEST['id'];
}else{
	header('Location: index.php');
	exit();
}
$query = "SELECT * FROM COMMISSION_HISTORY_HEAD WHERE ID = $id";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_array($result);
$batchNotes = $row['Notes'];
$batchPeriod = $row['Period'];
$batchUser = $row['User'];
$batchDate = $row['TransactionDate'];


 ?>
 
 <!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">-->
     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
     <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/fileinput.js"></script>
       	 <script src="../js/bootstrap-combobox.js"></script>
				 <script src="../js/bootstrap-waitingfor.min.js"></script>
				 
				 <script src="../js/functions.js"></script>
           <script type="text/javascript">
             $(document).ready(function(){
				//				$('#salesDataTable').DataTable();
             });
           </script>

     <![endif]-->
	<link rel="stylesheet" href="../css/styles.css"/>
	<link rel="stylesheet" href="../css/fileinput.min.css"/>
	
	<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs-3.3.6/dt-1.10.12/af-2.1.2/fh-3.1.2/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs-3.3.6/dt-1.10.12/af-2.1.2/fh-3.1.2/r-2.1.0/sc-1.4.2/se-1.2.0/datatables.min.js"></script>

   </head>
   <body>
<?php 
	include("navbar.php");

?>
        
   <!-- Stack the columns on mobile by making one full-width and the other half-width -->
	<div class="container-fluid">
		<div class="row">
			<div class="col-xs-8">
				<h3 class="page-header">Monthly Tax Summary</h3>
			</div>
			<div class="col-xs-4">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">Batch ID: <?= $id ?> (<?= date("d M Y h:i", strtotime($batchDate)) ?>)</h3>
					</div>
					<div class="panel-body" style="">
						<b>Period: </b><?= date("M Y", strtotime($batchPeriod)) ?><br />
						<b>User: </b><?= $batchUser ?><br />
						<b>Notes: </b><?= $batchNotes ?>
					</div>
				</div>
			</div>
		</div>
		
		<div class="row">
			<div class="col-xs-12">
				<h4 class="page-header"></h4>
			</div>
		</div>
		
		<div class="row">
			<div class="col-xs-8">
				<table class="table" id="TaxSummaryEV">
					<thead>
						<tr>
							<th>Location</th>
							<th>Total Payments</th>
							<th>Total IVU</th>
							<th>10.5 %</th>
							<th>1 %</th>
							<th>10.5 % + 1 %</th>
						</tr>
						
					</thead>
					<tbody>
					<?php
						
						
						$query = "SELECT Branch, round(SUM(PaymentAmt),2) as TotalPaymentAmount, round(SUM(IVU),2) as TotalTaxAmount, round(SUM(IVU_E),2) as TotalStateTax, round(SUM(IVU_M),2) as TotalMunicipalTax, round(sum(IVU_E+IVU_M),2) as StateMunicipal FROM `PAYMENT_TAX_DETAIL` WHERE RunID = $id GROUP BY Branch";
						
						$result = mysqli_query($con, $query);
						while($row = mysqli_fetch_array($result)){
							
						
							
					?>
						
						<tr>
							<td><?= $row['Branch'] ?></td>
							<td><?= moneyFormat($row['TotalPaymentAmount']); ?></td>
							<td><?= moneyFormat($row['TotalTaxAmount']); ?></td>
							<td><?= moneyFormat($row['TotalStateTax']); ?></td>
							<td><?= moneyFormat($row['TotalMunicipalTax']); ?></td>
							<td><?= moneyFormat($row['StateMunicipal']); ?></td>
							
						</tr>
					<?php
						}
					?>
					</tbody>
				</table>
			</div>
			<div class="col-xs-4">
				<div class="panel panel-default">
					<div class="panel-heading">
						<h3 class="panel-title">Process Reports</h3>
					</div>
					<div class="panel-body">
						<table class="table">
							<thead>
								<tr>
									<th>Report Type</th>
									<th></th>
								</tr>
							</thead>
							<tbody>
								<tr>
									<td>Regular Report (no exceptions)</td>
									<td><a id="processRegReportBtn" class="btn btn-success" onclick="processRegular()" href="#">Process</a></td>
								</tr>
								<tr>
									<td>Exceptions Report</td>
									<td><a class="btn btn-success" onclick="processExceptions()" href="#">Process</a></td>
								</tr>
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
		
	

     <script type="text/javascript">
			function processRegular(){
				alert('The report will begin to process now... the page will reload automatically');
				$.get('mod.php?p=commission&a=functions&f=processPaymentTaxRegular&id=<?= $id ?>', function(data){
					location.reload();	
						
				});
			}
			function processExceptions(){
				alert('The report will begin to process now... the page will reload automatically');
				$.get('mod.php?p=commission&a=functions&f=processPaymentTaxExceptions&id=<?= $id ?>', function(data){
					location.reload();	
						
				});
			}
     </script>
		 	<style>
				#iFrameModalUrl{
					width: 100%;
					height: 500px;
					border: none;
				}
				
			</style>
			
		 
   </body>
 </html>