<!-- 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">Sales</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="inventory">Inventory</a></li>
					<li class="breadcrumb-item"><a href="inventory/sales-list">Sales</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 class="page-header">
								<?php echo $this->session->company_name; ?>
								<small class="float-right">Date:<?php echo date_to_ui( $master[0]['sales_date'] ); ?></small>
							</h4>
							<h3 class="text-center">Sales Invoice</h3>
						</div>
					</div>

					<!-- info row -->
					<div class="row invoice-info mb-4">
						<div class="col-md-6 invoice-col">
							<strong>Sales #</strong> <?php echo $master[0]['sales_no']; ?><br>
							Notes: <?php echo $master[0]['notes']; ?><br>
						</div>

						<div class="col-md-6 invoice-col">
							<strong>Customer Details</strong>
							<address>
								<?php echo $master[0]['customer_name']; ?><br>
								Address: <?php echo $master[0]['customer_address']; ?><br>
								Mobile: <?php echo $master[0]['customer_mobile']; ?><br>
							</address>
						</div>
					</div>

					<!-- Table row -->
					<div class="row">
						<div class="col-md-12">
							<table class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>SL#</th>
										<th>ITEM DESCRIPTIONS</th>
										<th class="text-right">QTY</th>
										<th class="text-right">PRICE</th>
										<th class="text-right">TOTAL PRICE</th>
									</tr>
								</thead>
								<tbody>
									<?php
										$qty   = 0;
										$price = 0;
										$i     = 1;
										foreach ( $details as $detail ) {
										?>
										<tr>
											<td><?php echo $i; ?></td>
											<td><?php echo $detail['item_name']; ?></td>
											<td class="text-right"><?php echo $detail['quantity']; ?></td>
											<td class="text-right"><?php echo number_format( $detail['sale_price'], 2 ); ?></td>
											<td class="text-right"><?php echo number_format( $detail['quantity'] * $detail['sale_price'], 2 ); ?></td>
										</tr>
										<?php
											$qty += $detail['quantity'];
											$price += $detail['quantity'] * $detail['sale_price'];
											$i++;
										}
									?>
								</tbody>
							</table>
						</div>
					</div>

					<!-- Table row -->
					<div class="row">
						<div class="col-md-6">
							&nbsp;
						</div>

						<div class="col-md-6">
							<table class="table">
								<tr>
									<th class="col-md-6">Sub - Total:</th>
									<td class="col-md-6 text-right">
										<?php if ( $this->session->currency_symbol_position == 'Before' ) {echo $this->session->currency_symbol;}?><?php echo number_format( $price, 2 ); ?><?php if ( $this->session->currency_symbol_position == 'After' ) {echo $this->session->currency_symbol;}?>
									</td>
								</tr>
								<tr>
									<th>VAT/TAX:</th>
									<td class="text-right">
										<?php if ( $this->session->currency_symbol_position == 'Before' ) {echo $this->session->currency_symbol;}?><?php echo number_format( $master[0]['tax_amount'], 2 ); ?><?php if ( $this->session->currency_symbol_position == 'After' ) {echo $this->session->currency_symbol;}?>
									</td>
								</tr>
								<?php $total_price = $price + $master[0]['tax_amount'];?>
								<tr>
									<th>Grand Total:</th>
									<td class="text-right">
										<?php if ( $this->session->currency_symbol_position == 'Before' ) {echo $this->session->currency_symbol;}?><?php echo number_format( $total_price, 2 ); ?><?php if ( $this->session->currency_symbol_position == 'After' ) {echo $this->session->currency_symbol;}?>
									</td>
								</tr>
							</table>
						</div>
					</div>

					<!-- This row will not appear when printing -->
					<div class="row no-print">
						<div class="col-md-12">
							<a href="inventory/sales-print/<?php echo $master[0]['sales_no']; ?>" 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>