 <?php

$SupplierID = '';
$SupplierName = '';
$Address = '';
$ContactNumber = '';
$AlternateContactNumber = '';
$EmailAddress = '';
$TIN = '';
$PAN = '';
$GSTNO = '';
$GSTRange = '';
$CollectrateAddress = '';
$UANumber = '';
$PaymentTerms = '';
$PaymentDays = '';
$PayableAT = '';
$IsActive = '';
$PaymentBefore = '';
$PaymentAfter = '';
$CSTNO = '';
$CSTDate = '';
if(!empty($supplier))
{
    foreach ($supplier as $uf)
    {
        $SupplierID = $uf->SupplierID;
        $SupplierName = $uf->SupplierName;
        $Address = $uf->Address;
        $ContactNumber = $uf->ContactNumber;
        $AlternateContactNumber = $uf->AlternateContactNumber;
        $EmailAddress = $uf->EmailAddress;
        $Exiseregistration = $uf->Exiseregistration;
        $TIN = $uf->TIN;
        $PAN = $uf->PAN;
        $GSTNO = $uf->GSTNO;
        $GSTRange = $uf->GSTRange;
        $CollectrateAddress = $uf->CollectrateAddress;
        $UANumber = $uf->UANumber;
        $PaymentTerms = $uf->PaymentTerms;
        $PaymentDays = $uf->PaymentDays;
        $PayableAT = $uf->PayableAT;   
		$CSTNO = $uf->CSTNO;
		$CSTDt = $uf->CSTDate;
		//echo 'CST date:'. $CSTDt ;
		if($CSTDt != '')
		{
		$dtCST = new DateTime($CSTDt);
		$CSTDate =  $dtCST ->format('Y-m-d');
		//echo $CSTDate ;
		}
			
         $chk = $uf->IsActive;  
		 
		 if($chk == 1)
		 {
			 $IsActive = 'checked';
		 }
		 else
		 {
			 $IsActive = '';
		 }
		  $Paymentchk = $uf->PaymentDays;
		  if($Paymentchk == 'Before' )
		  {
			 $PaymentBefore = 'checked'; 
			 $PaymentAfter = '';
		  }
		  else
		  {
			   $PaymentAfter = 'checked'; 
			   $PaymentBefore = '';
		  }
		  	 
    }
}


?>
 <script>

 
  function blockKeyPress(evt)
{
	 var charCode = (evt.which) ? evt.which : evt.keyCode;
	 alert(charCode);
			if(charCode == 8 || charCode == 46 )
       
			{
				return false;
			}
			else
			{
				return false;
			}
}

 function isNumberKey(evt)
       {
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode != 46 && charCode > 31 
            && (charCode < 48 || charCode > 57))
             return false;

          return true;
       }
	   
//PAN Validate 
function validatePAN() {
 var reg = /(?=.*[A-Z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Z]).{1,}$/;
          
			var PAN = $('#panno').val();
			
			if(PAN != '')
			{
				if (reg.test(PAN) == false) 
				{
					alert('Please Enter Valid PAN Number');
					return (false);
				}
				else
				{
					return true;
				}
			}
			else
			{
				alert('Please Enter PAN Number');
				return (false);
			}
			
}
function validateECCNumber() {
 var reg = /(?=.*[A-Z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Z]).{1,}(?=.*[A-Z]).{2,}(?=.*[0-9]).{3,}$/;
          
			var ECC = $('#Exciseregistration').val();
			
			if(ECC != '')
			{
				if (reg.test(ECC) == false) 
				{
					alert('Please Enter Valid Excise Control Code Number');
					return (false);
				}
				else
				{
					return true;
				}
			}
			
}
function getContactNumberValidation() {
	var contactNumber = $('#ContactNumber').val().length;
	if(contactNumber < 10)
	{
		alert('Please Enter valid Contact Number');
		return false;
	}
	else
	{
		return true;
	}
}
function getValidAlternateNumber() 
{
	var contactNumber = $('#AlternateContactNumber').val().length;
	if(!empty($('#AlternateContactNumber').val()))
	{
		if(contactNumber < 10)
		{
			alert('Please Enter valid Alternate Contact Number');
			return false;
		}
		else
		{
			return true;
		}
	}
}
 
function validateEmail() {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
          
			var email = $('#emailid').val();
			
			if(email != '')
			{
            if (reg.test(email) == false) 
            {
                alert('Please Enter Valid Email Address');
                return (false);
            }
			else
			{
				return true;
			}
			}
			else
			{
				alert('Please Enter email id');
			}
			
} 
function onlyAlphabets(evt) {
        var charCode;
        if (window.event)
            charCode = window.event.keyCode;  //for IE
        else
            charCode = evt.which;  //for firefox
        if (charCode == 32) //for &lt;space&gt; symbol
            return true;
        if (charCode > 31 && charCode < 65) //for characters before 'A' in ASCII Table
            return false;
        if (charCode > 90 && charCode < 97) //for characters between 'Z' and 'a' in ASCII Table
            return false;
        if (charCode > 122) //for characters beyond 'z' in ASCII Table
            return false;
        return true;
    }
	$(function() {
	var d = new Date();

	var month = d.getMonth();
	var day = d.getDate();
	var year = d.getFullYear()  ;
	var SIAStartYear = year - 2015;
	var mindt = year-70;
	var maxdt =  year-15;
	
	 $("#dateofCST").datepicker({
	//minDate : new Date(year-SIAStartYear,1,1),
	maxDate :'now',
	dateFormat: 'mm/dd/yy',changeMonth: true, changeYear: true,yearRange: '-100:+0'

});
});
</script>

 <style>
 legend{
 color:#00c0ef ! important;
 } 
 
   .pad{
	   padding-bottom:1%;
   }
    .badge
   {
	   color:red; background-color:#fff;
   }
 </style>
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
       <center> Siddharth Industries - <?php echo  $SupplierID;  ?>   DETAILS</center>
       
      </h1>
	  	  
    </section>
    
    <section class="content">
    <div style="text-align:right;">
    <a href="<?php echo base_url() ?>supplierListing" class="btn btn-primary" value="Back"/>Back</a>
	</div>
	<br/>
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
              <!-- general form elements -->
                               
                
                <div class="box box-primary">
                     
                <!-- form start -->
                    
   
    <div class="row">
    <div class="col-md-10 col-md-offset-1"   style="border:3px solid #3c8dbc;">
      <form class="form-horizontal" role="form" id="UpdateSupplier" action="<?php echo base_url() ?>editsupplier" method="post" role="form">
        <fieldset>
		 
          <!-- Form Name -->
          <legend>Supplier Information</legend> 
      		<div class="col-md-2 pad">
			<span for="SupplierID">Supplier ID</span>
            <input type="text" name="SupplierID" id="SupplierID"  class="form-control" readonly  value="<?php echo $SupplierID;?>">   
			</div>
            <div class="col-md-4 pad">
			<span for="SupplierName">Supplier Name</span><span class="badge">*</span>
            <input type="text" name="SupplierName" onkeypress="return onlyAlphabets(event);" maxlength="100" id="supplierName"  class="form-control" required value="<?php echo $SupplierName;?>">
			
			  </div>
             
            <div class="col-md-2 pad">
				<span for="ContactNumber">Contact Number</span><span class="badge">*</span>             
				<input type="text" name="ContactNumber" onchange="return getContactNumberValidation();"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="ContactNumber" required pattern="(.){10,10}" maxlength="10"  class="form-control" value="<?php echo $ContactNumber;?>" title="Please Enter 10 digit Number">
            </div>
			
			<div class="col-md-2 pad"> 
				<span for="AlternateContactNumber">Alternate Contact Number</span>
				<input type="text" name="AlternateContactNumber" onchange="return getValidAlternateNumber();"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" id="AlternateContactNumber"  pattern="(.){10,10}" maxlength="10"  class="form-control" value="<?php echo $AlternateContactNumber;?>"  title="Please Enter 10 digit Number">
            </div>
			
			<div class="col-md-2 pad">
				<span for="EmailAddress">Email ID</span><span class="badge">*</span>
				<input type="email" name="emailid" id="emailid" pattern="([A-Z0-9_\-\.])+\@([A-Z0-9_\-\.])+\.([A-Z]{2,4})" required  maxlength="100" class="form-control" value="<?php echo $EmailAddress;?>" title="Please Enter valid mail address" onchange="validateEmail();">
            </div>
             <div class="col-md-12">
			</br><input type="checkbox" id="isactive"  <?php echo $IsActive;?>   name="isactive" > IsActive </div>
<!-- Address Section -->
          <!-- Form Name -->
          <legend>Address Details</legend>
          <!-- Text input-->
         
            <div class="col-md-12"><span for="Address2">Address</span><span class="badge">*</span>
                <input type="text" class="form-control required" id="Address" name="Address" maxlength="500" required value="<?php echo $Address;?>">
            </div>
                
  
          
          <legend>Tax Related Data</legend>
          <!-- Text input-->
		  
         
		    <div class="col-md-3 pad">
			   <span for="PAN">PAN</span> <span class="badge">*</span>
                <input type="text" id="panno"  maxlength="10"  name="panno" required   pattern="(?=.*[A-Z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Z]).{1,}" onchange="validatePAN();" class="form-control" value="<?php echo $PAN;?>" style="text-transform:uppercase;" title="Please Enter 5 Character and 4 digit numbers and 1 Character format">
		    </div>
			 <div class="col-md-3 pad">
			<span for="TIN">TIN</span><span class="badge">*</span>
                <input type="text"  class="form-control required"  value="<?php echo $TIN;?>"   pattern="(.){11,11}" id="TIN" name="TIN" minlength="11" maxlength="11"  onkeypress="return event.charCode >= 48 && event.charCode <= 57" title="Please Enter 11 digit Number">
            </div>
			<div class="col-md-3 pad">			
			    <span for="UANumber">UA Number</span>
                <input type="text"  class="form-control" pattern="^\d{12}$" id="UANumber" name="UANumber" maxlength="12" value="<?php echo $UANumber;?>" title="Please Enter 12 digit Number">
            </div>
			
            <div class="col-md-3 pad">			
			<span for="Exciseregistration">Excise Registration</span>
                <input type="text"  class="form-control required"  onchange="validateECCNumber();" id="Exciseregistration" name="Exciseregistration" minlength="15" maxlength="15" value="<?php echo $Exiseregistration;?>" style="text-transform:uppercase;" title="Please enter PAN Number and EM/ED option and 3 digit Numbers format" pattern="(?=.*[A-Z]).{5,}(?=.*[0-9]).{4,}(?=.*[A-Z]).{1,}(?=.*[A-Z]).{2,}(?=.*[0-9]).{3,}">
            </div>
			 <div class="col-md-3 pad">
			<span for="GSTNo">CST Number</span>
                <input type="text"  class="form-control "  value="<?php echo $CSTNO;?>" id="CSTNo"  name="CSTNo" maxlength="15">
            </div>
			 <div class="col-md-3 pad"><span>CST Registration Date</span>
              <input  id="dateofCST" name="dateofCST" value="<?php echo $CSTDate;?>"    onkeypress="return false;" maxlength="10"   class="form-control">
            </div>
            <div class="col-md-3 pad">
			<span for="GSTNo">GST Number</span>
                <input type="text"  class="form-control " value="<?php echo $GSTNO;?>" id="GSTNo"  name="GSTNo" maxlength="10">
            </div>
			
			<div class="col-md-3 pad">
			<span for="Range">GST Range</span>
                <input type="text"  class="form-control " id="GSTRange"  value="<?php echo $GSTRange;?>"  name="GSTRange" maxlength="10">
            </div>
			<!-- Text input-->
        
            <div class="col-md-6 pad"><span for="CollectrateAddress">Collectrate Address</span>
            <input type="text"  class="form-control " id="CollectrateAddress"  value="<?php echo $CollectrateAddress;?>"  name="CollectrateAddress" maxlength="500" >
            </div>
			
            
         
          <!-- Text input-->
		   <legend>Payment Details</legend>
          <!-- Text input-->
		  
       
            <div class="col-md-3">
			    <span for="payablefrom">Payable Terms</span>
				    <select class="form-control required" id="PaymentTerms" name="PaymentTerms">
					    <option value="<?php echo $PaymentTerms;?>" ><?php echo $PaymentTerms;?></option>
							<?php
							if(!empty($payment))
							{
								foreach ($payment as $rl)
								{									
									?>
									<option value="<?php echo $rl->ConfigValue ?>"><?php echo $rl->ConfigValue ?></option>
									<?php
									
								}
							}
							?>
					</select>
            </div>
			
            <div class="col-md-3">
			  <span for="PayableAT">Payable AT</span>
              <input type="text"   class="form-control required" value="<?php echo $PayableAT;?>" id="PayableAT" name="PayableAT">	 
            </div>
			
            <div class="col-md-3"><span>Payment Date</span><br/>
				<label class="radio-inline"><input type="radio" name="Payment"  <?php echo $PaymentBefore; ?>   value="Before">Before</label>
				<label class="radio-inline"><input type="radio" name="Payment"  <?php echo  $PaymentAfter; ?>  value="After">After</label>
            </div>
			 
     
	   

          <div class="form-group">
            <div class="col-md-3 col-md-offset-9">
              <div class="pull-right">
               <input type="reset" id="reset"  class="btn btn-info" value="Reset" />
                <input type="submit" onclick="validate();"   class="btn btn-primary">
              </div>
            </div>
          </div>
        </fieldset>
      </form>
    </div><!-- /.col-lg-12 -->
</div><!-- /.row -->
    
                        
                     
                </div>
            </div>
            <div class="col-md-4">
                <?php
                    $this->load->helper('form');
                    $error = $this->session->flashdata('error');
                    if($error)
                    {
                ?>
                <div class="alert alert-danger alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('error'); ?>                    
                </div>
                <?php } ?>
                <?php  
                    $success = $this->session->flashdata('success');
                    if($success)
                    {
                ?>
                <div class="alert alert-success alert-dismissable">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <?php echo $this->session->flashdata('success'); ?>
                </div>
                <?php } ?>
                
                <div class="row">
                    <div class="col-md-12">
                        <?php echo validation_errors('<div class="alert alert-danger alert-dismissable">', ' <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button></div>'); ?>
                    </div>
                </div>
            </div>
        </div>    
    </section>
    
</div>
<script>
function Validate()
{
	if(!validatePAN())
	{
		return false;
		$('#panno').focus();
	}
}

//Call to ajax existing PAN
 $('#panno').change(function() {
    
 var id = $('#panno').val();
		if(id != '')
		{
		 $.ajax({
			data:{id:id},
			
			type:"POST",
			url:"<?php echo base_url();?>supplier/checkPAN",
			success:function(data) {
				if(data)
			{
				
			var answer = confirm(data+""+" supplier details is already exists in the database.Do you want to change the SUPPLIER details?")
				if (answer) {        
	                $('#panno').val('');
					$('#panno').focus();
                                        return false;
	             	}
			else 
				{
					alert('Please edit the supplier details in the Edit screen and change the supplier status to Active');
				    window.location = 'supplier/supplierListing';	
				}					
			
		      }
			}
		
		});	
		}
		else
		{
			alert('Please enter the PAN Number');
			$('#panno').focus();
                        return false;
		}
  
});
</script>
