<?php
session_start();

if (isset($_SESSION['username']) == true) {
	include 'master.php';
	$username = $_SESSION['username'];
}else{
	header("location:login");
}
?>
		<!--page-wrapper-->
		<div class="page-wrapper">
			<!--page-content-wrapper-->
			<div class="page-content-wrapper">
				<div class="page-content">
					<!--breadcrumb-->
					<div class="page-breadcrumb d-none d-md-flex align-items-center mb-3">
						<div class="breadcrumb-title pr-3">New Tax Code</div>
						<div class="pl-3">
							<nav aria-label="breadcrumb">
								<ol class="breadcrumb mb-0 p-0">
									<li class="breadcrumb-item"><a href="javascript:;"><i class='bx bx-home-alt'></i></a>
									</li>
									<li class="breadcrumb-item active" aria-current="page">Layouts</li>
								</ol>
							</nav>
						</div>
						<div class="ml-auto">
							<div class="btn-group">
								<button type="button" class="btn btn-primary">Active</button>
							</div>
						</div>
					</div><br><br>
					<!--end breadcrumb-->
						<div class="row">
						<div class="col-12 col-lg-9 mx-auto">
							<div class="card radius-15">
								<div class="card-body">
									<form action="" method="post" enctype="multipart/form-data">
										<div class="form-group">
											<label>Added By</label>
											<input type="text" class="form-control border-left" name="username" disabled value="<?php echo $username;?>">
										</div>
										<div class="form-group">
											<span class="text-color-primary">Click on the add button to add new Tax Code</span>
										</div>
										<div class="form-group">
											<button type="submit" class="btn btn-primary px-4" name="add" onclick="return confirm('Are you sure you want to add Tax Code?')">Add</button>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
					<!--end row-->
				</div>
			</div>
			<!--end page-content-wrapper-->
		</div>
		<!--end page-wrapper-->
		<!--start overlay-->
		<div class="overlay toggle-btn-mobile"></div>
		<!--end overlay-->
		<!--Start Back To Top Button--> <a href="javaScript:;" class="back-to-top"><i class='bx bxs-up-arrow-alt'></i></a>
		<!--End Back To Top Button-->
<?php
include 'footer.php';

if (isset($_POST['add']) == true) {
	$added_by = $username;
	$date = date("h:i:a d F Y");

	$char = "1234567890ABCDEFGHIJKLMNOPQRSTUVWSYZ";
    $tax_code =  str_shuffle($char);
    $tax_code = substr("T-".$tax_code, 0, 12);

    if (isset($tax_code) == true) {
    	$insert = $conn->query("INSERT INTO tax_codes (added_by, tax_code, date_added) VALUES ('$added_by', '$tax_code', '$date') ");
    	echo "<script>swal({text:'Tax Code Added Successfully', icon:'success'})
    		.then(function(){
    			window.location = 'active-tax-codes'
    			})
    	</script>";
    }

}