<?php 

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

$id  =  $_GET['id'];

$sql = mysqli_query($conn,"SELECT * FROM customer_master WHERE id='$id' ");
 
$row=mysqli_fetch_array($sql,MYSQLI_ASSOC);

// `sname`, `saddress`, `customer_state`, `pincode`, `mobile`, `email`, `gstin`, `other_ref`, `scode`

$customername   = $row['cname'];
$address1       = $row['caddress'];
$cstate         = $row['customer_state'];
$pincode        = $row['pincode'];
$mobile         = $row['mobile'];
$opening_balance          = $row['opening_balance'];

$customercode   = $row['ccode'];
$gstin=$row['gstin'];


?>

<!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">Edit Customer Details</h2><br>
    <form class="form-horizontal" action="customerMasterUpdate.php" method="post">
      

    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Customer Name *</label>
      <div class="col-sm-9">
        <input type="text" class="form-control input-lg" placeholder="Enter customer Name" name="customername" autocomplete="off" value='<?php echo $customername; ?>' required> 
        <input type="hidden" value=<?php echo $id; ?> name="edit_id">
      </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"><?php echo $address1; ?></textarea>
      </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" value='<?php echo $customercode; ?>' autocomplete="off" 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">
        <option value="SELECT STATE">SELECT STATE</option>
        <option value="Andhra Pradesh" <?php if( $cstate == "Andhra Pradesh" ): ?> selected="selected"<?php endif; ?> >Andhra Pradesh</option>
        <option value="Arunachal Pradesh" <?php if( $cstate == "Arunachal Pradesh" ): ?> selected="selected"<?php endif; ?> >Arunachal Pradesh</option>
        <option value="Assam" <?php if( $cstate == "Assam" ): ?> selected="selected"<?php endif; ?> >Assam</option>
        <option value="Bihar" <?php if( $cstate == "Bihar" ): ?> selected="selected"<?php endif; ?> >Bihar</option>
        <option value="Chattisgarh" <?php if( $cstate == "Chattisgarh" ): ?> selected="selected"<?php endif; ?> >Chhattisgarh</option>
        <option value="Dadra and Nagar Haveli" <?php if( $cstate == "Dadra and Nagar Haveli" ): ?> selected="selected"<?php endif; ?> >Dadra and Nagar Haveli</option>
        <option value="Daman and Diu" <?php if( $cstate == "Daman and Diu" ): ?> selected="selected"<?php endif; ?> >Daman and Diu</option>
        <option value="Delhi" <?php if( $cstate == "Delhi" ): ?> selected="selected"<?php endif; ?> >Delhi</option>
        <option value="Goa" <?php if( $cstate == "Goa" ): ?> selected="selected"<?php endif; ?> >Goa</option>
        <option value="Gujarat" <?php if( $cstate == "Gujarat" ): ?> selected="selected"<?php endif; ?> >Gujarat</option>
        <option value="Haryana" <?php if( $cstate == "Haryana" ): ?> selected="selected"<?php endif; ?> >Haryana</option>
        <option value="Himachal Pradesh" <?php if( $cstate == "Himachal Pradesh" ): ?> selected="selected"<?php endif; ?> >Himachal Pradesh</option>
        <option value="Jammu and Kashmir" <?php if( $cstate == "Jammu and Kashmir" ): ?> selected="selected"<?php endif; ?> >Jammu and Kashmir</option>
        <option value="Jharkhand" <?php if( $cstate == "Jharkhand" ): ?> selected="selected"<?php endif; ?> >Jharkhand</option>
        <option value="Karnataka" <?php if( $cstate == "Karnataka" ): ?> selected="selected"<?php endif; ?> >Karnataka</option>
        <option value="Kerala" <?php if( $cstate == "Kerala" ): ?> selected="selected"<?php endif; ?> >Kerala</option>
        <option value="Madhya Pradesh" <?php if( $cstate == "Madhya Pradesh" ): ?> selected="selected"<?php endif; ?> >Madhya Pradesh</option>
        <option value="Maharashtra" <?php if( $cstate == "Maharashtra" ): ?> selected="selected"<?php endif; ?> >Maharashtra</option>
        <option value="Manipur" <?php if( $cstate == "Manipur" ): ?> selected="selected"<?php endif; ?> >Manipur</option>
        <option value="Meghalaya" <?php if( $cstate == "Meghalaya" ): ?> selected="selected"<?php endif; ?> >Meghalaya</option>
        <option value="Mizoram" <?php if( $cstate == "Mizoram" ): ?> selected="selected"<?php endif; ?> >Mizoram</option>
        <option value="Nagaland" <?php if( $cstate == "Nagaland" ): ?> selected="selected"<?php endif; ?> >Nagaland</option>
        <option value="Orissa" <?php if( $cstate == "Orissa" ): ?> selected="selected"<?php endif; ?> >Orissa</option>
        <option value="Puducherry"  <?php if( $cstate == "Puducherry" ): ?> selected="selected"<?php endif; ?> >Puducherry</option>
        <option value="Punjab"  <?php if( $cstate == "Punjab" ): ?> selected="selected"<?php endif; ?> >Punjab</option>
        <option value="Rajasthan"  <?php if( $cstate == "Rajasthan" ): ?> selected="selected"<?php endif; ?> >Rajasthan</option>
        <option value="Sikkim"  <?php if( $cstate == "Sikkim" ): ?> selected="selected"<?php endif; ?> >Sikkim</option>
        <option value="TamilNadu" <?php if( $cstate == "TamilNadu" ): ?> selected="selected"<?php endif; ?> >Tamil Nadu</option>
        <option value="Telangana"  <?php if( $cstate == "Telangana" ): ?> selected="selected"<?php endif; ?> >Telangana</option>
        <option value="Tripura"  <?php if( $cstate == "Tripura" ): ?> selected="selected"<?php endif; ?> >Tripura</option>
        <option value="Uttar Pradesh"  <?php if( $cstate == "Uttar Pradesh" ): ?> selected="selected"<?php endif; ?> >Uttar Pradesh</option>
        <option value="Uttarakhand"  <?php if( $cstate == "Uttarakhand" ): ?> selected="selected"<?php endif; ?> >Uttarakhand</option>
        <option value="West Bengal"  <?php if( $cstate == "West Bengal" ): ?> selected="selected"<?php endif; ?> >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" value='<?php echo $mobile; ?>' 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"  value='<?php echo $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" value='<?php echo $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" value='<?php echo $gstin; ?>'>
      </div>
      </div>
        
    

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

 <?php require 'footer.php' ?>
 <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>