<?php
	include'session.php';
	include'../connection.php';
	include'../functions.php';
	
	
?>
<html>
<head>
	<title>Add Seller</title>
	<!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
	<link rel="icon" href="images/logo.png" type="image/gif" sizes="16x16">
	
	<!-- Admin CSS File Link -->
	<link rel="stylesheet" href="css/style.css">
	
	<!-- User JAVA SCRIPT File Link -->
	<script type="text/javascript" src="js/script.js"></script>

	
	<!-- Font Awesome Icone -->
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	
	<style>
		.div1{
			background:#f7f7f7;
			width:50%;
			height:auto;
			float:left;
			text-align:center;
			padding:10px;
		}
		.div1 i{
			font-size:300px;
			color:#6b5127;
			margin:0 10px;
			
		}
		.div1 input, select{
			width:90%;
			height:45px;
			margin:10px;
			padding:5px 10px;
			border-radius:5px;
			border:1px solid #6b5127;
			font-size:15px;
		}
		input[type=submit]{
			background:#6b5127;
			color:white;
			font-size:30px;
			transition:1s;
		}
		input[type=submit]:hover{
			background:white;
			color:#6b5127;
			border:1px solid #6b5127;
			cursor:pointer;
			transition:1s;
		}
		
		@media(max-width:768px)
		{
			.div1{
				width:100%;
				height:auto;
			}
			.nav,.container{
				height:auto;
			}
		}
	</style>
	<link rel="stylesheet" href="css/mediaStyle.css">
</head>
<body>
	<!--Header Divison-->
	<?php
		require'header.php';
	?>
	
	<!--Container Division-->
	<div class="container">
		<?php
			include'menu.php';
			
	if(isset($_POST['submit']))
	{
		$SellerName  = $_POST['SellerName'];
		$SellerCity  = $_POST['SellerCity'];
		$Mobile      = $_POST['Mobile'];
		
		$FirmName    = $_POST['FirmName'];
		$FirmGst     = $_POST['FirmGst'];
		$FirmOwner   = $_POST['FirmOwner'];
		$FirmCircle  = $_POST['FirmCircle'];
		
		$quDupName="SELECT * FROM Seller WHERE Name='$sName' AND City='$SellerCity'";
		$reDupName=mysqli_query($con,$quDupName);
		$countDupName=mysqli_num_rows($reDupName);
		
		if($seller=="--Select Seller--")
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Select Seller Please !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($seller=="--Select City--")
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Select Seller City Please !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		elseif($countDupName>0)
		{
		    echo "<div class='msg-div'>
			        <form method='post'>
				        <h3>Seller Name Already Exists !</h3><br>
				        <i class='fa fa-ban' aria-hidden='true' id='NotokIcon'></i><br><br>
				        <button type='submit' class='btnPopup'>OK</button><br><br>
			        </form>
		        </div>";
		}
		else
		{
		    echo $quAddSeller="INSERT INTO Seller (Name,Mobile,City) VALUES ('$SellerName','$Mobile','$SellerCity')";
			if(mysqli_query($con,$quAddSeller))
			{
			    if(!empty($FirmName))
			    {
			        $sellerId = mysqli_insert_id($con);
			        echo $quAddFirm="INSERT INTO seller_firm (SellerId,FirmName,GstNo,OwnerName,Circle) 
			        VALUES ('$sellerId','$FirmName','$FirmGst','$FirmOwner','$FirmCircle')";
			        if(mysqli_query($con,$quAddFirm))
			        {
			            echo "<div class='msg-div'>
		    				<form method='post'>
			        			<h3>Seller & Firm Added Successfully !</h3><br>
					        	<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
						        <button type='submit' class='btnPopup'>OK</button><br><br>
						    </form>
					    </div>";
			        }
			    }
				echo "<div class='msg-div'>
						<form method='post'>
						<h3>Seller Added Successfully !</h3><br>
						<i class='fa fa-check-circle' aria-hidden='true' id='okIcon'></i><br><br>
						<button type='submit' class='btnPopup'>OK</button><br><br>
						</form>
					</div>";
			}
			
		}
	}
		?>
		<div class="content">
			<div class="head">
				<div class="title"><p>Add Seller :-</p></div>
				<div class="msg"><marquee><?php include'../msg.php'; ?></marquee></msg>
			</div><hr>
			<div class="data-content">
				<div class="div1">
				    <form method="post">
						<input type="text" name="SellerName" placeholder="Enter Seller's Name..." >
						<input type="text" name="SellerCity" placeholder="Enter Seller's City...." >
						<input type="text" name="Mobile" placeholder="Enter Seller's Mobile Number...." >
						<input type="text" name="FirmName" placeholder="Enter Firm Name...." >
						<input type="text" name="FirmGst" placeholder="Enter Firm Gst No...." >
						<input type="text" name="FirmOwner" placeholder="Enetr Firm Owner Name...." >
						<select name="FirmCircle">
						    <option>UP</option>
						    <option>XUP</option>
						</select>
						<input type="submit" name="submit" value="Submit"  onclick='showLoader()'>
				    </form>
				</div>
			</div>
		</div>
	</div>
	<?php
		require'footer.php';
	?>
</body>
</html>