<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$user_type = $_SESSION["user_type"];
$user_session = $_SESSION["user_session"];

$id1 = base64_decode($_GET['id']);
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>BTCOVER : Admin Dashboard</title>
    <!-- Custom CSS -->
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/jquery-minicolors/jquery.minicolors.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/quill/dist/quill.snow.css">
    <link href="dist/css/style.min.css" rel="stylesheet">
   <script>
	
		function myFunction() {
			var txt;
		
			var r = confirm("Are you sure to Cancel !");
			if (r == true) {
				window.location.href="commission-percentage.php";
			} 
		}
		</script>
		<script>
		function exist(str)
		{
			
			 document.getElementById('percentage').style.display="block";	
			 document.getElementById('percentage2').style.display="none";	
				document.getElementById('percentage11').value=0;
		}
		</script>
		<script>
		function exist2(str)
		{
		
			 document.getElementById('percentage2').style.display="block";	
			 document.getElementById('percentage').style.display="none";	
			document.getElementById('percentage22').value=0;
		}
		</script>
		<script>
		function exist3(str)
		{
		
			 document.getElementById('percentage').style.display="block";	
			 document.getElementById('percentage2').style.display="block";	
			document.getElementById('percentage11').value=0;
			document.getElementById('percentage22').value=0;
		}
		</script>
		<script>
		function validate(str)
		{
			
			var t=(str>=0 && str <= 100);
          
            if (!t ) {
                alert("Please enter correct percentage.");
				document.getElementById('percentage11').value="";
                document.form.discount.focus();
                return false;
            }
	
		}
	 </script>
	 <script>
		function check(str)
		{
			
			var t=(str>=0 && str <= 100);
          
            if (!t ) {
                alert("Please enter correct percentage.");
				document.getElementById('percentage22').value="";
                document.form.discount.focus();
                return false;
            }
	
		}
	 </script>
</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
  
	 <div id="main-wrapper">
   <?php include("header.php"); ?>
    
     <?php include("menu.php"); ?>
	
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Add Commission Percentage</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<?php if($id1!='') 
									{ ?>
                                    <li class="breadcrumb-item"><a href="commission-percentage.php">View Commission Percentage</a></li>
                                    <?php } ?>
									<li class="breadcrumb-item active" aria-current="page">Add Commission Percentage</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <form class="form-horizontal" method="post" name="form"  enctype="multipart/form-data">
                                <div class="card-body">
                                  
									
                                   <div class="form-group row">
                                   <div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label"><b>Vehicle Category</b></label>
										
                                       <?php 
									   
									   $selrenew3=mysqli_query($con,"select * from tbl_vehicle_master where vehicle_id='$id1'");
											
											$recset=mysqli_fetch_array($selrenew3);
									?>
                                            <input type="text" class="form-control" id="vehicle_type" name="vehicle_id" placeholder="Vehicle Category" value="<?php echo $recset['vehicle_type']; ?>" required>
											
											
                                    </div>
                                </div>
                                </div>
								
								 <div class="col-md-12">	
								
                                   <div class="form-group row">
                                    <div class="col-md-2" >
                                        <div class="custom-control custom-radio">
                                            <input type="radio" class="custom-control-input"  id="customControlValidation1" value="OD"  name="type"  onclick="exist(this.value);"  onclick="exist(this.value);"  >
                                            <label for="customControlValidation1" class="custom-control-label" for="customControlValidation1"><b>OD</b></label>
										</div>
										</div>
										 <div class="col-md-2" >
                                        <div class="custom-control custom-radio">
                                            <input type="radio" class="custom-control-input" value="TP" id="customControlValidation2" name="type"  onclick="exist2(this.value);"    onclick="exist2(this.value);" >
                                            <label for="customControlValidation2" class="custom-control-label" for="customControlValidation1"><b>TP</b></label>
										</div>
										</div>
										<div class="col-md-2">
										 <div class="custom-control custom-radio">
											<input type="radio" class="custom-control-input" id="customControlValidation3" name="type" value="Both"   checked onclick="exist3(this.value);" >
                                            <label for="customControlValidation3" class="custom-control-label" for="customControlValidation2"><b>Both</b></label>
											
                                        </div>
                                        
                                         
                                    </div>
                                </div>
                                </div>
								<div class="form-group row" >
								<div class="col-md-4" id="percentage">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label"><b>OD Percentage</b></label>
                                        
                                            <input type="text" class="form-control" id="percentage11" name="percentage" onkeypress="check(this.value)" onkeyup="validate(this.value)" placeholder="OD Percentage" >
                                        
                                    </div>
                                </div>
                             
								
								<div class="col-md-4" id="percentage2">	
									<div class="form-group ">
                                        <label for="fname" class="text-left control-label col-form-label"><b>TP Percentage</b></label>
                                        
                                            <input type="text" class="form-control" id="percentage22"  name="percentage2" placeholder="OD Percentage" onkeypress="check(this.value)" onkeyup="check(this.value)" >
                                        
                                    </div>
                                    </div>
									
								<div class="col-md-4">	
									<div class="form-group ">
                                        <label for="fname" class=" text-left control-label col-form-label"><b>Start Date</b></label>
                                        <div class="input-group">
                                    <input type="text" class="form-control" id="datepicker-autoclose" name="start_date" placeholder="mm/dd/yyyy">
                                    <div class="input-group-append">
                                        <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                                    </div>
                                </div>
                                     </div>
                                </div>
                                </div>
								<div class="form-group row">
                                 <div class="col-md-4">   
                                <div class="border-top">
                                    <div class="card-body">
                                       <div class="card-body">
                                    <button type="submit" name="sub" class="btn btn-success">Save</button>
                                    <button type="button" onclick="myFunction()" name="subcancel" class="btn btn-primary">Cancel</button>
                                    
                                </div>
                                    </div>
                                </div>
                                </div>
                                </div>
                            </form>
							
							<?php 
			
			if(isset($_POST['sub']))
				{
		//$vehicle_id=$_POST['vehicle_id'];
		$vehicle_id = base64_decode($_GET['id']);
	$start_date1=$_POST['start_date'];
	$start_date=date("Y-m-d", strtotime($start_date1) );
	$end_date=$_POST['end_date'];
	$type=$_POST['type'];
	$percentage2=$_POST['percentage2'];
	$percentage=$_POST['percentage'];
	$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$end_date=date('Y-m-d', strtotime($fdate .'+50 years'));
		date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:sa');
									
		$select_product = mysqli_query($con,"SELECT * FROM `tbl_commission_type` WHERE vehicle_id = '$vehicle_id' ORDER by commission_id desc limit 1");

	if(mysqli_num_rows($select_product)>0)
	{     $row = mysqli_fetch_assoc($select_product); 

		  $commission_id  = $row['commission_id'];
		  $end_dt = date('Y-m-d', strtotime('-1 day', strtotime($start_date)));
		$uq2=mysqli_query($con,"update tbl_commission_type set end_date='$end_dt' where commission_id='$commission_id'"); 
	}
	
		$query1 = mysqli_query($con,"INSERT INTO `tbl_commission_type`(`admin_id`,`vehicle_id`,`type`,`percentage`,`percentage2`,`start_date`,`end_date`,`insert_datetime`)VALUES('$ver','$vehicle_id','$type','$percentage','$percentage2','$start_date','$end_date','$cdate')");		
		if($query1)
			{
				
				header('location:commission-percentage.php');	
				
			}
			
	
				}	
				
							?>
							
							
                        </div>
                    
          

                    </div>
              
                </div>
                <!-- editor -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
             <footer class="footer text-center">
                  2019 &copy; All Rights Reserved by BTCOVER. Designed and Developed by <a href="http://www.belltechnology.in/">Bell Technology</a>.
            </footer>
          
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!-- This Page JS -->
    <script src="assets/libs/inputmask/dist/min/jquery.inputmask.bundle.min.js"></script>
    <script src="dist/js/pages/mask/mask.init.js"></script>
    <script src="assets/libs/select2/dist/js/select2.full.min.js"></script>
    <script src="assets/libs/select2/dist/js/select2.min.js"></script>
    <script src="assets/libs/jquery-asColor/dist/jquery-asColor.min.js"></script>
    <script src="assets/libs/jquery-asGradient/dist/jquery-asGradient.js"></script>
    <script src="assets/libs/jquery-asColorPicker/dist/jquery-asColorPicker.min.js"></script>
    <script src="assets/libs/jquery-minicolors/jquery.minicolors.min.js"></script>
    <script src="assets/libs/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <script src="assets/libs/quill/dist/quill.min.js"></script>
    <script>
        //***********************************//
        // For select 2
        //***********************************//
        $(".select2").select2();

        /*colorpicker*/
        $('.demo').each(function() {
        //
        // Dear reader, it's actually very easy to initialize MiniColors. For example:
        //
        //  $(selector).minicolors();
        //
        // The way I've done it below is just for the demo, so don't get confused
        // by it. Also, data- attributes aren't supported at this time...they're
        // only used for this demo.
        //
        $(this).minicolors({
                control: $(this).attr('data-control') || 'hue',
                position: $(this).attr('data-position') || 'bottom left',

                change: function(value, opacity) {
                    if (!value) return;
                    if (opacity) value += ', ' + opacity;
                    if (typeof console === 'object') {
                        console.log(value);
                    }
                },
                theme: 'bootstrap'
            });

        });
        /*datwpicker*/
        jQuery('.mydatepicker').datepicker();
        jQuery('#datepicker-autoclose').datepicker({
            autoclose: true,
            todayHighlight: true
        });
        var quill = new Quill('#editor', {
            theme: 'snow'
        });

    </script>
</body>

</html>