<?php 

require_once("config/configDB.php"); 
require "userPermission.php";

$sql_InvoiceQuery   = mysqli_query($conn,"SELECT count(*) as code FROM supplier_master");
$rowInvoiceCount    = mysqli_fetch_array($sql_InvoiceQuery,MYSQLI_ASSOC);
$code_count      = $rowInvoiceCount['code']+1;

$createdby      = $_SESSION['username'];
    $userID         = $_SESSION['user_id'];
	
	//echo $createdby;
	//echo $userID;

?>

<!DOCTYPE html>
<html>
<head>
    
    <?php 
      require 'meta.php'; 
      require 'header.php'; 
    ?>

</head>
<body>
    <?php require 'menu.php' ?>
<div class="container-fluid">
<h2 class="text-center">Supplier Master Details</h2><br>
    <form class="form-horizontal" action="supplierMasterInsert.php" method="post" id="customerMasterForm" onSubmit="return checkForm(this);">
      
	  <input type="hidden" value="<?php echo $createdby;?>" name="createdby">
	  <input type="hidden" value="<?php echo $userID;?>" name="userID">

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Supplier Name *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter Supplier Name" name="suppliername" autocomplete="off" required> 
      </div>
  
    
   
      <label class="control-label col-sm-2" for="email">Supplier Name Tamil*</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg tamil" placeholder="Enter Supplier Name" name="sname_tamil" id="sname_tamil" autocomplete="off" required> <br>
        <a href="https://www.google.com/intl/ta/inputtools/try/" target="_blank">Tamil Type</a>
      </div>
    </div>

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Address </label>
      <div class="col-sm-4">
        <textarea  class="form-control input-lg" placeholder="Enter Address" name="address1" rows="4"></textarea>
      </div>

      <label class="control-label col-sm-2" for="email"> Supplier Code *</label>
        <div class="col-sm-4">
          <input type="text" class="form-control input-lg" placeholder="Enter Supplier Code" name="suppliercode" autocomplete="off" value="<?php echo "SUP-".$code_count; ?>" required readonly>
        </div> 
      
    </div>

    <div class="form-group">

    <label class="control-label col-sm-2" for="email"> Area</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg " placeholder="Enter area" name="area" required>
      </div>

     <label class="control-label col-sm-2" for="email"> Area Tamil</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg tamil" placeholder="Enter area" name="area_tamil" reqyured>
      </div>
    
     
    </div>
    
    <div class="form-group">
     
      <label class="control-label col-sm-2" for="email"> Pincode</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter Pincode" name="pincode">
      </div>
    
      <label class="control-label col-sm-2" for="email">Mobile *</label>
      <div class="col-sm-4">
        <input type="number" class="form-control input-lg" placeholder="Enter mobile Number" name="mobile" autocomplete="off" required>
      </div>

      
            
    </div>
        
    
        
    
        
    
        
    
    
    
    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" name="myButton" class="btn btn-default btn-lg">Save</button>
      </div>
    </div>
  </form>   
</div>


    <?php require 'footer.php' ?>
    
    <script>

  var checkForm = function(form) {

    //
    // validate form fields
    //

    form.myButton.disabled = true;
    return true;
  };


</script>



<SCRIPT language=JavaScript src="js/utf.js"></SCRIPT>
		<SCRIPT language=JavaScript src="js/tamil.js"></SCRIPT>
		
		<script>
			$(document).ready(function(){
				$('.tamil').on('keydown',function(event){
					if(event.which==121){
						$(this).toggleClass('tamil');
						return false;
					}
					if($(this).hasClass('tamil')){
						toggleKBMode(event);
					}else{
						return true;
					}
				});
				$('.tamil').on('keypress',function(event){
					if($(this).hasClass('tamil')){
						convertThis(event);
					}
				});
			});
		</script>

    
    <script>
      $('#customerMasterForm').bootstrapValidator({
        // To use feedback icons, ensure that you use Bootstrap v3.1.0 or later
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
          customername: {
                message: 'The customer name is not valid',
                validators: {
                    notEmpty: {
                        message: 'The customer name is required and cannot be empty'
                    }
                }
            },
            mobile: {
                message: 'The mobile is not valid',
                validators: {
                    notEmpty: {
                        message: 'The mobile is required and cannot be empty'
                    },
                    stringLength: {
                        min: 10,
                        max: 10,
                        message: 'The mobile must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'The mobile can only consist of number'
                    },
                }
            }

        }
    });
    
    </script>
</body>
</html>