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


$isAdmin = $_SESSION['isAdmin'];
if (!$isAdmin) {
	header("Location: logout.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="<?= $root ?>css/bootstrap.min.css" rel="stylesheet">
      <link rel="stylesheet" href="<?= $root ?>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="<?= $root ?>js/bootstrap.min.js"></script>
        	 <script src="<?= $root ?>js/bootstrap-combobox.js"></script>
            <script type="text/javascript">
              $(document).ready(function(){
        //        $('.grpline').css("width", "100px");
              });
            </script>
 
      <![endif]-->
 	<link rel="stylesheet" href="<?= $root ?>css/styles.css"/>
	<style>
		.paymentSummaryHeader{
			font-weight: bold;
		}
		
	</style>
    </head>
    <body>
    
        <?php 
        		include("navbar.php"); 
        		
 
        ?>     
 
    
    <!-- Stack the columns on mobile by making one full-width and the other half-width -->
 <?php
 $depositID = $_REQUEST['id'];
 $deposit = new PaymentDeposit($depositID);
 
 
 ?>
 <div class="container-fluid" style="padding-top: 5px;">
 	<div class="row">
 	  <div class="col-xs-5">
 	  	<img class="img-responsive" style="width: 200px;" src="<?= $root ?>img/<?= $config['Logo'] ?>" alt="" />
 	  	
 	  </div>
  	  <div class="col-xs-1"></div>
	  <div class="col-xs-6 pull-right" style="margin-top: -20px;  text-align: right;">
 		  
 		  <h3>Deposit</h3>
		  
		  <p style="margin-top: -90px;">
 		  	<h1><span style="padding-left: 20px;"><b><?= $deposit->DepositID ?></b></span></h1>
          </p>
			
 		  	<h1 class="hidden-print" style="margin-top: 100px;"><span ><b><?= $deposit->DepositID ?></b></span></h1>
			<?= insertPrintButton(); ?>
			<br>
			
 		  <b>Date: </b><?= date("m/d/Y",strtotime($deposit->DepositDate)) ?><br>
		  <b>Creation Date: </b><?= date("m/d/Y h:i a",strtotime($deposit->CreationDate)) ?><br>
		  <b>Created By: </b><?php
		  echo $deposit->Username;
		  
		  //$createdBy = new Administrator($deposit->Username);
		  //echo $createdBy;
		  
		  ?>
		  <br>
		  <b>Deposited By: </b><?= $deposit->DepositorName ?>
		  
 	  </div>
 	  
	</div> 
	<div class="row">
			<div class="col-xs-8">
				<h4>Deposit Detail</h4>
				<table class="table table-condensed">
					<thead>
						<tr>
							<th>Type</th>
							<th>Name</th>
							<th style="text-align: right;">Reference</th>
							<th style="text-align: center;">Reconciliation</th>
							<th style="text-align: right;">Amount</th>
						</tr>
					</thead>
					<tbody>
						<?php
						foreach($deposit->CashPayments as $pmt){
							//var_dump($pmt);
						?>
						<tr>
							<td>Cash</td>
							<td><?= ($pmt->Customer) ?></td>
							<td></td>
							<td style="text-align: center;"><?= $pmt->Payment->getPaymentReconciliation() ?></td>
							<td style="text-align: right;"><?= moneyFormat($pmt->CashAmount) ?></td>
						</tr>
						<?php
						}
						?>
						
						<?php
						
						
						$checksCount = 0;
						$totalChecks = 0;
						foreach($deposit->Checks as $check){
							
						
						$checksCount++;
						$totalChecks += $check->Amount;
				  ?>
					  <tr>
							  <td>Check</td>
							  <td>
								  <span class="itemInfo"><?= $check->CustomerName ?></span>
							  </td>						
							  <td style="text-align: right;">
								  <span class="itemInfo"><?= $check->Number ?></span>
							  </td>
							  <td style="text-align: center;"><?= $check->Payment->getPaymentReconciliation() ?></td>
							  <td style="text-align: right;">
								  <span class="itemInfo"><?= moneyFormat($check->Amount) ?></span>
							  </td>
							  
					  </tr>
					  <?php 
					  
					  }?>
					</tbody>
				</table>
			</div>
			<div style="border-left: solid;" class="col-xs-4">
				<h4>Deposit Summary</h4>
				<table class="table table-condensed">
					<thead>
						<tr>
							<th>Type</th>
							<th style="text-align: right;">Amount</th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td>Cash</td>
							<td  style="text-align: right;"><?= moneyFormat($deposit->TotalCash) ?></td>
						</tr>
						<tr>
							<td>Check</td>
							<td style="text-align: right;"><?= moneyFormat($totalChecks) ?></td>
						</tr>
						<tr>
							<td><b>Total</b></td>
							<td style="text-align: right;"><b><?= moneyFormat($deposit->TotalCash+$totalChecks) ?></b></td>
						</tr>
					</tbody>
				</table>
			</div>
			<hr>
			<div style="border-left: solid;"  class="pull-right col-xs-4">
				<h4>Deposit Information</h4>
				<div class="panel" style="text-align: center; font-weight: bold;">
					<span>PAY TO THE ORDER OF</span><br/>
					<span><?= getSetting('DepositBankName')['value']; ?></span><br/>
					<span><?= getSetting('DepositBankBranch')['value']; ?></span><br/>
					<span>FOR DEPOSIT ONLY</span><br/>
					<span><?= getSetting('DepositBankAccountName')['value']; ?></span><br/>
					<span><?= getSetting('DepositBankAccountNumber')['value']; ?></span>
					
				</div>
			</div>
		
	</div>
	
</div>
 
        <div class="panel panel-default">
          <div class="panel-body">
           <span><b><big>Notes: </big></b><?= $deposit->Notes ?></span>
		   
          </div>
        </div>
        
    </body>
  </html>