<script src="http://geodata.solutions/includes/countrystatecity.js"></script>
	<div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark"><?php echo (isset($organizationdetails))?'Edit Organization':'Add Organization' ?>
            </h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?= base_url(); ?>organization">Organization</a></li>
              <li class="breadcrumb-item active"><?php echo (isset($organizationdetails))?'Edit Organization':'Add Organization' ?></li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
       	      <form method="post" id="customer_add" class="card" action="<?php echo base_url();?>organization/<?php echo (isset($organizationdetails))?'updateorganization':'insertorganization'; ?>">  
          <div class="card-body"> 

                  <div class="row">
                     <?php if(isset($organizationdetails)) { ?>
                   <input type="hidden" name="org_id" id="org_id" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_id']:'' ?>" >
                 <?php } ?>
                    <div class="col-sm-6 col-md-3">
                      <div class="form-group">
                          <label class="form-label">Organization Name<span class="form-required">*</span></label>
                          <input type="text" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_name']:'' ?>" id="org_name" name="org_name" placeholder="Organization Name">
                      </div>
                    </div>
                    <div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Organization Category<span class="form-required">*</span></label>
                          <input type="text" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_category']:'' ?>" id="org_category" name="org_category" placeholder="Organization Category">
                      </div>
                    </div>
					           <div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Organization Email<span class="form-required">*</span></label>
                          <input type="email" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_email']:'' ?>" id="org_email" name="org_email" placeholder="Organization Email">
                      </div>
                    </div>
					             <div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Organization Phone<span class="form-required">*</span></label>
                          <input type="text" maxlength="10" pattern="[6789][0-9]{9}" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_phone']:'' ?>" id="org_phone" name="org_phone" placeholder="Organization Phone">
                      </div>
                    </div>			
              				<div class="col-sm-6 col-md-3">
                    <div class="form-group">
                      <label class="form-label">Organization Country<span class="form-required">*</span></label>
                <select name="org_country" required="true" id="org_country" class="form-control">
                  <option value="">Select Country</option>
                 <?php  foreach ($country as  $countrylists) { ?>
                      <option <?php if((isset($organizationdetails)) && $organizationdetails[0]['org_country'] == $countrylists->country_id){ echo 'selected';} ?> value="<?php echo output($countrylists->country_id) ?>"><?php echo output($countrylists->country_name); ?></option>
                      <?php  } ?>
                 </select>
                </div>
                </div>
                <div class="col-sm-6 col-md-3">
                <div class="form-group">
                  <label class="form-label">Organization State<span class="form-required">*</span></label>
                 <select name="org_state" id="org_state" required="true" class="form-control">
                  <option value="">Select State</option> 
                  <?php  foreach ($state as  $statelists) { ?>
                        <option <?php if((isset($organizationdetails)) && $organizationdetails[0]['org_state'] == $statelists->state_id){ echo 'selected';} ?> value="<?php echo output($statelists->state_id) ?>"><?php echo output($statelists->state_name); ?></option>
                        <?php  } ?>
                 </select>
                </div>
                </div>
                
                <div class="col-sm-6 col-md-3">
                <div class="form-group">
                  <label class="form-label">Organization City<span class="form-required">*</span></label>
                 <select name="org_city" id="org_city"  required="true" class="form-control">
                  <option value="">Select City</option>
                  <?php  foreach ($city as  $citylists){ ?>
                        <option <?php if((isset($organizationdetails)) && $organizationdetails[0]['org_city'] == $citylists->city_id){ echo 'selected';} ?> value="<?php echo output($citylists->city_id) ?>"><?php echo output($citylists->city_name); ?></option>
                        <?php  } ?>
                 </select>
                </div>
              </div>
			
					<div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Organization Pincode<span class="form-required">*</span></label>
                          <input type="text" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_pincode']:'' ?>" id="org_pincode" name="org_pincode" placeholder="Organization Pincode">
                      </div>
                    </div>
					<div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Organization Gst<span class="form-required"></span></label>
                          <input type="text"  class="form-control org_gsts" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_gst']:'' ?>" id="org_gst" name="org_gst" placeholder="Organization Gst">
                      </div>
                    </div>

					<div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Admin Name<span class="form-required">*</span></label>
                          <input type="text" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_admin_name']:'' ?>" id="org_admin_name" name="org_admin_name" placeholder="Organization Admin Name">
                      </div>
                    </div>
					<div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Admin Email<span class="form-required">*</span></label>
                          <input type="email" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_admin_email']:'' ?>" id="org_admin_email" name="org_admin_email" placeholder="Organization Admin Email ">
                      </div>
                    </div>
					<div class="col-sm-6 col-md-3">
                      <div class="form-group">
                         <label class="form-label">Admin Phone<span class="form-required">*</span></label>
                          <input type="text" maxlength="10" pattern="[6789][0-9]{9}" required="true" class="form-control" value="<?php echo (isset($organizationdetails)) ? $organizationdetails[0]['org_admin_phone']:'' ?>" id="org_admin_phone" name="org_admin_phone" placeholder="Organization Admin Phone ">
                      </div>
                    </div>	
                </div>
                 <input type="hidden" id="org_created_date" name="org_created_date" value="<?php echo date('Y-m-d h:i:s'); ?>">
  
      <div class="modal-footer">

                  <button type="submit" class="btn btn-primary"> <?php echo (isset($organizationdetails))?'Update Organization':'Add Organization' ?></button>
      </div>
    </div>
    </form>
             </div>
    </section>
	<script type="text/javascript">      
$(document).ready(function () {      
$(".org_gst").change(function () {    
                var inputvalues = $(this).val();    
                var gstinformat = new RegExp('^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]1}[1-9A-Z]{1}Z[0-9A-Z]{1}$');    
                if (gstinformat.test(inputvalues)) {    
                    return true;     
                } else {    
                    alert('Please Enter Valid GSTIN Number');    
                    $(".org_gst").val('');    
                    $(".org_gst").focus();    
                }    
            });          
 });          
  </script>    
    <!-- /.content -->
    <script>
$(document).ready(function(){
 $('#org_country').change(function(){
  var country_id = $('#org_country').val();
  if(country_id != '')
  {
   $.ajax({
    url:"<?php echo base_url(); ?>Organization/fetch_state",
    method:"POST",
    data:{country_id:country_id},
    success:function(data)
    {
     $('#org_state').html(data);
     $('#org_city').html('<option value="">Select City</option>');
    }
   });
  }
  else
  {
   $('#org_state').html('<option value="">Select State</option>');
   $('#org_city').html('<option value="">Select City</option>');
  }
 });

 $('#org_state').change(function(){
  var state_id = $('#org_state').val();
  if(state_id != '')
  {
   $.ajax({
    url:"<?php echo base_url(); ?>Organization/fetch_city",
    method:"POST",
    data:{state_id:state_id},
    success:function(data)
    {
     $('#org_city').html(data);
    }
   });
  }
  else
  {
   $('#org_city').html('<option value="">Select City</option>');
  }
 });
 
});
</script>