<style>
	.bootstrap-select>.dropdown-toggle.bs-placeholder,
	.bootstrap-select>.dropdown-toggle.bs-placeholder:hover,
	.bootstrap-select>.dropdown-toggle.bs-placeholder:focus,
	.bootstrap-select>.dropdown-toggle.bs-placeholder:active {
		height: 38px;
	}

	.bootstrap-select .dropdown-toggle .filter-option-inner {
		margin-top: 4px;
		margin-left: 4px;
	}

	.form-group .bootstrap-select>.dropdown-toggle {
		height: 38px;
	}
</style>
<div class="wraper responsive-width">
	<main>
		<div class="admin_tempblock">
			<div class="admin_tempsec">
				<div class="admin_sec">
					<div class="subsec_sec">
						<div class="subject_r subject_r_lng">
							<div class="subject_lsec">

								<div class="mb-4">
									<nav aria-label="breadcrumb">
										<ol class="breadcrumb">
											<li class="breadcrumb-item"><a href="<?= base_url() . 'admin/inventory/dashboard' ?>">Dashboard</a></li>
											<li class="breadcrumb-item active" aria-current="page"><?= $title ?></li>
										</ol>
									</nav>
								</div>

								<?php if ($this->session->flashdata('success')) { ?>
									<div class="alert alert-success alert-dismissible fade show" role="alert">
										<p><b> Success !</b> <?php echo $this->session->flashdata('success') ?></p>
										<button type="button" class="close" data-dismiss="alert" aria-label="Close">
											<span aria-hidden="true">&times;</span>
										</button>
									</div>
								<?php } ?>

								<?php if ($this->session->flashdata('danger')) { ?>
									<div class="alert alert-danger alert-dismissible fade show" role="alert">
										<p><b> Error !</b> <?php echo $this->session->flashdata('danger') ?></p>
										<button type="button" class="close" data-dismiss="alert" aria-label="Close">
											<span aria-hidden="true">&times;</span>
										</button>
									</div>
								<?php } ?>
								<div class="d-flex justify-content-end mb-3 small">
									<b style="font-weight: 500">Quick Links:</b>
									<a href="<?= base_url() ?>admin/inventory/book-publication" class="text-primary px-1"> Publications </a> |
									<a href="<?= base_url() ?>admin/inventory/item-categories" class="text-primary px-1"> Item Categories </a> |
									<a href="<?= base_url() ?>admin/inventory/items" class="text-primary px-1"> Items </a> |
									<a href="<?= base_url() ?>admin/inventory/item-stocks" class="text-primary px-1"> Stocks </a> |
									<a href="<?= base_url() ?>admin/inventory/add-edit-new-entry/0" class="text-primary px-1"> New Purchase Entry </a> |
									<a href="<?= base_url() ?>admin/inventory/add-new-sales-record/0" class="text-primary px-1"> New Sales Entry </a>
								</div>

								<div class="row justify-content-center ">

									<div class="row w-100 mb-4">
										<div class="col">
											<div class="float-right w-25 ">
												<a class="btn btn-sm float-right btn-outline-success" href="<?= base_url() ?>admin/inventory/add-new-sales-record/0">
													Add New Entry
												</a>
											</div>
										</div>
									</div>
									<div class="clearfix"></div>
									<div class="col-md-12">
										<div class="col-md-12 border rounded py-3">

											<!--  -->
											<table id="tbl" class="display table-responsive">
												<thead>
													<tr>
														<th class="textCenter">S.No</th>
														<th class="textCenter">Name</th>
														<th class="textCenter">Item</th>
														<th class="textCenter">Purchased On</th>
														<th class="textCenter">Qty</th>
														<th class="textCenter">Unit Price</th>
														<th class="textCenter">Total Price</th>
														<th class="textCenter noExport">Action</th>
													</tr>
												</thead>
												<tbody>
													<?php
													foreach ($sales_list as $s_key => $sales) {
														// echo '<pre>';
														// print_r($sales);
													?>
														<tr>
															<td><?= $s_key + 1 ?></td>
															<td class="text-left"><?= $sales['name'] ?></td>
															<td class="text-left"><?= $sales['title'] ?>
															<td>
																<?php

																$date_time = explode(' ', $sales['sales_on']);
																echo $date_time[0];
																?>
															</td>
															<td><?= $sales['qty'] ?></td>
															<td><?= $sales['unit_price'] ?></td>
															<td><?= $sales['total_amount'] ?></td>
															<td>

																<a href="<?= base_url() . 'admin/inventory/view-invoice/' . urlsafe_b64encode($sales['salesId']) ?>" class="mr-1" data-toggle="tooltip" title="Invoice" target="_blank">
																	<i class="fas fa-file-invoice text-primary fa-lg"></i>
																</a>
																<a href="<?= base_url() . 'admin/inventory/view-sales-detail/' . $sales['id'] ?>" data-toggle="tooltip" title="View" target="_blank">
																	<i class="fa fa-eye text-primary fa-lg"></i>
																</a>
															</td>
														</tr>
													<?php
													}
													?>
												</tbody>
												<tfoot>
													<th></th>
													<th></th>
													<th></th>
													<th>Total (In <?= $school_info['currency_symbol'] ?>)</th>
													<th class="text-center"></th>
													<th class="text-center"></th>
													<th class="text-center"></th>
													<th></th>
												</tfoot>
											</table>
										</div>

									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</main>

</div>
<script defer src="<?php echo base_url(); ?>assets_admin/js/bootstrap-select.min.js"></script>


<!--End right-top side-->

<!-- <script src="<?php echo base_url(); ?>assets-bustracking/js/jquery-3.2.1.slim.min.js"></script> -->
<script>
	$(document).ready(function() {
		$("#course-section").hide();
		var jsTheExportHeader = '<?php echo $theExportHeader; ?>';
		//table js
		$('#tbl').DataTable({
			"dom": 'lBfrtip',
			"lengthMenu": [
				[25, 50, 100, 150, -1],
				[25, 50, 100, 150, "All"]
			],
			buttons: [{
					extend: 'pdfHtml5',
					// orientation: 'landscape',
					exportOptions: {
						columns: "thead th:not(.noExport)",
						rows: function(indx, rowData, domElement) {
							return $(domElement).css("display") != "none";
						},
						stripNewlines: false,
						stripHtml: true
					},
					orientation: 'landscape',
					pageSize: 'A4'
					// messageTop: 'The information in this table is copyright to Sirius Cybernetics Corp.'
				},
				{
					extend: 'print',
					exportOptions: {
						columns: "thead th:not(.noExport)",
						rows: function(indx, rowData, domElement) {
							return $(domElement).css("display") != "none";
						},
						stripNewlines: false,
						stripHtml: true
					},
				},
				{
					extend: 'excelHtml5',
					header: true,
					footer: true,
					title: jsTheExportHeader,

					exportOptions: {
						columns: "thead th:not(.noExport)",
						rows: function(indx, rowData, domElement) {
							return $(domElement).css("display") != "none";
						},
						stripNewlines: false,
						stripHtml: true,

					},
					customize: function(xlsx) {
						var sheet = xlsx.xl.worksheets['sheet1.xml'];

						$('row c[r^="C"]', sheet).attr('s', '2');
					}
				}
			],
			"footerCallback": function(row, data, start, end, display) {
				//var theDynTdCnt = (theTdCnt - 7);
				var api = this.api();

				// Remove the formatting to get integer data for summation
				var intVal = function(i) {
					return typeof i === 'string' ? i.replace(/[\$,]/g, '') * 1 : typeof i === 'number' ? i : 0;
				};

				// Total over all pages
				total = api
					.column(4)
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

				// Total over this page
				pageTotal = api
					.column(4, {
						page: 'current'
					})
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

				pageTotal5 = api
					.column(5, {
						page: 'current'
					})
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

				pageTotal6 = api
					.column(6, {
						page: 'current'
					})
					.data()
					.reduce(function(a, b) {
						return intVal(a) + intVal(b);
					}, 0);

				// Update footer
				$(api.column(4).footer()).html(pageTotal);
				$(api.column(5).footer()).html(pageTotal5);
				$(api.column(6).footer()).html(pageTotal6);
			}
		});
	});
</script>