<?php
include("../connection.php");
include("../user.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
$cur_date = date('Y-m-d H:i:s');
$user = $_SESSION['user'];
$branch_id = $_SESSION['branch_id'];
$ho_access = $_SESSION['ha'];
$branch = $_SESSION['division_name'];
$location = $_SESSION['location'];

$editid = $_POST['editid'];
$scrab_query = mysqli_query($con, "SELECT * FROM scrab_master WHERE id=$editid");
$result = mysqli_fetch_array($scrab_query);
?>
<!doctype html>
<html class="no-js" lang="">

<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">
	<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/html5shiv/3.7.3/html5shiv.min.js"></script> -->

	<style>
		input {
			text-transform: uppercase;
		}

		textarea {
			text-transform: uppercase;
		}

		select {
			text-transform: uppercase;
		}
	</style>
</head>

<body>
	<div class="col-lg-8">
		<div class="card">
			<div class="card-header">
				<strong>Edit Scrap</strong>
				<a href="scrab.php"><button class="btn btn-primary" style="width:50px;float:right;" onclick=""><i
							class="fa fa-backward"></i></button></a>
			</div>
			<div class="card-body card-block">
				<form method="post" enctype="multipart/form-data" class="form-horizontal" action="scrap_update.php">
					<input type="hidden" name="edit_id" value="<?php echo $editid; ?>">
						<div class="row form-group" id="asset_set">
							<div class="col col-md-3"><label for="text-input" class=" form-control-label">Asset
									ID</label></div>
							<div class="col-12 col-md-9">
								<select id="asset_code" name="asset_code" onchange="asse_code(this.value)"
									class="form-control select-search" autocomplete="off" disabled>
									<option value="" selected disabled>Select Asset Code</option>
									<?php $asset_id = mysqli_query($con, "SELECT * FROM `asset_master`");
									while ($asset = mysqli_fetch_array($asset_id)) { ?>
										<option value="<?php echo $asset['id']; ?>" <?php if ($asset['id'] == $result['asset_id']) echo "selected"; ?>>
											<?php echo $asset['description']; ?>
										</option>
									<?php } ?>
								</select>
							</div>
						</div>
						
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input"
								class=" form-control-label">Priority</label></div>
						<div class="col-12 col-md-9">
							<select name="priority" class="form-control">
                                <option value="">SELECT PRIORITY</option>
                                <option value="High" <?php if ($result['priority'] == "High") echo "selected"; ?>>High</option>
                                <option value="Medium" <?php if ($result['priority'] == "Medium") echo "selected"; ?>>Medium</option>
                                <option value="Low" <?php if ($result['priority'] == "Low") echo "selected"; ?>>Low</option>
                            </select>
						</div>
					</div>
					
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class="form-control-label">Cost</label></div>
						<div class="col-12 col-md-9">
							<input type="number" class="form-control" name="cost" id="cost" value="<?php echo $result['cost']; ?>"
								placeholder="Please Enter Cost">
						</div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Scrap
								Remarks</label></div>
						<div class="col-12 col-md-9">
							<textarea name="remarks" placeholder="Scrap Remarks" class="form-control"><?php echo $result['remarks']; ?></textarea>
						</div>
					</div>

					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Scrab Request By
								Department Manager</label></div>
						<div class="col-12 col-md-9"><input type="text" id="material_request_by"
								name="material_request_by" class="form-control" autocomplete="off" value="<?php echo $result['scrab_requested_by']; ?>"
								placeholder="Enter material_requester Name"></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Approved By
								Sr.Facility Manager</label></div>
						<div class="col-12 col-md-9"><input type="text" id="Approved_By_Shift_Engineer"
								name="Approved_By_Shift_Engineer" class="form-control" autocomplete="off" value="<?php echo $result['scrab_approved_by']; ?>"
								placeholder="Enter Shift Engineer Name"></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Store
								Incharge</label></div>
						<div class="col-12 col-md-9"><input type="text" id="store_incharge" name="store_incharge" value="<?php echo $result['store_incharge']; ?>"
								class="form-control" autocomplete="off" placeholder="Enter Store Incharge">
						</div>
					</div>


					<div>
						<button type="submit" name="submit" class="btn btn-success"><i class="fa fa-inbox"></i>
							Submit</button>
					</div>
				</form>
			</div>
		</div>
		<div class="clearfix"></div>

		<footer class="site-footer">

		</footer>
	</div>
</body>

</html>
<script>
	// Initialize Select2
	$(document).ready(function () {
		$('.select-search').select2({
			placeholder: "-- SELECT --",  // Optional placeholder text
			allowClear: true                // Optional: allows clearing the selection
		});
	});
</script>
