<!DOCTYPE html>
<html>

<head>
	<title>Expense Settlement Details</title>
</head>

<body>
	<div class="heading">
		<div class="logo">
			<img src="images/logo.png" alt="Logo" >
		</div>
	<!-- 	<div class="company_name text-right" style="margin-top: -30px;">
			<h3>D-Link</h3>
			<p>User: <?php echo $username; ?></p>
		</div> -->
	</div>

	<div class="table-body">
		<div class="title">
			<h1>Expense Settlement</h1>
		</div>
		<table class="table table-bordered table-primary">
			<tbody>
				<?php if (!empty($settlement)) : ?>
					<tr>
						<td><strong>Expense Settlement Date</strong></td>
						<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($settlement->settlement_date))); ?></td>
					</tr>
					<tr>
						<td><strong>User</strong></td>
						<td><?php echo htmlspecialchars($username); ?></td>
					</tr>
					<tr>
						<td><strong>Unsettled Expense</strong></td>
						<td style="text-align: right;"><?php echo number_format((float)$settlement->unsettled_expenses, 2, '.', ','); ?>
					</td>
				</tr>
			</tr>
			<tr>
				<td><strong>Balance</strong></td>
				<td style="text-align: right;"><?php echo number_format((float)$settlement->balance, 2, '.', ','); ?>
			</td>
		</tr>
		<tr>
			<td><strong>Amount Returned</strong></td>
			<td style="text-align: right;">
				<?php echo number_format((float)$settlement->amount_returned, 2, '.', ','); ?>

			</td>
		</tr>
		<tr>
			<td><strong>Amount Dispersed</strong></td>
			<td style="text-align: right;">
				<?php echo number_format((float)$settlement->amount_dispersed, 2, '.', ','); ?>

			</td>
		</tr>
		<tr>
			<td><strong>New Balance</strong></td>
			<td style="text-align: right;"><?php echo number_format((float)$settlement->new_balance, 2, '.', ','); ?>
		</td>
	</tr>
	<?php else : ?>
		<tr>
			<td colspan="2" style="text-align:center;">No settlement found</td>
		</tr>
	<?php endif; ?>
</tbody>
</table>
</div>

<div class="table-body">
	<div class="title">
		<h1>Unsettled Expense Details</h1>
	</div>
	<table class="table table-bordered table-primary">
		<thead>
			<tr>
				<th>No</th>
				<th>Expense Date</th>
				<th>Expense Type</th>
				<th>Description</th>
				<th>Account Number</th>
				<th style="text-align:right;">Amount</th>
			</tr>
		</thead>
		<tbody>
			<?php if (!empty($expense_details)) : ?>
				<?php 
				$i = 1; 
				$grandTotal = 0;
				?>
				<?php foreach ($expense_details as $expense) : ?>
					<?php 
					$amount = (float)$expense->amount;
					$grandTotal += $amount;
					?>
					<tr>
						<td><?php echo $i++; ?></td>
						<td><?php echo htmlspecialchars(date('d/m/Y', strtotime($expense->expense_date))); ?></td>
						<td><?php echo htmlspecialchars($expense->expense_type_name); ?></td>
						<td><?php echo htmlspecialchars($expense->description); ?></td>
						<td><?php echo htmlspecialchars($expense->account_no); ?></td>
						<td style="text-align:right;">
							<?php echo number_format($amount, 2, '.', ','); ?>
						</td>
					</tr>
				<?php endforeach; ?>

				<tr>
					<td colspan="5" style="text-align:right; font-weight:bold;">
						Total Amount
					</td>
					<td style="text-align:right; font-weight:bold;">
						<?php echo number_format($grandTotal, 2, '.', ','); ?>
					</td>
				</tr>

				<?php else : ?>
					<tr>
						<td colspan="6" style="text-align:center;">No records found</td>
					</tr>
				<?php endif; ?>
			</tbody>
		</table>

		<br><br>

		<br><br>

		<table width="100%" style="margin-top:40px;">
			<tr>
				<td width="50%" style="text-align:left; vertical-align:top;">
					Prepared By
					<br><br>
					<span>_______________________________</span>
				</td>

				<td width="50%" style="text-align:right; vertical-align:top;">
					Accepted By
					<br><br>
					<span>_______________________________</span>
				</td>
			</tr>
		</table>


	</div>
</body>

</html>
