<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link href="<?=base_url();?>/assets/style.css" rel="stylesheet">
	<!-- <script>
        function closeWindow() {
            setTimeout(function() {
                window.close();
            }, 500); // 2000 milliseconds = 2 seconds
        }
    </script> -->
</head>

<body class='bg-white' onload="closeWindow()">

	<h4 class="mt-2 text-center fw-bold"> Data Activity Periode </h4>

	<div class='text-center'>
		<button id='saveButton' class='btn btn-success' onclick="exportToExcel()">Simpan Excel</button>	
	</div>
	
	<div class="row p-5">
		<div class="col-12">	
			<div class="table-responsive">
				<table id="myTable" class="table table-bordered">
					<thead>
						<tr>
							<th scope="col">No</th>
							<th scope="col">Product ID</th>
							<th scope="col">Product Name</th>
							<th scope="col">Product Number</th>
							<th scope="col">Catalog Number</th>
							<th scope="col">Product Owner</th>
							<th scope="col">Owner Account</th>
							<th scope="col">Status Service</th>
							<th scope="col">Status Parts</th>
							<th scope="col">Type</th>
							<th scope="col">Manufacturer</th>
							<th scope="col">Site Name</th>
							<th scope="col">City</th>
							<th scope="col">Province</th>
							<th scope="col">Installation Date</th>
							<th scope="col">Start Date</th>
							<th scope="col">End Date</th>
							<th scope="col">Warranty Start</th>
							<th scope="col">Warranty End</th>
							<th scope="col">Active Status</th>
						</tr>
					</thead>
					<tbody>
						<?php foreach ($products as $index => $item): ?>
							<tr>
								<td><?= $index + 1 ?></td>
								<td><?= htmlspecialchars($item['productid'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['productname'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['productnumber'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['catalognumber'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['productowner'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['owneraccount'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['service'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['statuspart'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['type_name'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['manufacturer'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['sitename'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['city'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['prov'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['installationdate'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['locationstartdate'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['locationenddate'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['warrantystartdate'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['warrantyenddate'] ?? '') ?></td>
								<td><?= htmlspecialchars($item['active'] != 2 ? 'Yes' : 'No' ) ?></td>
							</tr>
						<?php endforeach; ?>
					</tbody>
				</table>
			</div>
		</div>
		
	</div>
<script src="<?=base_url();?>/assets/xlsx.mini.min.js"></script>
<script>
function exportToExcel() {
	const data = document.getElementById("myTable");
	var ws = XLSX.utils.table_to_sheet(data);
	var wb = XLSX.utils.book_new();
	XLSX.utils.book_append_sheet(wb, ws, "Sheet 1");
	XLSX.writeFile(wb, "ProductsList.xlsx");
}
window.onload = function() {
	document.getElementById('saveButton').click();
	window.close();
}
</script>
</body>

</html>