<!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">Bills Payable</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 class="col-md-2">Journal Date</th>
													<th class="col-md-2 text-center">Journal No.</th>
													<th class="col-md-3 text-center">Name of Account</th>
													<th class="col-md-3">Transaction By/To</th>
													<th class="col-md-1 text-right">Debit</th>
													<th class="col-md-1 text-right">Credit</th>
													<!--<th class="center">Balance</th>-->
												</tr>
											</thead>
											<?php
												$debit  = 0;
												$credit = 0;
												foreach ( $previous as $pre ) {
													$debit += $pre['debit'];
													$credit += $pre['credit'];
												}
												if ( $opening_sum['opening'] > 0 ) {
													$debit += $opening_sum['opening'];
												} else {
													$credit += $opening_sum['opening'];
												}
												$opening = $debit - $credit;
											?>
											<tbody>
												<tr style="font-size: 16px; font-weight: bold;">
													<td colspan="4">Balance Forwarded</td>
													<td colspan="2" class="text-right"><?php echo number_format(  ( $debit ?? 0 - $credit ?? 0 ), 2 ); ?></td>
												</tr>
												<?php
													foreach ( $charts as $chart ):
												?>
													<tr>
														<td><?php echo date( 'jS M, Y ', strtotime( $chart['journal_date'] ) ); ?></td>
														<td class="text-center"><b><a href="accounts/journal_preview/<?php echo $chart['journal_id']; ?>" target="_blank"><?php echo $chart['journal_no']; ?></a></b></td>
														<td><?php echo $chart['chart_name']; ?></td>
														<td><?php echo $chart['ref_journal']; ?></td>
														<td class="text-right"><?php echo number_format( $chart['debit'] ?? 0, 2 ); ?></td>
														<td class="text-right"><?php echo number_format( $chart['credit'] ?? 0, 2 ); ?></td>
													</tr>
													<tr>
														<td>&nbsp;</td>
														<td colspan="5"><?php echo $chart['master_memo']; ?></td>
													</tr>
												<?php
														$debit += $chart['debit'];
														$credit += $chart['credit'];
													endforeach;
												?>
											</tbody>
											<tfoot>
												<tr style="font-size: 16px; font-weight: bold;">
													<td colspan="4"> Closing Balance</td>
													<td colspan="2" class="text-right"><?php echo number_format(  ( $debit ?? 0 - $credit ?? 0 ), 2 ); ?></td>
												</tr>
											</tfoot>
										</table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</section>
		</div>
	</body>
</html>