<?php
  include('common/header.php');
  
?>
<style>
/* Popup box BEGIN */
.hover_bkgr_fricc{
    background:rgba(0,0,0,.4);
    cursor:pointer;
    display:none;
    height:100%;
    position:fixed;
    text-align:center;
    top:0;
    width:100%;
    z-index:10000;
}
.hover_bkgr_fricc .helper{
    display:inline-block;
    height:100%;
    vertical-align:middle;
}
.hover_bkgr_fricc > div {
    background-color: #fff;
    box-shadow: 10px 10px 60px #555;
    display: inline-block;
    height: auto;
    max-width: 551px;
    min-height: 100px;
    vertical-align: middle;
    width: 60%;
    position: relative;
    border-radius: 8px;
    padding: 15px 5%;
}
.popupCloseButton {
    background-color: #fff;
    border: 3px solid #999;
    border-radius: 50px;
    cursor: pointer;
    display: inline-block;
    font-family: arial;
    font-weight: bold;
    position: absolute;
    top: -20px;
    right: -20px;
    font-size: 25px;
    line-height: 30px;
    width: 30px;
    height: 30px;
    text-align: center;
}
.popupCloseButton:hover {
    background-color: #ccc;
}
.trigger_popup_fricc {
    cursor: pointer;
    font-size: 13px;
    margin: 20px;
    display: inline-block;
    font-weight: bold;
}
/* Popup box BEGIN */
</style>
<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 PRODUCTS;?>search_product">

    <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 'Product Type'?>:</label>
                              <div class="col-sm-7">
                                 <select name="product_type"  id="product_type"  onchange="get_cateogry(this.value);" style="width: 250px;">
                                    <option value="default">Select Product Type</option>
                                      <option value="1" <?php if ($product_type=='1') {
                                        echo 'selected="selected"';
                                      } ?>>Dispenser</option> 
                                      <option value="2" <?php if ($product_type=='2') {
                                        echo 'selected="selected"';
                                      } ?> >Refill</option>                                    
                                 </select>
                    
                              </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 'Product Category'?>:</label>
                              <div class="col-sm-7">
                                 <select name="product_category_type" id="product_category_type"  style="width: 250px;">
                                    <option>Select Product Category</option>
                                                                        
                                 </select>
                    
                              </div>  
                          </div>
                      </div>
      </div>
      <input type="hidden" name="product_category_type_id" value="<?php echo $product_category_type; ?>" id="product_category_type_id">
      <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 'Product Name'?>:</label>
                              <div class="col-sm-7">
                                <input type="text" name="product_name" onkeypress="return RestrictSpace()" value="<?php echo $product_name; ?>" id="product_name" placeholder="Product Name" class="form-control" maxlength="75" /> 
                    
                              </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">
        
        <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/products/list_products/$query_id/$field_name/" .
            (($sort_order == 'asc' && $sort_by == $field_name) ? 'desc' : 'asc') ,
            $field_display); ?>     </th>
          <?php endforeach; ?>
          <!-- <th>Product Type</th>
          <th>Product Category</th>
          <th>Product Name</th>
          <th>Quantity in Hand</th>         
          <th>price</th> -->
          <th>Action</th>
        </tr>
      </thead>

     <tbody>
          <?php 
        $icnt=0;
      $count=count($product); 
      if ($count>0) {      
     foreach ($product as  $value) {
           $product_id = $value->product_id;
           $id=$this->encrypt->encode($product_id);
           $stock_quantity=$value->stock_quantity;
           $product_type=$value->product_type;
           $product_category_name=$value->product_category_name;
           $product_name=$value->product_name;
           $price=$value->price;
           $is_active=$value->is_active;
           $icnt++;
           $sr=$offset+$icnt;  

       ?> 
        <tr>
          <td><?php echo $sr; ?></td>
          <td><?php echo $product_type;?></td> 
          <?php if ($product_category_name=="") {?>
           <td><?php echo '-';?></td> <?php }else{?> 
          <td><?php echo $product_category_name;?></td> <?php } ?>
          <td><?php echo $product_name;?></td> 
          <td><?php echo $stock_quantity;?></td> 
          <td><?php echo $price;?></td> 
          <td>
            <b><a href="<?php echo base_url();?>index.php/gc/products/view_products/<?php echo $id?>"><?php if ($product_type=='Dispenser') {?>View Refill<?php }elseif ($product_type=='Refill') {?>View Dispenser <?php }else{?>View <?php } ?></a> | <a href="<?php echo base_url();?>index.php/gc/products/manage_products/<?php echo $id ?>"> Edit |
             <?php if($is_active==0) {?>
                 <a href="<?php echo base_url();?>index.php/gc/products/enable_products/<?php echo $id ?>">Enable</a></b><?php }else{?>
                 <a href="<?php echo base_url();?>index.php/gc/products/disable_products/<?php echo $id ?> " onclick="return confirm('Are you sure you want to Disable?')">Disable</a></b><?php } ?>   |<a  onclick="quantityid('<?php echo $id?>','<?php echo $stock_quantity; ?>')"class="trigger_popup_fricc">Add Quantity</a>
               
                 

          </td>
        </tr>

    <?php 
        // $srno=$srno+1;
       }
         }else{?>
              <td colspan="7" class="text-center">no data found</td>
         <?php } ?>
        </tbody>
            </table>
         </div>
          <div>
           <?php
     if($num_results > 0) { ?>
      <div class="block"> </div>
        <div class="clearfix">
        <div class="row">
          <?php 
            if (strlen($pagination)): 
              $label_disp="Products";
              $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/products/manage_products'">
          Add Product
        </button>
      </div>
    </div>

     <div class="hover_bkgr_fricc">
    <span class="helper"></span>
    <div>
        <div class="popupCloseButton">X</div>
        <form method="post" action="<?php echo base_url();?>index.php/gc/products/quantity" onsubmit="return validateForm();">
          <section class="panel panel-default">
            <header class="panel-heading bg-info lt font-bold"><?php echo 'Add Quantity'; ?></header>
         
          <input type="hidden" name="stock_add_quanity" id="stock_add_quanity" >
          <input type="hidden" name="update_id_quanity" id="update_id_quanity" >
         <br>
         <span>Add Quantity: </span><input type="text" name="update_quantity" id="update_quantity" placeholder="Add Quantity"><br>
         <span id="update_quantity1" class="text-danger font-weight-bold"></span> 
          <br>
         <br>
         <span>Start Number: </span><input type="text" name="start_number" id="start_number" placeholder="Start Number"><br>
         <span id="start_number1" class="text-danger font-weight-bold"></span> <br>
         <br>
         <span>Branch Name: </span><select name="branch" id="branch" required>
            <option value="default">Select Branch Name</option>
                <?php 
                foreach($branch as $value1) 
                  { ?>
                <option value="<?php echo $value1['company_branch_id']; ?>"><?php echo $value1['company_branch_name'] ; ?></option>
                <?php
              }
              ?>
              </select> <br>
              <br>
          <input type="submit" name="submit">
         </section>
        </form>
    </div>
</div>


  </div>
</div>

<!-- /.main-content --> 
<!-- </div> -->
<!-- /#ace-settings-container --> 
<!-- </div> -->
<!-- /.main-container-inner -->

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

<!-- <script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#example').DataTable();
    $('#myForm').hide();
  } );
</script> -->
<!-- <script type="text/javascript">
$(document).ready(function() {
    $('#example').DataTable( {
    destroy: true,
    searching: false,
    paging: false,
    sorting:true,
    bInfo : false,
    "order": [],
    "columnDefs": [
      { "orderable": false, "targets":  [3] }
      ]
  } );
});
</script>  --> 


<script>
 var product_category_type_id = $('#product_category_type_id').val();
 var product_type2 = $('#product_type').val();
     //var country_id = $('#country_id').val();
    if (product_category_type_id=='default' || product_category_type_id>0 || product_type2>0) {
      get_cateogry();
    }

  function get_cateogry(){
  //var fetched_state = $('#fetched_state').val();

  var product_type1 = $('#product_type').val();
  var product_category_type_id = $('#product_category_type_id').val();
  if (product_category_type_id > 0) {
    var product_category_type_ids =product_category_type_id;
  }

  $.ajax({
    url:"<?php echo base_url();?>index.php/gc/products/fetch_cateogory_types",
    method:"POST",
    data:{
        cateogory_type:product_type1,
        product_category_type:product_category_type_ids
    },
    success:function(data)
    {
     $('#product_category_type').html(data);
    }
  });

  // });
}

  
  function quantityid(id,stock_quantity){
     $('#update_quantity1').hide(); 
 $('#start_number1').hide(); 
      $('#update_id_quanity').val(id);
      $('#stock_add_quanity').val(stock_quantity);
       $('.hover_bkgr_fricc').show();
 
    $('.popupCloseButton').click(function(){
        $('.hover_bkgr_fricc').hide();
    });
}

function validateForm(){
var error=false; 
  var update_quantity=$("#update_quantity").val();  
  if(update_quantity=='')
  {
    $("#update_quantity1").html("Please Enter Quantity");
    $('#update_quantity1').show(); 
    error=true; 
  }
  else
  {

    $('#update_quantity1').html("");
      
  }

  var start_number=$("#start_number").val();  
  if(start_number=='')
  {
    $("#start_number1").html("Please Enter Start Number");
    $('#start_number1').show(); 
    error=true; 
  }
  else
  {
    $('#start_number1').html("");
      
  }
  // var branch=$("#branch").val();  
  // if(branch=='default')
  // {
  //   $("#branch1").html("Please Select Start Number");
  //   error=true; 
  // }
  // else
  // {
  //   $('#branch1').html("");
      
  // }

  
  if(error==true)
  {
    return false;
  }
  else
  {
      var r = confirm("Are you sure you want to Add Quantity!");
      if (r==true) {return true;}else{return false;} 
    
  }

 
     
}
</script>