<?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;

?>

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

function validateForm() {
  var address1 = document.forms["myForm"]["address1"].value;
   var state = document.forms["myForm"]["state"].value;
   
   var stype = document.forms["myForm"]["stype"].value;
  
  
  if (address1 == "") {
    alert("Please Fill Address");
    return false;
  }
  
  if (state == "a") {
    alert("Please Select State");
    return false;
  }
  
   if (stype == "a") {
    alert("Please Select Supplier Type");
    return false;
  }
  
  
}
</script>
</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="supplierMasterForm" onSubmit="return checkForm(this);" name="myForm">
      

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">supplier Name *</label>
      <div class="col-sm-9">
        <input type="text" class="form-control input-lg" placeholder="Enter supplier Name" name="suppliername" autocomplete="off" required> 
      </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" required></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 "SUPP-".$code_count; ?>" required readonly>
        </div> 
      
    </div>

    
    
    <div class="form-group">
      <label class="control-label col-sm-2" for="email">State</label>
      <div class="col-sm-4">
      <select class="form-control input-lg" name="state" required>
        <option value="">SELECT STATE</option>
        <option value="Andhra Pradesh">Andhra Pradesh</option>
        <option value="Arunachal Pradesh">Arunachal Pradesh</option>
        <option value="Assam">Assam</option>
        <option value="Bihar">Bihar</option>
        <option value="Chhattisgarh">Chhattisgarh</option>
        <option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
        <option value="Daman and Diu">Daman and Diu</option>
        <option value="Delhi">Delhi</option><option value="Goa">Goa</option>
        <option value="Gujarat">Gujarat</option>
        <option value="Haryana">Haryana</option>
        <option value="Himachal Pradesh">Himachal Pradesh</option>
        <option value="Jammu and Kashmir">Jammu and Kashmir</option>
        <option value="Jharkhand">Jharkhand</option>
        <option value="Karnataka">Karnataka</option>
        <option value="Kerala">Kerala</option>
        <option value="Madhya Pradesh">Madhya Pradesh</option>
        <option value="Maharashtra">Maharashtra</option>
        <option value="Manipur">Manipur</option>
        <option value="Meghalaya">Meghalaya</option>
        <option value="Mizoram">Mizoram</option>
        <option value="Nagaland">Nagaland</option>
        <option value="Orissa">Orissa</option>
        <option value="Puducherry">Puducherry</option>
        <option value="Punjab">Punjab</option>
        <option value="Rajasthan">Rajasthan</option>
        <option value="Sikkim">Sikkim</option>
        <option value="TamilNadu">Tamil Nadu</option>
        <option value="Telangana">Telangana</option>
        <option value="Tripura">Tripura</option>
        <option value="Uttar Pradesh">Uttar Pradesh</option>
        <option value="Uttarakhand">Uttarakhand</option>
        <option value="West Bengal">West Bengal</option>
        </select>
      </div>
    
      <label class="control-label col-sm-2" for="email">Mobile *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter mobile Number" name="mobile" autocomplete="off" required >
      </div>

      
            
    </div>
        
    
        
    <div class="form-group">

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

      <label class="control-label col-sm-2" for="email"> Opening Balance</label>
      <div class="col-sm-4">
        <input type="number" class="form-control input-lg"  name="opening_balance" required>
      </div>
    
     
    </div>
        
    
        
    
    

    
    <div class="form-group">        
      <div class="col-sm-12 text-center">
        <button type="submit" class="btn btn-default btn-lg" name="myButton" id="btn">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>
      $('#supplierMasterForm').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: {
          suppliername: {
                message: 'The supplier name is not valid',
                validators: {
                    notEmpty: {
                        message: 'The supplier 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 10 and less than 10 characters long'
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'The mobile can only consist of number'
                    },
                }
            }

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