<?php
	include('common/header.php');
?>

<div class="row">
  <div class="col-xs-12"> 

                        <section class="panel panel-default">
                        
                              <header class="panel-heading bg-info lt font-bold"><?php echo 'Branch Details'; ?></header>
                              <div class="panel-body bs-example form-horizontal">
                                <form method="post" action="<?php echo base_url();?>index.php/<?php echo DISPENSER_SALES_DATA;?>transfer_to_branch"  onsubmit="return validateForm()">
                                  <input type="hidden" name="from_branch_hidden" value=" <?php echo $get_company_id;?>">
                    <div class="col-sm-12"> 
                      <div class="col-sm-6">
                            <div class="form-group" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo 'Transfer From Branch '; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7" style="padding: 4px;">
                                   <?php echo $get_company_name; ?>
                                  <span id="to_branch_name1" 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"><?php echo $lable_branch_To; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                    <select name="to_branch_name" id="to_branch_name">
                                  <option value="default">Select Transfer To Branch</option>                                                                  
                                          
                                  </select>
                                  <span id="to_branch_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" id="client_code">
                              <label for="client_code" class="col-sm-5 control-label required"><?php echo 'Comments'; ?>:<font style="color:red">*</font></label>
                              <div class="col-sm-7">
                                  <textarea class="form-control" rows="2" name="tranfer_comments" id="tranfer_comments" value=""></textarea> 
                                  
                              </div>
                               
                            </div>
                          </div>
                    </div>
                    
              </div>
   </section>
<!--  <div class="col-md-12"> -->

      <section class="panel panel-default">
        <div class="panel-body bs-example form-horizontal">
          <div class="table-responsive">
            <div class="table-header">
               Select Tracking numbers to transfer
          </div>
            <table id="example" class="table table-bordered dataTables" cellspacing="0" width="100%">
                <thead>
                            <tr>
                              <th class="text-center">Select</th>
                              <th class="text-center">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/dispenser_sale_data/fetch_dispenser_track/$query_id/$field_name/" .
                           (($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc') ,
            $field_display); ?>     </th>
          <?php endforeach; ?>
                              <!-- <th class="text-center">Customer Name</th>
                              <th class="text-center">Dispenser Name</th>
                              <th class="text-center">Sale Type</th>
                              <th class="text-center">Branch Name</th>
                              <th class="text-center">Sale Person Name</th>
                              <th class="text-center">Refill Date</th>
                              <th class="text-center">Next Refill Date</th> -->
                            <!--   <th class="text-center">Tracking Number</th> -->
                             
                            </tr>   
                </thead>
      <tbody>

         <?php 
       $icnt=0;
     $count=count($return);
     if ($count>0) {
       foreach ($return as  $value) {
         // $user_id = $value['user_id'];
             $tracking_numbers_id= $value->tracking_numbers_id;
             $customer_name=$value->customer_name;
             $dispenser=$value->dispenser;
             $sales_type=$value->sales_type;
             $company_branch_name=$value->company_branch_name;
             $user_name=$value->first_name." ".$value->last_name;
             $refill_date=$value->refill_date;
             $next_refill_date= $value->next_refill_date;
             $tracking_number=$value->tracking_number;
             $icnt++;
             $sr=$offset+$icnt;
       ?> 
                            
        <tr>
          <td><?php echo '<input type="checkbox" name="check_action[]" onclick="get_check_value();"value='.$tracking_numbers_id.'>';?></td>
          <td><?php echo $sr; ?></td>
          <!-- <td><?php echo $customer_name;?></td> -->
          <td><?php echo $tracking_number;?></td>
          <td><?php echo $dispenser;?></td>
          <td><?php echo $company_branch_name;?></td>                        
        </tr> 
        <?php 
       }
     }else{?>
            <td class="text-center" colspan="12"> no data available</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="dispensers";
              $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>
 <input type="hidden" name="hidden_transfer" id="dispenser_sales_id">
  <input type="hidden" name="from_branch" value="<?php echo $hidden_from_id; ?>" id="from_branch"> 
		<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/dispenser_sale_data/transfer_dispenser/<?php echo $get_company_id;?>'">
					Back
				</button>
        <button class="btn btn-info" type="submit">
         Transfer Dispenser
        </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>
  $(document).ready(function() {
    var from_branch=$("#from_branch").val(); 
    if (from_branch>0) {
      var f_branch = from_branch;
    }
    $.ajax({
    url:"<?php echo base_url();?>index.php/gc/dispenser_sale_data/branch_all",
    method:"POST",
    data:{
        from_branch:f_branch    
    },
    success:function(data)
    {
     $('#to_branch_name').html(data);
    }
   });

  
});

  function get_check_value(){
    var fav = [];
    $("input[name='check_action[]']:checked").each(function(){
      //$('#pc').show();
       fav.push($(this).val());

    });
    document.getElementById("dispenser_sales_id").value = fav;
    // console.log(fav);
  }
function validateForm(){
  var error=false;  
  var to_branch_name=$("#to_branch_name").val();  
  if(to_branch_name=='default')
  {
    $("#to_branch_name1").html("Please Select Branch Name");
    error=true; 
  }
  else
  {
    $('#to_branch_name1').html("");
      
  }
 
  if(error==true)
  {
    return false;
  }
  else
  {
 
      var r = confirm("Are you sure you want to Transfer Dispenser!");
      if (r==true) {return true;}else{return false;} 
    
  }


    }
</script>