<?php $this->include('rs/utils.php')?>
<?= $this->extend('rs/template-admin'); ?>
<?= $this->section('content'); 

?>
  
<link rel="stylesheet" href="intlTelInput/css/intlTelInput.css">
	<style>
		.categ{border:1px solid #CCC;border-radius:5px;display:block;padding:10px 20px;margin:10px}
		form{width:100%}
		.form-control{max-width:350px!important}
	</style>
	<script type="text/javascript">
	
	document.getElementById("company").classList.add("active");
	document.getElementById("company_bar").classList.add("active");
	
	</script>
	<div class="card shadow">
		<a href="#collapsePrimary" class="d-block card-header py-3" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="collapseReception">
			<h6 class="m-0 font-weight-bold text-primary">Company info</h6>
		</a>
		<div class="collapse show" id="collapsePrimary">
			<div class="card-body">
				
				 <form class="" id="frmdata" action="" method="post" >
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Company name</label>
						<input  type="text" class="form-control" name="company_name" id="companyname" value="<?=$company['company_name'] ?>">
					   </div>
					 </div>
					 
					  <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">VAT number</label>
						<input  type="text" class="form-control" name="vat_code" id="vatnumber" value="<?=$company['vat_code'] ?>">
					   </div>
					 </div>
					 
					  
					 
					 <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Address 1</label>
						<input type="text" class="form-control" name="address1" id="address1" value="<?=$company['address1'] ?>">
					   </div>
					 </div>
					 
					 
					 <div class="col-12 col-sm-12">
					   <div class="form-group">
						<label for="realname">Address 2</label>
						<input type="text" class="form-control" name="address2" id="address2" value="<?=$company['address2']?>">
					   </div>
					 </div>
					 
					 
					 <div class="col-12 col-sm-6">
						 <div class="form-group">
						   <label for="phone">Phone number </label>
						   <div class="input-group">
								<input type="tel"  class="form-control" name="phone" id="phone" value="<?=$company['phone'] ?>"  required>										
							</div>
					   </div>	
					 </div>
					 
					 <div class="col-12">
					   <div class="form-group">
						<label for="email">Company email address</label>
						<input type="text" class="form-control"  name="email" value="<?=$company['email'] ?>">
					   </div>
					 </div>
					 
					 <div class="col-12">
					   <div class="form-group">
						<label for="website">Company website</label>
						<input type="text" class="form-control"  name="website" value="<?=$company['website'] ?>">
					   </div>
					 </div>
					
				 <br><br>
					<hr>				 
				 <div><b>Sale comissions public</b></div>
				  <hr>
					<div class="col-12 font-weight-bold mb-1 form-check-inline">
						
						<div class="form-check">
						  <input class="form-check-input" type="radio" name="coms" id="coms1" value="1" <?=($company['commission_type']==1?'checked' :'')?>>
						  <label class="form-check-label" for="coms1">
							Fixed ammount
						  </label>
						</div>
						<div class="form-check">
						  <input class="form-check-input" type="radio" name="coms" id="coms2" value="2" <?=($company['commission_type']==2?'checked' :'')?>>
						  <label class="form-check-label" for="coms2">
							Percent %
						  </label>
						</div>
						<div class="form-check">
						  <input class="form-check-input" type="radio" name="coms" id="coms0" value="0" <?=($company['commission_type']==0?'checked' :'')?>>
						  <label class="form-check-label" for="coms0">
							No comission
						  </label>
						</div>
					</div>
				   <br><br>
				   
				   <div class="col-12 cmsAbs">
					   <div class="form-group">
							<label for="commission_abs">Fixed ammount BGN</label>
							<input type="text" class="form-control"  name="commission_abs" id="commission_abs" value="<?= set_value('commission_abs', $company['commission_abs']) ?>" required>
					  </div> 
					  </div>

					<div class="col-12 cmsPerc">
					   <div class="form-group">
							<label for="commission_percent">Percent</label>
							<input type="text" class="form-control"   name="commission_percent" id="commission_percent" value="<?= set_value('commission_percent', round(100*$company['commission_percent'],2)) ?>" required>
						</div>
					 </div>	  
					 
					 <div class="col-12 cmsPerc">
					   <div class="form-group">
							<label for="commission_min">But no less than BGN</label>
							<input type="text" class="form-control"  name="commission_min" id="commission_min" value="<?= set_value('commission_min', $company['commission_min']) ?>" required>
					   </div>
					 </div>	
					 
					 
					  <br><br>
					<hr>				 
				 <div><b>Sale comissions dealers</b></div>
				  <hr>
					<div class="col-12 font-weight-bold mb-1 form-check-inline">
						
						<div class="form-check">
						  <input class="form-check-input2" type="radio" name="comsd" id="comsd1" value="1" <?=($company['commission_type_deal']==1?'checked' :'')?>>
						  <label class="form-check-label" for="comsd1">
							Fixed ammount
						  </label>
						</div>
						<div class="form-check">
						  <input class="form-check-input2" type="radio" name="comsd" id="comsd2" value="2" <?=($company['commission_type_deal']==2?'checked' :'')?>>
						  <label class="form-check-label" for="comsd2">
							Percent %
						  </label>
						</div>
						<div class="form-check">
						  <input class="form-check-input2" type="radio" name="comsd" id="comsd0" value="0" <?=($company['commission_type_deal']==0?'checked' :'')?>>
						  <label class="form-check-label" for="comsd0">
							No comission
						  </label>
						</div>
					</div>
				   <br><br>
				   
				   <div class="col-12 cmsAbsd">
					   <div class="form-group">
							<label for="commission_abs">Fixed ammount BGN</label>
							<input type="text" class="form-control"  name="commission_abs_deal" id="commission_abs_deal" value="<?= set_value('commission_abs_deal', $company['commission_abs_deal']) ?>" required>
					  </div> 
					  </div>

					<div class="col-12 cmsPercd">
					   <div class="form-group">
							<label for="commission_percent">Percent</label>
							<input type="text" class="form-control"   name="commission_percent_deal" id="commission_percent_deal" value="<?= set_value('commission_percent_deal', round(100*$company['commission_percent_deal'],2)) ?>" required>
						</div>
					 </div>	  
					 
					 <div class="col-12 cmsPercd">
					   <div class="form-group">
							<label for="commission_min">But no less than BGN</label>
							<input type="text" class="form-control"  name="commission_min_deal" id="commission_min_deal" value="<?= set_value('commission_min_deal', $company['commission_min_deal']) ?>" required>
					   </div>
					 </div>	
						
					   <?php if (isset($validation)): ?>
						 <div class="col-12">
						   <div class="alert alert-danger" role="alert">
							 <?= $validation->listErrors() ?>
						   </div>
						 </div>
					   <?php endif; ?>
					   
					   
					   
					   <div class="row">
							<div class="col-12 col-sm-4">
							<button type="button" onclick="doSubmit()" class="btn btn-primary">Update</button>
							</div>
						</div>
				</form>
			</div>	   
		</div>
		<hr>
	</div>
			
<script src="/intlTelInput/js/intlTelInput.js"></script>
<script>

  var input = document.querySelector("#phone");
 
 $(document).ready(function() {
		if($("#coms0").prop('checked'))
		{
			showCms(0);
		}
		if($("#coms1").prop('checked'))
		{
			showCms(1);
		}
		if($("#coms2").prop('checked'))
		{
			showCms(2);
		}
		
		if($("#comsd0").prop('checked'))
		{
			showCmsd(0);
		}
		if($("#comsd1").prop('checked'))
		{
			showCmsd(1);
		}
		if($("#comsd2").prop('checked'))
		{
			showCmsd(2);
		}
		
	 })

 
 
  var i=window.intlTelInput(input, {
    utilsScript:"/intlTelInput/js/utils.js"
  });
  
  function doSubmit(){
	  phoneInput=$("#phone");
	  phoneInput.val(i.getNumber());
	  document.getElementById('frmdata').submit();
	 
	}
  
   
  function generatePassword() { 
        const passwordLength = 18
        const useSymbols = true
        const useNumbers = true
        const useLowerCase = true
        const useUpperCase = true
        
        let charset = ''; 
        let newPassword = ''; 
  
        if (useSymbols) charset += "!@#$%^&*()"; 
        if (useNumbers) charset += "0123456789"; 
        if (useLowerCase) charset += "abcdefghijklmnopqrstuvwxyz"; 
        if (useUpperCase) charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
  
        for (let i = 0; i < passwordLength; i++) { 
            newPassword += charset.charAt( 
                Math.floor(Math.random() * charset.length)); 
        } 
  
        password = newPassword;
		
		$('#password').val(password)
		$('#password').prop('type', 'text');
		//alert(password);
    } 
	
	
	$( ".form-check-input").on( "change", function() {
	  var val=$(this).val();
	  showCms(val);
	 	  
	});
	
	
	$( ".form-check-input2" ).on( "change", function() {
	  var val=$(this).val();
	 	  showCmsd(val);
	  
	});
	
	function showCms(val)
	{
	  if(val=='0')
	  { 
		$(".cmsAbs").hide();
		$(".cmsPerc").hide();
		//$("#commission_abs").val(0);
		//$("#commission_percent").val(0);
		//$("#commission_min").val(0);
	  }
	  
	  if(val=='1')
	  {
		$(".cmsAbs").show();
		$(".cmsPerc").hide();
		//$("#commission_percent").val(0);
		//$("#commission_min").val(0);
	  }
	  
	  if(val=='2')
	  {
		$(".cmsAbs").hide();
		$(".cmsPerc").show();
		//$("#commission_abs").val(0);
	  }
	  
	
	}
	
	
	function showCmsd(val)
	{
	  if(val=='0')
	  { 
		$(".cmsAbsd").hide();
		$(".cmsPercd").hide();
		//$("#commission_abs").val(0);
		//$("#commission_percent").val(0);
		//$("#commission_min").val(0);
	  }
	  
	  if(val=='1')
	  {
		$(".cmsAbsd").show();
		$(".cmsPercd").hide();
		//$("#commission_percent").val(0);
		//$("#commission_min").val(0);
	  }
	  
	  if(val=='2')
	  {
		$(".cmsAbsd").hide();
		$(".cmsPercd").show();
		//$("#commission_abs").val(0);
	  }
	  
	
	}
	
  
</script>
			
		
<?= $this->endsection(); ?>