<!-- Content Header (Page header) -->
<section class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1 class="m-0">Journal</h1>
			</div>

			<div class="col-sm-6">
				<ol class="breadcrumb float-sm-right">
					<li class="breadcrumb-item"><a href="dashboard">Dashboard</a></li>
					<li class="breadcrumb-item"><a href="accounts">Accounts</a></li>
					<li class="breadcrumb-item"><a href="accounts/journal-list">Journal</a></li>
					<li class="breadcrumb-item active">Preview</li>
				</ol>
			</div>
		</div>
	</div>
</section>

<!-- 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">
							<h4>
								<?php echo $this->session->company_name; ?>
								<small class="float-right">Date:<?php echo date_to_ui( $master['journal_date'] ); ?></small>
							</h4>
							<h3 class="text-center">Journal Voucher</h3>
						</div>
					</div>

					<!-- info row -->
					<div class="row invoice-info mb-4">
						<div class="col-md-12 invoice-col">
							<strong>Journal #</strong> <?php echo $master['journal_no']; ?><br>
							<strong>Notes:</strong> <?php echo $master['memo']; ?><br>
						</div>
					</div>

					<!-- Table row -->
					<div class="row">
						<?php
							$d = 0;
							$c = 0;
							foreach ( $details as $list ) {
								if ( $list['debit'] ) {
									$d++;
								} else {
									$c++;
								}
							}
						?>
						<div class="col-md-6">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>Debit Account</th>
										<th class="text-right col-md-4">Amount</th>
									</tr>
								</thead>
								<tbody>
								<?php
									$debit_amount = 0;
									foreach ( $details as $list ) {
										if ( $list['debit'] ) {
										?>
										<tr>
											<td><?php echo $list['chart_name']; ?></td>
											<td class="text-right col-md-4"><?php echo number_format( $list['debit'], 2 ); ?></td>
										</tr>
										<?php
											$debit_amount += $list['debit'];
										}
									}
								?>
								</tbody>
							</table>
						</div>

						<div class="col-md-6">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>Credit Account</th>
										<th class="text-right col-md-4">Amount</th>
									</tr>
								</thead>
								<tbody>
								<?php
									$credit_amount = 0;
									foreach ( $details as $list ) {
										if ( $list['credit'] ) {
										?>
										<tr>
											<td><?php echo $list['chart_name']; ?></td>
											<td class="text-right col-md-4"><?php echo number_format( $list['credit'], 2 ); ?></td>
										</tr>
										<?php
											$credit_amount += $list['credit'];
										}
									}
								?>
								</tbody>
							</table>
						</div>
					</div>

					<!-- Table row -->
					<div class="row">
						<div class="col-md-6">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th class="text-center">Total</th>
										<th class="text-right col-md-4">
											<?php if ( $this->session->currency_symbol_position == 'Before' ) {echo $this->session->currency_symbol;}?><?php echo number_format( $debit_amount, 2 ); ?><?php if ( $this->session->currency_symbol_position == 'After' ) {echo $this->session->currency_symbol;}?>
										</th>
									</tr>
								</thead>
							</table>
						</div>

						<div class="col-md-6">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th class="text-center">Total</th>
										<th class="text-right col-md-4">
										<?php if ( $this->session->currency_symbol_position == 'Before' ) {echo $this->session->currency_symbol;}?><?php echo number_format( $credit_amount, 2 ); ?><?php if ( $this->session->currency_symbol_position == 'After' ) {echo $this->session->currency_symbol;}?>
										</th>
									</tr>
								</thead>
							</table>
						</div>
					</div>

					<!-- This row will not appear when printing -->
					<div class="row no-print">
						<div class="col-md-12">
							<a href="accounts/journal-print/<?php echo $master['id']; ?>" target="_blank" class="btn btn-default"><i class="fa fa-print"></i> Print</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>

<div class="clearfix"></div>