<?php
	include('common/header.php');
?>
<div id="messages" style="color: green;"><h5><?php echo $this->session->flashdata('message'); ?></h5></div>
<div class="row">
  <section class="panel panel-default">
     <header class="panel-heading bg-info lt font-bold"><?php echo 'Search results'; ?></header>
    <form method="post" action="<?php echo base_url()?>index.php/<?php echo CUSTOMER_MASTER;?>search_customer">

    <div class="panel-body bs-example form-horizontal">
     <div class="col-sm-12" >  
                    <div class="col-sm-6">
                          <div class="form-group">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Branch Company Name'?>:</label>
                              <div class="col-sm-7">
                                 <select class="select2 select2-multiple form-control" name="branch_id"  id="branch_id" style="width: 250px;">
                                  <!-- <option>select company branch name</option>
                                  <?php if ($branch_id!='' ): ?>
                                    <option value="<?php  echo $branch_id ?>" selected><?php  echo $branch_name; ?></option>
                                  <?php endif ?> --> 
                                 </select>
                    
                              </div>  
                          </div>
                      </div>                                           
                          <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Customer Name'; ?>:</label>
                              <div class="col-sm-7">
                                  <input type="text" name="customer_name" onkeypress="return RestrictSpace()" value="<?php echo $customer_name; ?>" id="customer_name" placeholder="Customer Name" class="form-control" maxlength="75" />
                                
                              </div>
                            </div>
                          </div>

                        
        </div>
        <div class="col-sm-12">
                      <div class="col-sm-6">    
                           <div class="form-group" id="client_code">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Mobile No'; ?>:</label>
                              <div class="col-sm-7">   
                                <input type="text" name="cutomer_mobile" onkeypress="return RestrictSpace()" value="<?php echo $cutomer_mobile; ?>" id="cutomer_mobile" placeholder="Mobile Number" class="form-control" maxlength="10">
                                                                        
                              </div>   
                            </div>                         
                      </div>
                      <div class="col-sm-6">    
                       <div class="form-group">
                                <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Email Id'; ?>:</label>
                              <div class="col-sm-7">                             
                                <input type="text" name="cutomer_email" onkeypress="return RestrictSpace()" value="<?php echo $cutomer_email; ?>" id="cutomer_email" placeholder="Email Id" class="form-control" maxlength="75" />                                        
                              </div>
                       </div>                            
                     </div>
        </div>
         <div class="col-sm-12">
                      <div class="col-sm-6">    
                           <div class="form-group" id="client_code">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Address'; ?>:</label>
                              <div class="col-sm-7">   
                                <input type="text" name="cutomer_address" onkeypress="return RestrictSpace()" value="<?php echo $cutomer_address; ?>" id="cutomer_mobile" placeholder="Address" class="form-control" maxlength="200">
                                                                        
                              </div>   
                            </div>                         
                      </div>
                      <div class="col-sm-6">    
                       <div class="form-group">
                                <label for="client_code" class="col-sm-3 control-label required"><?php echo 'City'; ?>:</label>
                              <div class="col-sm-7">                             
                                <input type="text" name="cutomer_city" onkeypress="return RestrictSpace()" value="<?php echo $cutomer_city; ?>" id="cutomer_city" placeholder="City" class="form-control" maxlength="75" />                                        
                              </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-3 control-label required"><?php echo 'Sale Person Name'; ?>:</label>
                                <div class="col-sm-7">
                                 
                                <input type="text" name="cutomer_sale_person" onkeypress="return RestrictSpace()" value="<?php echo $cutomer_sale_person; ?>" id="cutomer_sale_person" placeholder="Sale Person Name" class="form-control" maxlength="75" /> 
                                  
                                 </div>
                              
                            </div>
                          </div> 

                           <div class="col-sm-6">
                          <div class="form-group">
                            <label for="client_code" class="col-sm-3 control-label required"><?php echo 'Sales Status'?>:</label>
                              <div class="col-sm-7">
                                 <select name="sale_status_id"  id="sale_status" style="width: 250px;">
                                    <option>Select Sales Status</option>
                                      <option value="1" <?php if ($sale_status_id=='1') {
                                        echo 'selected="selected"';
                                      } ?>>pre_sales</option> 
                                      <option value="2" <?php if ($sale_status_id=='2') {
                                        echo 'selected="selected"';
                                      } ?> >won</option>
                                 </select>
                    
                              </div>  
                          </div>
                      </div>   

        </div>

    </div>
    <div class="clearfix form-actions">
      <div class="col-md-offset-5 col-md-5">
        <button class="btn btn-info" type="submit" value="search" name="search">
         Search
        </button>
      </div>
    </div>
</form>
  </section>
</div>
<div class="row">
 <div class="col-xs-12">
      <section class="panel panel-default">
     <form method="post" action="<?php echo base_url();?>index.php/gc/customer_master/excel_list">
      <input type="hidden" name="excel" value="1"> 
      <input type="hidden" name="excel_cutomer_sale_person" value="<?php echo $excel_cutomer_sale_person; ?>">
      <input type="hidden" name="excel_customer_name" value="<?php  echo $excel_customer_name; ?>">

      <input type="hidden" name="excel_cutomer_mobile" value="<?php   echo $excel_cutomer_mobile; ?>">

      <input type="hidden" name="excel_cutomer_email" value="<?php  echo $excel_cutomer_email; ?>">
      <input type="hidden" name="excel_cutomer_address" value="<?php  echo $excel_cutomer_address; ?>">

      <input type="hidden" name="excel_cutomer_city" value="<?php echo $excel_cutomer_city; ?>">
      <input type="hidden" name="excel_branch_id" value="<?php  echo $excel_branch_id; ?>">
      <input type="hidden" name="excel_sale_status_id" value="<?php  echo $excel_sale_status_id; ?>">
      <div class="panel-body bs-example form-horizontal">
      <div class="table-responsive">
            <table id="example" class="table table-bordered dataTables" cellspacing="0" width="100%">
              <thead>
        <tr>
          <th>Sr No</th>
		   <?php foreach($fields as $field_name => $field_display): ?>
						<th <?php if ($sort_by == $field_name) echo "class=\"sorting_$sort_order\"" ?>>
						<?php echo anchor("gc/customer_master/list_customer_master/$query_id/$field_name/" .
						(($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc') ,
						$field_display); ?>			</th>
					<?php endforeach; ?>
		     
          <th>Action</th>
        </tr> 
      </thead>
      <tbody>  
       <?php 
     $icnt=0;
     $count=count($customer);
     if ($count>0) {
     foreach ($customer as  $value) {
		 $customer_id=$value->customer_id;		 
         $id=$this->encrypt->encode($customer_id);
         $customer_name=$value->customer_name;
         $company_branch_name=$value->company_branch_name;
         $city_name=$value->city_name;
         $email_id=$value->email_id;
         $date_of_enrollment=$value->date_of_enrollment;
         $is_active=$value->is_active;
         $contact_person_name=$value->contact_person_name;
         $first_name=$value->first_name;
         $address_line1=$value->address_line1;
         $address_line2=$value->address_line2;
         $postal_code=$value->postal_code;
         $mobile_no=$value->mobile_no;
         $sales_status=$value->sales_status;
         $icnt++;
        $sr=$offset+$icnt;
       ?>     
        <tr>
          <td><?php echo $sr; ?></td>
		      <td><?php echo $company_branch_name;?></td> 
          <td><?php echo $customer_name;?></td>  
          <td><?php echo $contact_person_name;?></td>
          <td><?php echo $first_name;?></td>
          <td><?php echo $city_name;?></td>
          <td><?php echo $address_line1." ".$address_line2;?></td>
          <td><?php echo $postal_code;?></td>
          <td><?php echo $mobile_no;?></td>
          <td><?php echo $email_id;?></td>
          <td><?php echo $date_of_enrollment;?></td>
          <td><?php echo $sales_status;?></td>
         <td>
            <b><a href="<?php echo base_url();?>index.php/gc/customer_master/view_customer_master/<?php echo $id?>">View</a> | <a href="<?php echo base_url();?>index.php/gc/customer_master/manage_customer_master/<?php echo $id ?>"> Edit |
             <?php if($is_active==0) {?>
                 <a href="<?php echo base_url();?>index.php/gc/customer_master/enable_customer_master/<?php echo $id ?>">Enable</a></b><?php }else{?>
                 <a href="<?php echo base_url();?>index.php/gc/customer_master/disable_customer_master/<?php echo $id ?> " onclick="return confirm('Are you sure you want to Disable?')">Disable</a></b><?php } ?>
				| <b><a href="<?php echo base_url();?>index.php/gc/master_sale_data_report/master_sales_data_report_list/0/dispenser_sales_id/asc/0/0/<?php echo $id ?>">Sales Report</a></b>
          </td>
        </tr> 
        <?php 
        // $srno=$srno+1;
       }
         }else{?>
                    <td colspan="14" class="text-center">no data found</td>
         <?php } ?>
        
        </tbody>
            </table>
          </div>
           <?php
     if($num_results > 0) { ?>
      <div class="block"> </div>
        <div class="clearfix">
        <div class="row">
          <?php 
            if (strlen($pagination)): 
              $label_disp="Customer";
              $data['label_disp']=$label_disp;
              $data['count']=$count;
              $this->load->view('pagination_view.php',$data);
            endif; ?>
            </div>
        </div>
          <div class="block"> </div>
      <?php } ?>
   <!--   </div> -->
      </section>

		<div class="clearfix form-actions">
			<div class="col-md-offset-5 col-md-5">
				<button class="btn btn-info" type="button" onclick="javascript:window.location='<?php echo base_url();?>index.php/gc/customer_master/manage_customer_master'">
					Add Customer 
				</button>
        <button class="btn btn-info" type="submit" value="excel_search" name="excel_search">
         Export to Excel
        </button>
			</div>
		</div>
    </form>
	</div>
</div>
<div>
	<!-- /.page-row -->
    <!-- /.page-content --> 
</div>
<!-- /.main-content --> 
</div>
<!-- /#ace-settings-container --> 
</div>
<!-- /.main-container-inner -->
<?php
	include('common/footer.php');
?>
<script type="text/javascript">
$(document).ready(function() {
   /*  $('#example').DataTable( {
    destroy: true,
    searching: false,
    paging: false,
    sorting:false,
    bInfo : false,
    "order": [],
    "columnDefs": [
      { "orderable": false, "targets":  [3] }
      ]
  } ); */
});
</script> 
<script>
  $(document).ready(function(){

  $("#contract_div").hide();
  $("#del").hide();
  $(".js-example-tags").select2({
  tags: true
  });

  $(".select2").select2();  
  $(".select2").prop("multiple", "");

   $("#branch_id").select2({
     tags: true,
    multiple: false,
    //tokenSeparators: [',', ' '],
    minimumInputLength: 3,
    minimumResultsForSearch: 10, 
    ajax: {
      url: '<?php echo base_url();?>index.php/gc/customer_master/branch',
      dataType: "json",
      type: "POST",
      data: function (params) {

        var queryParameters = {
          customer_id: params.term
        }
        return queryParameters;
      },
      processResults: function (data) {
        return {
          results: data
        };
      }
    }
  });



});
</script>