<?php 

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

$sql_InvoiceQuery   = mysqli_query($conn,"SELECT count(*) as code FROM customer_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">Customer Master Details</h2><br>
    <form class="form-horizontal" action="customerMasterInsert.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">Customer Name *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter Customer Name" name="customername" autocomplete="off" required> 
      </div>
      
       <label class="control-label col-sm-2" for="email">Customer Name Tamil *</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter Customer Name" name="customername_tamil" autocomplete="off" required> 
        <a href="https://www.google.com/inputtools/try/" target="_blank">Tamil Typing</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">Address Tamil</label>
      <div class="col-sm-4">
        <textarea  class="form-control input-lg" placeholder="Enter Address" name="address1_tamil" rows="4"></textarea>
      </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="number" 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="text" class="form-control input-lg" placeholder="Enter Pincode" name="pincode" required>
      </div>

      <label class="control-label col-sm-2" for="email"> Opening&nbsp;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">

    <label class="control-label col-sm-2" for="email"> GSTIN</label>
      <div class="col-sm-4">
        <input type="text" class="form-control input-lg" placeholder="Enter GST" name="gstin" >
      </div>
      <label class="control-label col-sm-2" for="email"> Customer Code *</label>
        <div class="col-sm-4">
          <input type="text" class="form-control input-lg" placeholder="Enter Customer Code" name="customercode" autocomplete="off" value="<?php echo "CUS-".$code_count; ?>" required readonly>
        </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>
      $('#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>