<!DOCTYPE html>
<html lang="en">
<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Chandrani Pearls Gold Billing</title>
  <link rel="icon" type="image/jpg" href="dist/img/favicon.png?v=2">
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">

  

  
 
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
	<link rel="stylesheet" href="dist/css/custom.css?v=2">
	
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.css">
	
	
	
	<style>
	
	.bg-light{
	   background-color:#f2f2f2 !important;
	   padding:10px;
	   margin-bottom:10px;
	}
	
	.bg1{
	    float:left;
	    height:50px;
	    width:100%;
	 background-color:#e6f2ff;
	 padding:5px 10px;
	}
	
	.bg2{
	    float:left;
	    width:100%;
	    height:50px;
	 background-color:#cce6ff; 
	  padding:5px 10px;
	}
	
	
	
	    label {
    display: inline-block;
    margin-bottom: 0rem;
}

.text-primary{
    color:#0a6abb !important;
}

button:focus{

outline: none;

}

	</style>

</head>
	


<body class="hold-transition sidebar-mini">
	
<div class="wrapper">




  <!-- Navbar -->
    <?php include ("topheader.php"); ?>
  <!-- Main Sidebar Container -->
    <?php include ("sidemenu.php"); ?>

<?php
	
	$Dealer_Sql=$Mainclass->dbh->prepare("SELECT Dealer_Name,Order_Code FROM dealer_master WHERE Active='Yes' ORDER BY Dealer_Name");
	$Dealer_Sql->execute();
	$Dealer_Res=$Dealer_Sql->get_result();
	
	$Dealer_Arr=[];
	while($Ft_Dealer=$Dealer_Res->fetch_assoc())
	{
		$Dealer_Arr[]=[
			"Dealer_Code"=>$Ft_Dealer['Order_Code'],
			"Dealer_Name"=>$Ft_Dealer['Dealer_Name'],
		];
	}
	$Dealer_Sql->close();
	
	$Collection_Sql=$Mainclass->dbh->prepare("SELECT SLN,collection_name FROM gold_collection_master WHERE active='Yes' ORDER BY collection_name");
	$Collection_Sql->execute();
	$Collection_Res=$Collection_Sql->get_result();
	
	$Collection_Arr=[];
	while($Ft_Collection=$Collection_Res->fetch_assoc())
	{
		$Collection_Arr[]=[
			"SLN"=>$Ft_Collection['SLN'],
			"Collection_Name"=>$Ft_Collection['collection_name'],
		 ];
	}
	$Collection_Sql->close();
	
	
	$Category_Sql=$Mainclass->dbh->prepare("SELECT SLN,Category FROM gold_product_category_master WHERE SLN>0");
	$Category_Sql->execute();
	$Category_Res=$Category_Sql->get_result();
	
	$Category_Arr=[];
	while($FT_Cat=$Category_Res->fetch_assoc())
	{
		$Category_Arr[]=[
			"SLN"=>$FT_Cat['SLN'],
			"Category"=>$FT_Cat['Category'],
		];
	}
	$Category_Sql->close();
	
	
	
	?>






  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
 
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h3>Create Discount</h3>
                </div>
                <div class="col-sm-6">
                    
                </div>
            </div>
        </div>
    </section>
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            
            <!-- /.card -->
            <div class="card">
            
              
              <!-- /.card-header -->
			  
	
			  
              <div class="card-body">


<div class="row">     
<div class="col-3" id="form_select">
<div class="form-group">
<label>Select Dealers <span style="color:crimson;font-weight:bold;">*</span></label>
<select id="dealer" name="dealer[]" data-placeholder="Select Dealers" class="chosen-select form-control " multiple onChange="removeerror()" >
                    	
                    <option value="" ></option>
	<?php
	foreach($Dealer_Arr as $dealers)
	{
		?>
	<option value="<?php echo $dealers['Dealer_Code'];?>"><?php echo $dealers['Dealer_Name'];?></option>
	<?php
	}
	?>                                  

                                      
                  </select>
                  
       <span id="dealer_err" class="text-danger"></span>          
                  <button type="button" class="chosen-toggle select button2" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Select all </button>
  <button type="button" class="chosen-toggle deselect button2" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Deselect all </button>
</div>
	
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>Select Offer On <span style="color:crimson;font-weight:bold;">*</span></label>
<select class="form-control" style="height:30px; line-height:30px; padding-top:3px;" id="offer_on" onChange="discount_on(),removeerror()">
<option value="" selected="">Select Offer On</option>
<option value="Collection">Collection</option>
<option value="Category">Category</option>
</select></div>
	<span id="offer_on_err" class="text-danger"></span>
</div>


<div class="col-3" id="form_select">
<div class="form-group">
<label>Select Collection <span style="color:crimson;font-weight:bold;">*</span></label>
<select id="collection" name="collection[]" data-placeholder="Select Collection" class="chosen-select form-control collectclass" multiple onChange="removeerror()">
                    	
                    <option value="" ></option>
	<?php
	foreach($Collection_Arr as $collections)
	{
		?>
	<option value="<?php echo $collections['SLN'];?>"><?php echo $collections['Collection_Name'];?></option>
	<?php
	}
	?>
                                      
                                      
                  </select>
                  
   <span id="collection_err" class="text-danger"></span>              
                  <button type="button" class="chosen-toggle select button2 collect-btn" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Select all </button>
  <button type="button" class="chosen-toggle deselect button2 collect-btn" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Deselect all </button>
</div>
</div>


<div class="col-3" id="form_select">
<div class="form-group">
<label>Select Category <span style="color:crimson;font-weight:bold;">*</span></label>
<select id="category" name="category[]" data-placeholder="Select Category" class="chosen-select form-control catselect" multiple onChange="removeerror()">
                    	
                    <option value="" ></option>
	<?php
	foreach($Category_Arr as $categories)
	{
		?>
	<option value="<?php echo $categories['SLN'];?>"><?php echo $categories['Category'];?></option>
	<?php
	}
	?>                                      
                                      
                  </select>
   <span id="category_err" class="text-danger"></span>               
                 
                  <button type="button" class="chosen-toggle select button2 catselect-btn" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Select all </button>
  <button type="button" class="chosen-toggle deselect button2 catselect-btn" style="margin-top:15px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;">Deselect all </button>
</div>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>Offer Name <span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="offer_name" id="offer_name" placeholder="Offer Name" class="form-control err"  autocomplete="off"  value="" onKeyDown="removeerror()">
</div>
	<span id="offer_name_err" class="text-danger"></span>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>From Date <span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="from_date" id="from_date" placeholder="From Date" class="form-control err"  autocomplete="off"  value="" onKeyDown="return false;" onChange="removeerror()" >
</div>
	<span id="from_date_err" class="text-danger"></span>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>To Date <span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="to_date" id="to_date" placeholder="To Date" class="form-control err"  autocomplete="off"  value="" onKeyDown="return false;" onChange="removeerror()">
</div>
	<span id="to_date_err" class="text-danger"></span>
</div>




<div class="col-3" id="form_select">
<div class="form-group">
<label>Making Charge Discount (in %)<span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="mc_disc" id="mc_disc" placeholder="Making Charge Discount In Percent" class="form-control err"  autocomplete="off"  value="" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onKeypress="removeerror()">
</div>
	<span id="mc_disc_err" class="text-danger"></span>
</div>


<div class="col-3" id="form_select">
<div class="form-group">
<label>Diamond Discount (in %)<span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="diamond_disc" id="diamond_disc" placeholder="Diamond Discount In Percent" class="form-control err"  autocomplete="off"  value="" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onKeypress="removeerror()">
</div>
	<span id="diamond_disc_err" class="text-danger"></span>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>Solitaire Discount (in %)<span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="solitaire_disc" id="solitaire_disc" placeholder="Solitaire Discount In Percent" class="form-control err"  autocomplete="off"  value="" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onKeypress="removeerror()">
</div>
	<span id="solitaire_disc_err" class="text-danger"></span>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<label>Stone Discount (in %)<span style="color:crimson;font-weight:bold;">*</span></label>
<input type="text" name="stone_disc" id="stone_disc" placeholder="Stone Discount In Percent" class="form-control err"  autocomplete="off"  value="" oninput="this.value = this.value.replace(/[^0-9.]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" onKeypress="removeerror()">
</div>
	<span id="stone_disc_err" class="text-danger"></span>
</div>

<div class="col-3" id="form_select">
<div class="form-group">
<input type="button" id="category_btn" name="category_btn" style="margin-top:25px; padding:4px 8px; border:0px; background-color:#062e50; color:#fff;" value="CREATE" onClick="create_category()">
</div>
</div>
</div>


</div>




              <!-- /.card-body -->

            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->


    <?php include ("footer.php"); ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->


  </aside>
  <!-- /.control-sidebar -->
</div>




<!-- ./wrapper -->
<!-- jQuery -->

<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->

<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->


<script src="chosen.jquery1.js"></script>

 <script type="text/javascript">
   $('select.chosen-select').chosen({width: "100%"});

$('.chosen-toggle').each(function(index) {
console.log(index);
    $(this).on('click', function(){
    console.log($(this).parent().find('option').text());
         $(this).parent().find('option').prop('selected', $(this).hasClass('select')).parent().trigger('chosen:updated');
		removeerror();
    });
});
  </script>
  
  



<script src="//cdn.jsdelivr.net/npm/sweetalert2@11"></script>
  



<!-- -=---- searchable dropdown link script ------ -->



        <link rel="stylesheet" href="https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
 <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>


<script>
$(function() {
$( "#from_date" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd-M-yy', 
minDate: 0, 
});
});


</script>

<script>
$(function() {
$( "#to_date" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd-M-yy', 
minDate: 0, 
});
});


</script>
<script>
	function discount_on()
	{
		var Offer_On=$("#offer_on").val();		
		if(Offer_On!='')
		   {
		   		if(Offer_On=="Collection")
				   {
				   		$(".collectclass").prop("disabled", false).trigger("chosen:updated");
					   const buttons = document.querySelectorAll('.collect-btn');
        buttons.forEach(button => {
            button.removeAttribute('disabled');
        });
					   
					   
		$(".catselect").val([]).prop("disabled", true).trigger("chosen:updated");			
			
			const buttons1 = document.querySelectorAll('.catselect-btn');
  buttons1.forEach(button => {
    button.setAttribute('disabled','true');
  });				   
					   
					   
					   
					   
				   }
			   if(Offer_On=="Category")
				  {
				  	$(".catselect").prop("disabled", false).trigger("chosen:updated");
					   const buttons1 = document.querySelectorAll('.catselect-btn');
        buttons1.forEach(button => {
            button.removeAttribute('disabled');
        });
					  
					  
			$(".collectclass").val([]).prop("disabled", true).trigger("chosen:updated");			
			
			const buttons = document.querySelectorAll('.collect-btn');
  buttons.forEach(button => {
    button.setAttribute('disabled','true');
  });		  
					  
					  
					  
				  }
		   }
		else{			
			$(".collectclass").val([]).prop("disabled", true).trigger("chosen:updated");			
			
			const buttons = document.querySelectorAll('.collect-btn');
  buttons.forEach(button => {
    button.setAttribute('disabled','true');
  });
			
			
		$(".catselect").val([]).prop("disabled", true).trigger("chosen:updated");			
			
			const buttons1 = document.querySelectorAll('.catselect-btn');
  buttons1.forEach(button => {
    button.setAttribute('disabled','true');
  });	
			
			
			
			
		}
	}
	
	discount_on();
	
	
function create_category()
	{
		var dealers=$("#dealer").val();
		var Offer_On=$("#offer_on").val();
		var Collection=$("#collection").val();
		var Category=$("#category").val();
		var Offer_Name=$("#offer_name").val();
		var From=$("#from_date").val();
		var To=$("#to_date").val();		
		var MC_Disc=$("#mc_disc").val();
		var Dia_Disc=$("#diamond_disc").val();
		var Soli_Disc=$("#solitaire_disc").val();
		var Stn_Disc=$("#stone_disc").val();
		var flag=0;
		
		if(dealers=='')
		   {
		   flag++;
			   $("#dealer_err").text("* Please Select Dealers.");
		   }
		if(Offer_On=='')
		   {
		   flag++;
			   $("#offer_on_err").text("* Please Select Offer On.");
		   }
		if(Offer_On=='Collection' && Collection=='')
		   {
		   flag++;
			   $("#collection_err").text("* Please Select Collections.");
		   }
		if(Offer_On=='Category' && Category=='')
		   {
		   flag++;
			   $("#category_err").text("* Please Select Categories.");
		   }
		if(Offer_Name=='')
		   {
		   flag++;
			   $("#offer_name_err").text("* Please Enter Offer Name.");
		   }
		if(From=='')
		   {
		   flag++;
			   $("#from_date_err").text("* Please Select Offer Start Date.");
		   }
		if(To=='')
		   {
		   flag++;
			   $("#to_date_err").text("* Please Select Offer End Date.");
		   }
		if(MC_Disc=='' && Dia_Disc=='' && Soli_Disc=='' && Stn_Disc=='')
		   {
		   flag++;
			   $("#mc_disc_err").text("* Please Enter Discount On Atleast One Parameter.");
		   }
		if(MC_Disc=='0')
		   {
		   flag++;
			   $("#mc_disc_err").text("* Making Charge Discount Cannot Be 0.");
		   }
		if(Dia_Disc=='0')
		   {
		   flag++;
			   $("#diamond_disc_err").text("* Diamond Discount Cannot Be 0.");
		   }
		if(Soli_Disc=='0')
		   {
		   flag++;
			   $("#solitaire_disc_err").text("* Solitaire Discount Cannot Be 0.");
		   }
		if(Stn_Disc=='0')
		   {
		   flag++;
			   $("#stone_disc_err").text("* Stone Discount Cannot Be 0.");
		   }
		if(flag>0)
		   {
		   	return false;
		   }
		else{
			$.ajax({
				url:'ajax_gold_category_discount.php',
				type:'POST',
				data:{dealers:dealers,Offer_On:Offer_On,Collection:Collection,Category:Category,Offer_Name:Offer_Name,From:From,To:To,MC_Disc:MC_Disc,Dia_Disc:Dia_Disc,Soli_Disc:Soli_Disc,Stn_Disc:Stn_Disc},
				success:function(res)
				{
					//console.log(res);
					Swal.fire({
              icon: 'success',
              title: '',
              text: 'Category Discount Created Successfully.',  
               showConfirmButton:false,
               timer:2000,
               toast:true,
               animation:true,
               position:'top-center',
        }).then(function() {  
						window.location.href="view-gold-category-discount.php";
						});
				}
			});
		}
	}
	
	function removeerror()
	{
		var dealers=$("#dealer").val();
		var Offer_On=$("#offer_on").val();
		var Collection=encodeURIComponent($("#collection").val());
		var Category=encodeURIComponent($("#category").val());
		var Offer_Name=$("#offer_name").val();
		var From=$("#from_date").val();
		var To=$("#to_date").val();		
		var MC_Disc=$("#mc_disc").val();
		var Dia_Disc=$("#diamond_disc").val();
		var Soli_Disc=$("#solitaire_disc").val();
		var Stn_Disc=$("#stone_disc").val();	
		
		if(dealers!='')
		   {		   
			   $("#dealer_err").text("");
		   }
		if(Offer_On!='')
		   {		   
			   $("#offer_on_err").text("");
		   }
		if(Offer_On!='')
		   {		   
			   $("#collection_err").text("");
		   }
		if(Offer_On!='')
		   {		   
			   $("#category_err").text("");
		   }
		if(Offer_Name!='')
		   {		   
			   $("#offer_name_err").text("");
		   }
		if(From!='')
		   {		   
			   $("#from_date_err").text("");
		   }
		if(To!='')
		   {		   
			   $("#to_date_err").text("");
		   }
		if(MC_Disc!='' || Dia_Disc!='' || Soli_Disc!='' || Stn_Disc!='')
		   {		   
			   $("#mc_disc_err").text("");
			   $("#diamond_disc_err").text("");
			   $("#solitaire_disc_err").text("");
			   $("#stone_disc_err").text("");
		   }
		if(MC_Disc>'0' || Dia_Disc>'0' || Soli_Disc>'0' || Stn_Disc>'0')
		   {		   
			   $("#mc_disc_err").text("");
			   $("#diamond_disc_err").text("");
			   $("#solitaire_disc_err").text("");
			   $("#stone_disc_err").text("");
		   }
	}
	
	
	</script>
</body>
</html>