<?php
include("../connection.php");
include("../user.php");
$cur_date = date('Y-m-d H:i:s');
$user = $_SESSION['user'];
$ho_access = $_SESSION['ha'];
$id = $_REQUEST['id'];
$editvendor = mysqli_fetch_array(mysqli_query($con, "select  * from vendor_master where id='$id'"));

?>
<!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;
		}
	</style>
	<script>
          function validateGST() {
            var gst = document.getElementById("gst_number").value;
            var gstPattern = /^[A-Z0-9]{15}$/; // Adjusted to 15 characters

            if (!gstPattern.test(gst)) {
                alert("Please enter a valid 15-character GST number.");
                return false;
            }
            return true;
        }
    </script>
</head>

<body>

	<div class="col-lg-8">
		<div class="card">
			<div class="card-header">
				<strong>Edit Vendor</strong>
				<a href="vendor_master.php"><button class="btn btn-primary" style="width:50px;margin-left:400px;" 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="vendor_update.php" onsubmit="return validateGST()"> -->
				<form method="post" enctype="multipart/form-data" class="form-horizontal" action="vendor_update.php">
					<?php
				    if ($ho_access == "yes") {
					?>
					<div class="row form-group">
							<div class="col col-md-3"><label for="text-input" class=" form-control-label">Department</label><span style="color:red;">*</span></div>
							<div class="col-12 col-md-9"><select id="department" name="department" placeholder="select Department" class="form-control  select-search" autocomplete="off" required>
									<option value="" selected disabled>Select Department</option>
									<?php
									$brn = mysqli_query($con, "SELECT * FROM type_master where  status='0' order by id asc");
									while ($brc = mysqli_fetch_array($brn)) {
										$selected = ($brc['type'] == $editvendor['department']) ? "selected" : "";
									?>
										<option value="<?php echo $brc['type']; ?>" <?php echo $selected; ?>><?php echo strtoupper($brc['type']); ?></option>
									<?php
									}
									?>
								</select></div>
						</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Code</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="vendor_code" name="vendor_code" value="<?php echo $editvendor['vendor_code']; ?>" placeholder="Enter Vendor Code" class="form-control" autocomplete="off" onchange="vendor_val(this.value)" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Name</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="vendor_name" name="vendor_name" value="<?php echo $editvendor['vendor_name']; ?>" placeholder="Enter Vendor Name" class="form-control" onchange="vendor_val(this.value)" autocomplete="off" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Address</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><textarea id="vendor_addr" name="vendor_addr" placeholder="Enter Vendor Address" class="form-control" autocomplete="off" required><?php echo $editvendor['vendor_address']; ?></textarea></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Phone</label></div>
						<div class="col-12 col-md-9"><input type="text" id="phone" name="phone" value="<?php echo $editvendor['phone']; ?>" placeholder="Enter Phone number" class="form-control" autocomplete="off"></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">E-Mail</label></div>
						<div class="col-12 col-md-9"><input type="email" id="email" name="email" value="<?php echo $editvendor['email']; ?>" placeholder="Enter E-mail Id" class="form-control" autocomplete="off" ></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Contact Person</label></div>
						<div class="col-12 col-md-9"><input type="text" id="contact" name="contact" value="<?php echo $editvendor['contact_person']; ?>" placeholder="Enter Contact person" class="form-control" autocomplete="off" ></div>
					</div>
					<div class="row form-group">
                        <div class="col col-md-3"><label for="gst_number" class="form-control-label">GST Number</label></div>
                        <div class="col-12 col-md-9"><input type="text" id="gst_number" name="gst_number" class="form-control" value="<?php echo $editvendor['gst_number']; ?>"></div>
                    </div>
					<input type="hidden" id="id" name="id" value="<?php echo $editvendor['id']; ?>">
					<?php
					} else {
					?>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Code</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="vendor_code" name="vendor_code" value="<?php echo $editvendor['vendor_code']; ?>" placeholder="Enter Vendor Code" class="form-control" autocomplete="off" onchange="vendor_val(this.value)" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Name</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="vendor_name" name="vendor_name" value="<?php echo $editvendor['vendor_name']; ?>" placeholder="Enter Vendor Name" class="form-control" onchange="vendor_val(this.value)" autocomplete="off" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Vendor Address</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><textarea id="vendor_addr" name="vendor_addr" placeholder="Enter Vendor Address" class="form-control" autocomplete="off" required><?php echo $editvendor['vendor_address']; ?></textarea></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Phone</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="phone" name="phone" value="<?php echo $editvendor['phone']; ?>" placeholder="Enter Phone number" class="form-control" autocomplete="off" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">E-Mail</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="email" id="email" name="email" value="<?php echo $editvendor['email']; ?>" placeholder="Enter E-mail Id" class="form-control" autocomplete="off" required></div>
					</div>
					<div class="row form-group">
						<div class="col col-md-3"><label for="text-input" class=" form-control-label">Contact Person</label><span style="color:red;">*</span></div>
						<div class="col-12 col-md-9"><input type="text" id="contact" name="contact" value="<?php echo $editvendor['contact_person']; ?>" placeholder="Enter Contact person" class="form-control" autocomplete="off" required></div>
					</div>
					<div class="row form-group">
                        <div class="col col-md-3"><label for="gst_number" class="form-control-label">GST Number</label></div>
                        <div class="col-12 col-md-9"><input type="text" id="gst_number" name="gst_number" class="form-control" value="<?php echo $editvendor['gst_number']; ?>"></div>
                    </div>
					<input type="hidden" id="id" name="id" value="<?php echo $editvendor['id']; ?>">
					<?php } ?>
					<div style="">
						<button type="submit" name="submit" class="btn btn-success"><i class="fa fa-dot-circle-o"></i>Update</button>

					</div>
				</form>
			</div>
		</div>
		<div class="clearfix"></div>

		<footer class="site-footer">

		</footer>

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

</html>