<?php
require("../connection.php");
include("../user.php");
// error_reporting(E_ALL);
// ini_set('display_errors', 1);
$user_id = $_SESSION['user'];
$username = $_SESSION['user_name'];
$branch = $_SESSION['division_name'];
$location = $_SESSION['location'];
?>
<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title><?php echo TITLE; ?></title>
	<meta name="description" content="Ela Admin - HTML5 Admin Template">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<link rel="apple-touch-icon" href="../images/bluebase.png">
	<link rel="shortcut icon" href="../images/bluebase.png">

	<link rel="stylesheet" href="../css/normalize.min.css">
	<link rel="stylesheet" href="../css/bootstrap.min.css">
	<link rel="stylesheet" href="../css/font-awesome.min.css">
	<link rel="stylesheet" href="../css/themify-icons.css">
	<link rel="stylesheet" href="../css/pe-icon-7-stroke.min.css">
	<link rel="stylesheet" href="../css/flag-icon.min.css">
	<link rel="stylesheet" href="../assets/css/cs-skin-elastic.css">
	<link rel="stylesheet" href="../assets/css/style.css">
	<link href="../css/chartist.min.css" rel="stylesheet">
	<link href="../css/jqvmap.min.css" rel="stylesheet">
	<link href="../css/weather-icons.css" rel="stylesheet" />
	<link href="../css/fullcalendar.min.css" rel="stylesheet" />

	<script src="../js/jquery-1.12.4.min.js"></script>
	<script src="../js/jquery-3.3.1.js"></script>
	<script src="../js/jquery.dataTables.min.js"></script>
	<script src="../js/popper.min.js"></script>
	<script src="../js/bootstrap.min.js"></script>
	<script src="../js/jquery.matchHeight.min.js"></script>
	<script src="../assets/js/main.js"></script>
	<script src="../js/jquery-3.3.1.min.js"></script>
	<script src="../js/sweet-alert.min.js"></script>


	<style>
		#weatherWidget .currentDesc {
			color: #ffffff !important;
		}

		.traffic-chart {
			min-height: 335px;
		}

		#flotPie1 {
			height: 150px;
		}

		#flotPie1 td {
			padding: 3px;
		}

		#flotPie1 table {
			top: 20px !important;
			right: -10px !important;
		}

		.chart-container {
			display: table;
			min-width: 270px;
			text-align: left;
			padding-top: 10px;
			padding-bottom: 10px;
		}

		#flotLine5 {
			height: 105px;
		}

		#flotBarChart {
			height: 150px;
		}

		#cellPaiChart {
			height: 160px;
		}

		th,
		td {
			text-transform: uppercase;
		}
	</style>

	<link rel="stylesheet" href="/asset_temp/datatable/css/jquery.dataTables.min.css">
	<script src="/asset_temp/datatable/js/jquery.dataTables.min.js"></script>

	<link rel="stylesheet" type="text/css" href="/asset_temp/button/css/buttons.css" />

	<script>
		$(document).ready(function () {
			$('#example').DataTable();
		});

		function printtab() {
			var print_table = document.getElementById('example');
			newWin = window.open("");
			newWin.document.write(print_table.outerHTML);
			newWin.print();
			newWin.close();
		}		
	</script>
	<?php require("../mainjavascript.js"); ?>
</head>

<body>
	<?php require('../sidemenu.php'); ?>
	<div id="right-panel" class="right-panel">
		<?php require('../header.php'); ?>
		<div class="content">
			<div class="animated fadeIn">
				<div style="background-color:white;margin-bottom:10px;">
					<strong style="color:blue">
						<center>REPAIR LIST</center>
					</strong>
				</div>
				<button class="button button--moema button--text-thick button--text-upper button--size-s"
					style="padding:1.5px;" onclick="after_repair()">
					<i class="fa fa-exchange">Create Repair</i>
				</button>
				<button class="button button--moema button--text-thick button--text-upper button--size-s"
					style="padding:1.5px;" onclick="printtab()"><i class="fa fa-print">Print</i>
				</button>
				<table id="example" class="table table-striped table-bordered">
					<thead>
						<tr>
							<th>S.No</th>
							<th>Asset Name</th>
							<th>Location</th>
							<th>Priority</th>
							<th>Vendor Name</th>
							<th>Sendon Date</th>
							<th>Expect Return Date</th>
							<th>Remarks</th>
							<th>Status</th>
							<th>Action</th>
							<th>Process</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$n = 1;
						$repair_query = mysqli_query($con, "SELECT rm.*, vm.vendor_name FROM repair_master rm LEFT JOIN vendor_master vm ON rm.vendor_name = vm.id");

						while ($repair_select = mysqli_fetch_array($repair_query)) {
							$asset_id = $repair_select['asset_id'];
							$asset_result = mysqli_query($con, "SELECT * FROM asset_master WHERE id = '$asset_id'");
							$asset_det = mysqli_fetch_array($asset_result);
							?>
							<tr>
								<td><?php echo $n++; ?></td>
								<td><?php echo $asset_det['description']; ?></td>
								<td>
									<?php
									$location_id = $asset_det['location'];
									$location_query = "SELECT location FROM location_master WHERE id=$location_id";
									$asset_location = mysqli_fetch_array(mysqli_query($con, $location_query));
									echo $asset_location['location'];
									?>
								</td>
								<td><?php echo $repair_select['priority']; ?></td>
								<td><?php echo $repair_select['vendor_name']; ?></td>
								<td><?php echo date('d-m-Y', strtotime($repair_select['sendon'])); ?></td>
								<td><?php echo date('d-m-Y', strtotime($repair_select['expect_return_date'])); ?></td>
								<td><?php echo $repair_select['remarks']; ?></td>
								<td>
									<?php
									$status_id = $asset_det['status'];
									$status_query = "SELECT name FROM status_master WHERE status_no=$status_id";
									$asset_status = mysqli_fetch_array(mysqli_query($con, $status_query));
									echo $asset_status['name'];
									?>
								</td>
								<td class="text-left">
                                    <button type="button" class="btn btn-link btn-round" id="<?php echo $repair_select['id']; ?>" title="Edit Repair" onclick="editrepair(this.id)">
                                        <i class="fa fa-edit"></i>
                                    </button>
                                    <button type="button" onclick="deleterepair(this.id)" id="<?php echo $repair_select['id']; ?>" class="btn btn-link btn-round" title="Delete">
                                        <i class="fa fa-trash"></i>
                                    </button>
                                </td>
								<td>
									<abbr title="Return to stock">
										<button onclick="return_repair(this.value)" name="a_repair"
											value="<?php echo $asset_id; ?>"
											id="<?php echo $asset_id; ?>" class="btn btn-info">
											<i class="fa fa-circle-o-notch"></i>
										</button>
									</abbr>
								</td>
							</tr>
						<?php } ?>
					</tbody>
				</table>
			</div>
		</div>
		<div class="clearfix"></div>
	</div>
</body>

</html>
<?php require("../mainjavascript.js"); ?>