<!DOCTYPE html>
<html>
	<head>
		<title><?php echo $title; ?></title>
		<base href="<?php echo base_url(); ?>">
		<meta charset="utf-8">
		<!-- Tell the browser to be responsive to screen width -->
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

		<link rel="shortcut icon" href="assets/images/favicon.png" type="image/x-icon">

		<!-- Theme style -->
		<link rel="stylesheet" href="assets/AdminLTE-3.2.0/dist/css/adminlte.min.css">

		<!-- Google Font: Source Sans Pro -->
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
	</head>

	<body>
		<div class="wrapper">
			<!-- Main content -->
			<section class="content">
				<div class="container-fluid">
					<!-- Small boxes (Stat box) -->
					<div class="row">
						<div class="col-md-12">
							<!-- Invoice content -->
							<div class="invoice p-3 mb-3">
								<!-- title row -->
								<div class="row mb-4">
									<div class="col-12">
										<h2 class="page-header">
											<img src="<?php echo $this->session->company_logo; ?>" width="115" class="img">
											<small class="float-right"><?php echo $this->session->company_name; ?></small>
										</h2>
										<h3 class="text-center">Income Statement</h3>
									</div>
								</div>

								<!-- info row -->
								<div class="row invoice-info mb-4">
									<div class="col-md-6 invoice-col">
										<strong>Date From:</strong> <?php echo date( 'jS M, Y ', strtotime( date_to_db( $start_date ) ) ); ?><br>
										<strong>Date To:</strong> <?php echo date( 'jS M, Y ', strtotime( date_to_db( $end_date ) ) ); ?>
									</div>
								</div>

								<!-- Table row -->
								<div class="row">
									<div class="col-md-12">
										<table class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th colspan="3" class="text-left">Reveniue</th>
												</tr>
												<tr>
													<th class="col-md-8">Name of Account</th>
													<th class="col-md-2 text-right">Debit</th>
													<th class="col-md-2 text-right">Credit</th>
												</tr>
											</thead>
											<tbody>
												<?php
													$debit  = 0;
													$credit = 0;
													foreach ( $reveniues as $reveniue ):
												?>
												<tr>
													<td><?php echo $reveniue['chart_name']; ?></td>
													<td class="text-right"><?php echo number_format( $reveniue['debit'] ?? 0, 2 ); ?></td>
													<td class="text-right"><?php echo number_format( $reveniue['credit'] ?? 0, 2 ); ?></td>
												</tr>
												<?php
														$debit += $reveniue['debit'];
														$credit += $reveniue['credit'];
													endforeach;
												?>
											</tbody>
											<tfoot>
												<tr>
													<td><b>Gross Total</b></td>
													<td class="text-right"><b><?php echo number_format( $debit ?? 0, 2 ); ?></b></td>
													<td class="text-right"><b><?php echo number_format( $credit ?? 0, 2 ); ?></b></td>
												</tr>
												<tr>
													<td><b>Net Balance</b></td>
													<td class="text-right" colspan="2"><?php echo number_format(  ( $debit ?? 0 - $credit ?? 0 ), 2 ); ?></td>
												</tr>
											</tfoot>
										</table>
									</div>
								</div>

								<!-- Table row -->
								<div class="row">
									<div class="col-md-12">
										<table class="table table-striped table-bordered table-hover">
											<thead>
												<tr>
													<th colspan="3" class="left">Expense</th>
												</tr>
												<tr>
													<th class="col-md-8">Name of Account</th>
													<th class="col-md-2 text-right">Debit</th>
													<th class="col-md-2 text-right">Credit</th>
												</tr>
											</thead>
											<tbody>
												<?php
													$debit  = 0;
													$credit = 0;
													foreach ( $expenses as $expense ):
												?>
												<tr>
													<td><?php echo $expense['chart_name']; ?></td>
													<td class="text-right"><?php echo number_format( $expense['debit'] ?? 0, 2 ); ?></td>
													<td class="text-right"><?php echo number_format( $expense['credit'] ?? 0, 2 ); ?></td>
												</tr>
												<?php
														$debit += $expense['debit'];
														$credit += $expense['credit'];
													endforeach;
												?>
											</tbody>
											<tfoot>
												<tr>
													<td><b>Gross Total</b></td>
													<td class="text-right"><b><?php echo number_format( $debit ?? 0, 2 ); ?></b></td>
													<td class="text-right"><b><?php echo number_format( $credit ?? 0, 2 ); ?></b></td>
												</tr>
												<tr>
													<td><b>Net Balance</b></td>
													<td class="text-right" colspan="2"><?php echo number_format(  ( $debit ?? 0 - $credit ?? 0 ), 2 ); ?></td>
												</tr>
											</tfoot>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
		</div>
	</body>
</html>