<?php
  include('common/header.php');
  //error_reporting(E_ALL);
    $customer_gst_no='';
    $date_of_enrollment= '';
    $contact_person_name= '';
    $designation= '';
    $mobile_no= '';
    $email_id= '';
    $address_line1='';
    $address_line2= '';
    $customer_name= '';
    $customer_pan_no='';
    $customer_pan_no='';
    $postal_code='';
    $city_name=''; 
    $state_name=''; 

?>
<?php
 if ($this->uri->segment(4)) {
   foreach ($customer as  $value){
    $customer_id=$value['customer_id'];
    $state_id=$value['state_id'];
    $country_id=$value['country_id'];
    $company_branch_id=$value['company_branch_id'];
    $city_id=$value['city_id'];
    $customer_name=$value['customer_name'];
    $customer_pan_no=$value['customer_pan_no'];
    $customer_gst_no=$value['customer_gst_no'];
    $date_of_enrollment= $value['date_of_enrollment'];
    $contact_person_name= $value['contact_person_name'];
    $designation=  $value['designation'];
    $mobile_no=  $value['mobile_no'];
    $email_id=  $value['email_id'];
    $address_line1= $value['address_line1'];
    $address_line2=  $value['address_line2'];
    $postal_code= $value['postal_code'];
    $city_name= $value['city_name']; 
    $state_name= $value['state_name'];                
   }
  }
 ?>
  <div class="">
    <div class="col-xm-12">
      <div class="widget-box light-border">
        <!-- <div class="widget-header header-color-grey">
          <h4 class="smaller">
            Customer 
          </h4>
        </div> -->
        <div class="widget-body">
          <div class="widget-main">
            <div class="row">
              <div class="col-sm-12">

                
                  <form class="form-horizontal" method="post" action="<?php echo base_url()?>index.php/<?php echo CUSTOMER_MASTER;?>add_customer" onsubmit="return validateForm();" name="manage_client" id="manage_client">

                  
                  <input type="hidden" value="<?php echo $customer_id ?>" name="hidden">
                  <section class="panel panel-default">
                  <header class="panel-heading bg-info lt font-bold">Company Details</header>
                  <!-- panel body start -->
                  <div class="panel-body bs-example form-horizontal">
                    <div class="">
                     <div class="hr hr12 dotted"></div>
                       <div class="">
                        <!-- main col-sm-12 -->
                      <div class="col-sm-12"> 
                          <div class="col-sm-6">
                           <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Branch Company Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <select name="branch_name" id="branch_name" class="form-control" required>
                                 <option value="">Select Branch Company Name</option>
                                          <?php  
                                          foreach ($branch_name as  $branch) {
                                           if ($company_branch_id == $branch['company_branch_id']) {?>
                                            <option value="<?php echo $branch['company_branch_id'] ?>" selected><?php echo $branch['company_branch_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                            <option value="<?php echo $branch['company_branch_id'] ?>"><?php echo $branch['company_branch_name'] ; ?><?php  } }
                                      ?>                                           
                                </select>              
                              </div>
                            </div>
                          </div>


   
                        
                          <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Customer Name:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="cutomer_name" value="<?php echo $customer_name;?>" id="customer_name" placeholder="Customer Name" class="form-control"  maxlength="75" /> 
                                  <!--  -->
                                 <span id="cutomer_name1" class="text-danger font-weight-bold"></span>            
                              </div>
                            </div>
                          </div>
                        </div>
                            

    
                        <div class="col-sm-12">
                          <div class="col-sm-6">                            
                             <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Customer PAN Number:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                              
                                <input type="text" name="cutomer_pan" value="<?php echo $customer_pan_no;?>" id="cutomer_pan" placeholder="Customer PAN  Number" class="form-control" maxlength="15" />
                              
                                <span id="cutomer_pan1" class="text-danger font-weight-bold"></span>               
                              </div>
                              </div>
                          </div>
                          <div class="col-sm-6"> 
                            <div class="form-group">
                             <label for="client_code" class="col-sm-5 control-label required">Customer GST Number:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                
                                <input type="text" name="cutomer_gst" value="<?php echo $customer_gst_no;?>" id="cutomer_gst" placeholder="Customer GST  Number" class="form-control" maxlength="20" />

                                 <span id="cutomer_gst1" class="text-danger font-weight-bold"></span>               
                              </div>
                            </div>
                          </div>
                      </div>



                      <div class="col-sm-12">
                       
   

                      </div>

                    
                        <div class="col-sm-12">
                           <div class="col-sm-6">                             
                            <div class="form-group">
                               <label for="client_code" class="col-sm-5 control-label required">Date Of Enrollment:<font style="color:red">*</font></label>
                                <div class="col-sm-7">  
                                  <div class="input-group">
                                   
                                   <input class="form-control date-picker" id="id-date-picker-2" type="text" data-date-format="dd-mm-yyyy" name="date_of_enroll" value="<?php echo $date_of_enrollment;?>" autocomplete="off">
                                    <span class="input-group-addon">
                                     <i class="fa fa-calendar bigger-110"></i>
                                    </span>
                                  </div>
                                   <span id="date1" class="text-danger font-weight-bold"></span>  
                                </div>
                            </div>

                          </div>
                        </div>

                        


                         <!-- </div> -->
                         <!-- main col-sm-12  close-->
                       </div> <!-- blank close -->
        </div><!-- blank close -->
      </div>   <!-- panel body close -->
    </section> <!-- section close -->

       <!-- customer contact start -->
    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold">Contact Details</header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">

              <div class="col-sm-6">  
                <div class="form-group" id="qc_name">
                      <label for="qc_name" class="col-sm-5 control-label required">Contact Person Name:<font style="color:red">*</font></label>
                        <div class="col-sm-7">
                                                   
                         <input type="text" name="contact_person_name" value="<?php echo $contact_person_name;?>" id="contact_person_name" placeholder="Contact Person Name" class="form-control" maxlength="75"  />
                         <span id="contact_person_name1" class="text-danger font-weight-bold"></span>                       
                        </div>
                    </div>
               </div>


               <div class="col-sm-6">
                    <div class="form-group">
                       <label for="client_code" class="col-sm-5 control-label required"> Designation:<font style="color:red">*</font></label>
                          <div class="col-sm-7">

                             
                            <input type="text" name="cutomer_designation" value="<?php echo $designation;?>" id="cutomer_designation" placeholder="Designation" class="form-control" maxlength="75" />
                              <span id="cutomer_designation1" class="text-danger font-weight-bold"></span>              
                          </div>
                    </div>
                  </div>

              <div class="col-sm-6">    


                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Mobile Number:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                 
                                <input type="text" name="cutomer_mobile" value="<?php echo $mobile_no;?>" id="cutomer_mobile" placeholder="Mobile Number" class="form-control" maxlength="10">
                                <span id="cutomer_mobile1" class="text-danger font-weight-bold"></span>                                          
                              </div>   


                </div>                         
            </div> <!-- col-ms-6 close -->

              <div class="col-sm-6">    
   
                  <div class="form-group">
                                <label for="client_code" class="col-sm-5 control-label required">Email Id:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                               
                                <input type="text" name="cutomer_email" value="<?php echo $email_id;?>" id="cutomer_email" placeholder="Email Id" class="form-control" maxlength="25" />
                             
                                <span id="cutomer_email1" class="text-danger font-weight-bold"></span>             
                              </div>
                </div>                            
            </div> <!-- col-ms-6 close -->

           <!--  -------------------------------------------addmore------------------------- -->

            <div class="col-sm-6" id="contactname1">  
                <div class="form-group" id="qc_name">
                      <label for="qc_name" class="col-sm-5 control-label required">Contact Person Name:<font style="color:red">*</font></label>
                        <div class="col-sm-7">                             
                         <input type="text" name="contact_person_name1" value="" id="contact_person_named" placeholder="Contact Person Name" class="form-control" maxlength="75" /> 
                     
                        </div>
                    </div>
              </div>

              <div class="col-sm-6" id="mobilenumber1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Mobile Number:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="cutomer_mobile1" value="" id="cutomer_mobiled" placeholder="Mobile Number" class="form-control" maxlength="10"> 
                                                                       
                              </div>  

                </div>                         
            </div>
            <div class="col-sm-6" id="email1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Email_id:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="cutomer_email1" value="" id="cutomer_email1" placeholder="Email ID" class="form-control" maxlength="25"> 
                                                                       
                              </div>  

                </div>  

            </div>
            <div class="col-sm-6" id="design1">    

                <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required">Designation:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                <input type="text" name="designation1" value="" id="designationed" placeholder="Mobile Number" class="form-control" maxlength="75"> 
                                                                        
                              </div>  

                </div>                         
            </div>
<!--  -------------------------------------------addmore------------------------- -->

          
            </div>
            <button type="button" class="btn btn-primary btn-xs" id="addmore" style="float: right;">Add More</button>
             <button type="button" class="btn btn-primary btn-xs" id="cancel" style="float: right;">cancel</button>
          </div>
        </div>
      </div>
    </section>


    <!-- customer location start -->
    <section class="panel panel-default">
      <header class="panel-heading bg-info lt font-bold">Location Details</header>
       <div class="panel-body bs-example form-horizontal">
        <div class="">
          <div class="hr hr12 dotted"></div>
          <div class="">
            <div class="col-sm-12">
              <div class="col-sm-6">    
                <div class="form-group">

   
                  <label class="col-sm-5 control-label required" for="form-field-2 ">Customer Address line 1:<font style="color:red">*</font></label>
                  <div class="col-sm-7">


                   
                    <input type="text" name="customer_addressl1" value="<?php echo $address_line1;?>" id="customer_addressl1" placeholder="Customer Address line 1" class="form-control" maxlength="75" />

                    <span id="customer_addressl1_1" class="text-danger font-weight-bold"></span>                   
                  </div>
              </div>             
               </div>



               <div class="col-sm-6">
                    <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required">Customer Address line 2: </label>
                  <div class="col-sm-7">
                                           
                      <input type="text" name="customer_addressl2" value="<?php echo $address_line2;?>" id="customer_addressl2" placeholder="Customer Address line 2" class="form-control" maxlength="75" />                   
                  </div>
                </div>
                  </div> 



  
            </div>
                <!-- <div class="col-sm-12">
                
              </div> -->

              <div class="col-sm-12">


                   <div class="col-sm-6">
                  <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required">Country:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                    <select name="country_id" id="country_id" onchange="get_state(this.value);" class="form-control" >
                     <option value="0">Select Country</option>
               
                              <?php  
                                          foreach ($country as  $co) {
                                           if ($country_id == $co['country_id']) {?>
                                            <option value="<?php echo $co['country_id'];?>" selected><?php echo $co['country_name'] ; ?></option>
                                            <?php
                                           }else{?>
                                            <option value="<?php echo $co['country_id'];?>"><?php echo $co['country_name'] ; ?><?php 
                                          
                                          }
                                        }
                                        ?>
                                      
                    </select>  
                    <span id="country1" class="text-danger font-weight-bold"></span>
                   

                  </div>
                </div>

                </div> 

                <div class="col-sm-6">
                <div class="form-group" id="qc_name">
                  <label for="qc_name" class="col-sm-5 control-label required">State:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                  <select name="state_id" id="state_id" onchange="get_city(this.value);" class="form-control"  >
                   <option value="0" selected>Select State</option> 
                  <?php if ($this->uri->segment(3)){?> 
                    <option value="<?php echo $value['state_id'];?>" selected><?php echo $state_name;?></option>
                    <?php }?>

                    
                                    
                  </select>
                  <span id="state_id1" class="text-danger font-weight-bold"></span>                     
                  </div>                
                </div>
               </div>

         

              </div> <!-- col-ms-6 close -->

              <div class="col-sm-12">

              <div class="col-sm-6">
                
                <div class="form-group">
                  <label for="qc_name" class="col-sm-5 control-label required">City:<font style="color:red">*</font></label>
                  <div class="col-sm-7">                             
                  <select name="city_id" id="city_id" onChange="" class="form-control">
                   
                    <?php if ($this->uri->segment(3)){?> 
                    <option value="<?php echo $value['city_id'];?>" selected><?php echo $city_name?></option>
                  <?php } ?>
                  <option value="0" selected>Select City</option>
                </select> 
                <span id="city_id1" class="text-danger font-weight-bold"></span>                    
                  </div>
                </div>
                </div>

                <div class="col-sm-6">
                 <div class="form-group" >
                  <label for="pincode" class="col-sm-5 control-label required">Postal Code:<font style="color:red">*</font></label>
                  <div class="col-sm-7">
                                            
                  <input type="text" name="postalcode" value="<?php echo $postal_code;?>" id="postalcode" placeholder="Postal Code" class="form-control" maxlength="25"/>
                  <span id="postalcode1" class="text-danger font-weight-bold"></span>                       
                  </div>


                </div>

              </div>
            
          </div>
        </div>
      </div>
    </section>
    <div class="clearfix form-actions">
    <div class="col-md-offset-5 col-md-5">  
      <button class="btn btn-info" type="submit">
         Submit
      </button>
    </div>
  </div>
    </form>

             
            </div>
          </div>  
        </div>
      </div>
    </div>
    <!-- /.col -->
  </div>
  
  <div class="space-4"></div>
    <!-- /.page-row -->
        <!-- /.page-content --> 
    </div>
    <!-- /.main-content --> 
  </div>
    <!-- /#ace-settings-container --> 
  </div>
  <!-- /.main-container-inner --> 
<?php
  include('common/footer.php');
?>
<script>
function hide()
{
  document.getElementById("admin_type_code").style.display="none";
}
function show()
{
  document.getElementById("admin_type_code").style.display="";
}
</script>
<script type="text/javascript">
 
  $('#id-date-picker-2').datepicker({ dateFormat: 'dd-mm-yy' });
                 //format: 'MM/DD/YYYY h:mm:ss A',//use this option to display seconds
            
         
             
//  .next().on(ace.click_event, function(){
//                     $(this).prev().focus();
// });
</script> 
<script>
   $(document).ready(function(){
    $('#contactname1').hide();
    $('#mobilenumber1').hide();
    $('#design1').hide();
    $('#email1').hide();
    $('#cancel').hide(); 
             
    });

</script>
<script>
  $(document).ready(function(){
      $("#addmore").click(function(){
     $('#contactname1').show();
     $('#mobilenumber1').show();
      $('#design1').show();
     $('#email1').show();
     $('#addmore').hide(); 
     $('#cancel').show(); 
 });
       $("#cancel").click(function(){
     $('#contactname1').hide();
     $('#mobilenumber1').hide();
      $('#design1').hide();
     $('#email1').hide();
     $('#addmore').show(); 
     $('#cancel').hide(); 
 });
    });
  // function showcontact(){
  //      $('#contactname1,#mobilenumber1').show();
  //   }
</script>
<script>
  function get_state()
{
  var country_id = $('#country_id').val();
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/customer_master/get_state",
    method:"POST",
    data:{
      country_id:country_id
    },
    success:function(data)
    {
     $('#state_id').html(data);
    }
   });
}

function get_city()
{
  var state_id = $('#state_id').val();
  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/customer_master/get_city",
    method:"POST",
    data:{
      state_id:state_id
    },
    success:function(data)
    {
     $('#city_id').html(data);
    }
   });
}
</script>
<script type="text/javascript">

    function validateForm(){

       // var reg_gst ='/^([0-9]{2}[a-zA-Z]{4}([a-zA-Z]{1}|[0-9]{1})[0-9]{4}[a-zA-Z]{1}([a-zA-Z]|[0-9]){3}){0,15}$/';
       var reg_gst ='^([0][1-9]|[1-2][0-9]|[3][0-5])([a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9a-zA-Z]{1}[zZ]{1}[0-9a-zA-Z]{1})+$';

       var reg_pan = '^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$';
      
       
                                                                    
      var customer_name = document.getElementById('customer_name').value;
      var cutomer_pan = document.getElementById('cutomer_pan').value;
      var cutomer_gst = document.getElementById('cutomer_gst').value;
      var id_date = document.getElementById('id-date-picker-2').value;
      var contact_person_name = document.getElementById('contact_person_name').value;
      var cutomer_designation = document.getElementById('cutomer_designation').value;
      var cutomer_mobile  = document.getElementById('cutomer_mobile').value;
      var cutomer_email = document.getElementById('cutomer_email').value;
      var customer_addressl1 = document.getElementById('customer_addressl1').value;
      var country_id = document.getElementById('country_id').value;
      var state_id = document.getElementById('state_id').value;
      var city_id = document.getElementById('city_id').value;
      var postalcode = document.getElementById('postalcode').value; 
          
      if(customer_name == ""){
        document.getElementById('cutomer_name1').innerHTML =" ** Please fill the Customer Name field";
        return false;
      }else{
        document.getElementById('cutomer_name1').innerHTML ="";
      }
      if(!isNaN(customer_name)){
        document.getElementById('cutomer_name1').innerHTML =" ** only characters are allowed";
        return false;
      }else{
        document.getElementById('cutomer_name1').innerHTML ="";
      }
      
      if(cutomer_pan == ""){
        document.getElementById('cutomer_pan1').innerHTML =" ** Please fill the Customer Pan Number field";
        return false;
      }else{
        document.getElementById('cutomer_pan1').innerHTML ="";
      }
      if(!cutomer_pan.match(reg_pan)){
        document.getElementById('cutomer_pan1').innerHTML =" ** PAN number is not valid";
        return false;
      }else{
        document.getElementById('cutomer_pan1').innerHTML ="";
      }

      if(cutomer_gst == ""){
        document.getElementById('cutomer_gst1').innerHTML =" ** Please fill the GST Number field";
        return false;
      }else{
        document.getElementById('cutomer_gst1').innerHTML ="";
      }
      if(!cutomer_gst.match(reg_gst)){
        document.getElementById('cutomer_gst1').innerHTML =" ** GST number is not valid";
        return false;
      }else{
        document.getElementById('cutomer_gst1').innerHTML ="";
      }

      if(id_date == ""){
        document.getElementById('date1').innerHTML =" ** Please fill the Date field";
        return false;
      }else{
        document.getElementById('date1').innerHTML ="";
      }
      if(contact_person_name == ""){
        document.getElementById('contact_person_name1').innerHTML =" ** Please fill the Contact Person Name field";
        return false;
      }else{
        document.getElementById('contact_person_name1').innerHTML ="";
      }
      if(!isNaN(contact_person_name)){
        document.getElementById('contact_person_name1').innerHTML =" ** only characters are allowed";
        return false;
      }else{
        document.getElementById('contact_person_name1').innerHTML ="";
      }

      if(cutomer_designation == ""){
        document.getElementById('cutomer_designation1').innerHTML =" ** Please fill the Customer Designation field";
        return false;
      }else{
         document.getElementById('cutomer_designation1').innerHTML ="";
      }
      if(!isNaN(cutomer_designation)){
        document.getElementById('cutomer_designation1').innerHTML =" ** only characters are allowed";
        return false;
      }else{
         document.getElementById('cutomer_designation1').innerHTML ="";
      }

      if(cutomer_mobile == ""){
        document.getElementById('cutomer_mobile1').innerHTML =" ** Please fill the mobile Number field";
        return false;
      }else{
        document.getElementById('cutomer_mobile1').innerHTML ="";
      }
      if(isNaN(cutomer_mobile)){
        document.getElementById('cutomer_mobile1').innerHTML =" ** user must write digits only not characters";
        return false;
      }else{
        document.getElementById('cutomer_mobile1').innerHTML ="";
      }

      if(cutomer_mobile.length!=10){
        document.getElementById('cutomer_mobile1').innerHTML =" ** Mobile Number must be 10 digits only";
        return false;
      }else{
        document.getElementById('cutomer_mobile1').innerHTML ="";
      }

      if(cutomer_email == ""){
        document.getElementById('cutomer_email1').innerHTML =" ** Please fill the email id field";
        return false;
      }else{
         document.getElementById('cutomer_email1').innerHTML ="";
      }
      if(cutomer_email.indexOf('@') <= 0 ){
        document.getElementById('cutomer_email1').innerHTML =" ** @ Invalid Position";
        return false;
      }else{
         document.getElementById('cutomer_email1').innerHTML ="";
      }
      if((cutomer_email.charAt(cutomer_email.length-4)!='.') && (cutomer_email.charAt(cutomer_email.length-3)!='.')){
        document.getElementById('cutomer_email1').innerHTML =" ** . Invalid Position";
        return false;
      }else{
         document.getElementById('cutomer_email1').innerHTML ="";
      }

      if(customer_addressl1 == ""){
          document.getElementById('customer_addressl1_1').innerHTML =" ** Please fill the Address field";
         return false;
      }else{
        document.getElementById('customer_addressl1_1').innerHTML ="";
      }
      if(country_id =='0'){
        document.getElementById('country1').innerHTML =" ** Please Select Country Name field";
        return false;
      }else{
        document.getElementById('country1').innerHTML ="";
      }
      if(state_id =='0'){
        document.getElementById('state_id1').innerHTML =" ** Please Select State Name field";
        return false;
      }else{
        document.getElementById('state_id1').innerHTML ="";
      }
      if(city_id =='0'){
        document.getElementById('city_id1').innerHTML =" ** Please Select City Name field";
        return false;
      }else{
        document.getElementById('city_id1').innerHTML ="";
      }
      if(postalcode  == ""){
        document.getElementById('postalcode1').innerHTML =" ** Please fill the Postal Code field";
        return false;
      }else{
        document.getElementById('postalcode1').innerHTML ="";
      }
      if(isNaN(postalcode)){
        document.getElementById('postalcode1').innerHTML =" ** user must write digits only not characters";
        return false;
      }else{
        document.getElementById('postalcode1').innerHTML ="";
      }
     
  }
</script>
