<?php
@session_start();
@ob_start();

include "header.php"; 
$objIms->supplier_alter();
?>
<script type="text/javascript">
	$(document).ready(function() {                
				$("#FORMNAME1").validate({
                    rules: {
					contact_no:"required number",
                   address:"required",
				  
					},
		messages: {
			
					 supplier_name: "",
					 address: "",
					 contact_no:"",
					 contact_person: "",
					
								
				},
		  });                
            });
//---auto search-----
</script>
<script type="text/javascript"> 
 
		jQuery(document).ready(function(){
			$('#emp_name').autocomplete({source:'../ProgramFile/auto/TMS_suggest_EmpName.php', minLength:1,
			select: function (event, ui) {
        	$("#trn_atndnt_mas_id").val(ui.item.trn_atndnt_mas_id);
			$("#emp_name").val(ui.item.value); // display the selected text.
						
    }
			});
			
			
		}); 
	</script> 
<!-- Page wrapper  -->
        <div class="page-wrapper">
           
            <!-- Container fluid  -->
             <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row justify-content-center">
                    <div class="col-lg-6">
                        <div class="card">
						<h4>Add Supplier <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h4>
						<hr />
<?php 
if(isset($_REQUEST["uid"])){

 $sql = "SELECT * FROM tbl_supplier WHERE md5(id) = '".$_REQUEST["uid"]."' and session_login_id = '".$_SESSION['login_id']."'";
  $res = mysql_query($sql);
  $row = mysql_fetch_assoc($res);
  $supplier_name = $row["supplier_name"];
  $address = $row["address"];
  $contact_no = $row["contact_no"];
  $contact_person = $row["contact_person"];
  $email_id = $row["email_id"];
  $gstin = $row["gstin"];
  $panno = $row["panno"];
}
if((isset($_REQUEST["Edit"])) AND (isset($_REQUEST["uid"]))){
  $id_1 = $_REQUEST["uid"]; 
  $supplier_name1 = $_REQUEST["supplier_name"];
  $address1 = $_REQUEST["address"];
  $contact_no1 = $_REQUEST["contact_no"];
  $contact_person1 = $_REQUEST["contact_person"];
  $gstin1 = $_REQUEST["gstin"];
  $pan_no1 = $_REQUEST["pan_no"];
  $email1 = $_REQUEST["email"];

$sql_update = "UPDATE tbl_supplier SET supplier_name ='$supplier_name1', address='$address1', contact_no='$contact_no1', contact_person = '$contact_person1', gstin = '$gstin1', panno = '$pan_no1', email_id = '$email1' WHERE md5(id)= '$id_1' and session_login_id = '".$_SESSION['login_id']."'";
  $res_update =mysql_query($sql_update);
?>
<script type="text/javascript">
     alert('Success');
    location.href="supplier_list.php";
</script>
<?php
}
?>		
<?php
if(isset($_REQUEST["Save"])){
$supplier_name2 = $_REQUEST["supplier_name"];
  $address2 = $_REQUEST["address"];
  $contact_no2 = $_REQUEST["contact_no"];
  $contact_person2 = $_REQUEST["contact_person"];
  $gstin2 = $_REQUEST["gstin"];
  $email2 = $_REQUEST["email"];
  $pan_no2 = $_REQUEST["pan_no"];

 $sql_ins = "INSERT INTO tbl_supplier (supplier_name, address, contact_no, contact_person, gstin, panno ,email_id ,session_login_id) VALUES ('$supplier_name2', '$address2', '$contact_no2', '$contact_person2', '$gstin2', '$pan_no2','$email2','".$_SESSION['login_id']."')";
$res_ins = mysql_query($sql_ins);
    ?>
        <script>
        alert('Success');
        location.href='supplier_list.php';
        </script>
        <?php

}
?>		
						
                                    <form class="form-valide" method="post">
									<?php  echo $objIms->error;?>
                                        <div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Supplier Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type="text" class="form-control"  name="supplier_name" id="supplier_name"  value="<?php echo $supplier_name; ?>" required="required" <?php echo $objIms->disableit;?>>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Address <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <textarea name="address" id="address" maxlength="50"  class="form-control" <?php echo $address; ?> ><?php echo $objIms->address;?></textarea>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact No <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="contact_no" type ="number" value="<?php echo $contact_no; ?>" id="contact_no"  onkeypress="return validate(event)" class="form-control" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Contact Person Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="contact_person" type ="text" value="<?php echo $contact_person; ?>" id="contact_person" class="form-control" required <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">GSTIN<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="gstin" type ="text" id="gstin" class="form-control" value="<?php echo $gstin; ?>" required="required" <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
                   <div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Pan No<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                 <input name="pan_no" type ="text" id="pan_no" class="form-control" value="<?php echo $pan_no; ?>" required="required" <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Email <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input type="email" name="email"  id="email" class="form-control" required="" value="<?php echo $email_id; ?>"  <?php echo $objIms->disableit;?>/>
                                            </div>
                                        </div>
                                        
                                        <div class="form-group row">
                                            <div class="col-lg-8 ml-auto">
                                             <?php     if(isset($_REQUEST['uid'])) { ?><input type ="submit" name="Edit" value="Edit" class="btn btn-primary"/><?php } else{ ?>
                                                <input type ="submit" name="Save" value="Save" class="btn btn-primary"/><?php } ?>
                                                
                                            </div>
                                        </div>
                                    </form>
						
						
						
	
  </div>

                            </div>
						
                            
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->
<?php include 'footer.php' ?>
<script type="text/javascript">
    
    $(function() {

  $('#supplier_name').keydown(function (e) {
  
    if (e.ctrlKey || e.altKey) {
    alert("only character allow");
      e.preventDefault();
      
    } else {
    
      var key = e.keyCode;
      
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        alert("only character allow");
        e.preventDefault();
        
      }

    }
    
  });
  
});
</script>
<script type="text/javascript">
    function validate(key)
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('contact_no');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57))
{
    alert("no only allow")
return false;

}
else
{
//Condition to check textbox contains ten numbers or not
if (phn.value.length <10)
{
return true;
}
else
{
    alert("not greater than 10")
return false;

}
}
}
</script>
<script type="text/javascript">
    
    $(function() {

  $('#contact_person').keydown(function (e) {
  
    if (e.ctrlKey || e.altKey) {
    alert("only character allow");
      e.preventDefault();
      
    } else {
    
      var key = e.keyCode;
      
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        alert("only character allow");
        e.preventDefault();
        
      }

    }
    
  });
  
});
</script>