<?php 

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

$id  =  $_GET['id'];

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

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

$suppliername   = $row['sname'];
$address1       = $row['saddress'];
$cstate         = $row['supplier_state'];
$pincode        = $row['pincode'];
$mobile         = $row['mobile'];
$opening_balance          = $row['opening_balance'];

$suppliercode   = $row['scode'];


?>

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

    <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" value='<?php echo $suppliername; ?>' 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"> supplier Code *</label>
        <div class="col-sm-4">
          <input type="text" class="form-control input-lg" placeholder="Enter supplier Code" name="suppliercode" value='<?php echo $suppliercode; ?>' autocomplete="off" required>
        </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" <?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_balace</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">        
      <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>
      $('#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 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[0-9]+$/,
                        message: 'The mobile can only consist of number'
                    },
                }
            }

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