<!DOCTYPE html>
<html>
<head>
<!-- TABLES CSS CODE -->
<?php include"comman/code_css_datatable.php"; ?>
<!-- bootstrap datepicker -->
<link rel="stylesheet" href="<?php echo $theme_link; ?>plugins/datepicker/datepicker3.css">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <!-- Left side column. contains the logo and sidebar -->
  
  <?php include"sidebar.php"; ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        <?=$page_title;?>
      </h1>
      <ol class="breadcrumb">
        <li><a href="<?php echo $base_url; ?>dashboard"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active"><?=$page_title;?></li>
      </ol>
    </section>

    <div class="pay_now_modal">
    </div>
    <div class="view_payments_modal">
    </div>

    <!-- Main content -->
    <?= form_open('#', array('class' => '', 'id' => 'table_form')); ?>
    <input type="hidden" id='base_url' value="<?=$base_url;?>">
    <section class="content">
      <!-- Small boxes (Stat box) -->
      <!-- /.row -->
      <div class="row">
        <!-- ********** ALERT MESSAGE START******* -->
        <?php include"comman/code_flashdata.php"; ?>
        <!-- ********** ALERT MESSAGE END******* -->
        
        <div class="col-xs-12">
          <div class="box">
            <div class="box-header with-border">
              
            </div>
            <!-- /.box-header -->
            <div class="box-body">
            <div class="row">
                <div class="col-xs-12">
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="formDate" class="col-sm-4 control-label">Form Date</label>
                        <div class="col-sm-8">
                            <input type="date" class="form-control" id="formDate" name="formDate" value="<?php $date = new DateTime("now", new DateTimeZone('Asia/Colombo')); echo $date->format('Y-m-d');?>">
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="toDate" class="col-sm-4 control-label">To Date</label>
                        <div class="col-sm-8">
                            <input type="date" class="form-control" id="toDate" name="toDate" value="<?php $date = new DateTime("now", new DateTimeZone('Asia/Colombo') ); echo $date->format('Y-m-d');?>">
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="fromSection" class="col-sm-4 control-label">From Section</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="fromSection" name="fromSection">
                                <?php
                                $sections_q = $this->db->query("SELECT section_id, section_name FROM db_section WHERE status=1");
                                foreach($sections_q->result() as $section){
                                    echo "<option value='{$section->section_id}'>{$section->section_name}</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>
                
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="toSection" class="col-sm-4 control-label">To Section</label>
                        <div class="col-sm-8">
                            <select class="form-control" id="toSection" name="toSection">
                                <?php
                                $sections_q = $this->db->query("SELECT section_id, section_name FROM db_section WHERE status=1 ORDER BY section_name DESC");
                                foreach($sections_q->result() as $section){
                                    echo "<option value='{$section->section_id}'>{$section->section_name}</option>";
                                }
                                ?>
                            </select>
                        </div>
                    </div>
                </div>
                </div>
              </div>
              <br>
              <table id="example2" class="table table-bordered table-striped" width="100%">
                <thead class="bg-primary ">
                <tr>
                  <th class="text-center">
                    #
                  </th>
                  <th>Item Name</th>
                  <th>QTY</th>
                  <th><?= $this->lang->line('created_by'); ?></th>
                  <th>Trasfer Date</th>
                </tr>
                </thead>
                <tbody>
				
                </tbody>
              </table>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
    <?= form_close();?>
  </div>
  <!-- /.content-wrapper -->
  <?php include"footer.php"; ?>
  <!-- Add the sidebar's background. This div must be placed
       immediately after the control sidebar -->
  <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<!-- SOUND CODE -->
<?php include"comman/code_js_sound.php"; ?>
<!-- TABLES CODE -->
<?php include"comman/code_js_datatable.php"; ?>
<!-- bootstrap datepicker -->
<script src="<?php echo $theme_link; ?>plugins/datepicker/bootstrap-datepicker.js"></script>
<script>
  $(document).ready(function() {
    $('#example2').DataTable({
      /* FOR EXPORT BUTTONS START*/
      dom:'<"row margin-bottom-12"<"col-sm-12"<"pull-left"l><"pull-right"fr><"pull-right margin-left-10 "B>>>tip',
      /* dom:'<"row"<"col-sm-12"<"pull-left"B><"pull-right">>> <"row margin-bottom-12"<"col-sm-12"<"pull-left"l><"pull-right"fr>>>tip',*/
      buttons: {
        buttons: [
            {
                className: 'btn bg-red color-palette btn-flat delete_btn pull-left',
                text: 'Delete',
                action: function ( e, dt, node, config ) {
                    multi_delete();
                }
            },
            { extend: 'copy', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4,5,6,7,8,9,10]} },
            { extend: 'excel', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4,5,6,7,8,9,10]} },
            { extend: 'pdf', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4,5,6,7,8,9,10]} },
            { extend: 'print', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4,5,6,7,8,9,10]} },
            { extend: 'csv', className: 'btn bg-teal color-palette btn-flat',exportOptions: { columns: [1,2,3,4,5,6,7,8,9,10]} },
            { extend: 'colvis', className: 'btn bg-teal color-palette btn-flat',text:'Columns' },  
        ]
      },
      "processing": true, //Feature control the processing indicator.
      "pageLength": 10,
      //"serverSide": true, //Feature control DataTables' server-side processing mode.
      "order": [], //Initial no order.
      "responsive": true,
      language: {
          processing: '<div class="text-primary bg-primary" style="position: relative;z-index:100;overflow: visible;">Processing...</div>'
      },
    });
    $('.deliver_chk').iCheck({
      checkboxClass: 'icheckbox_square-orange',
      /*uncheckedClass: 'bg-white',*/
      radioClass: 'iradio_square-orange',
      increaseArea: '10%' // optional
    });
         //call_code();
         //$(".delete_btn").hide();
  });
</script>

<script type="text/javascript">
$(document).ready(function() {
    //datatables
    fill_tbData();
});
$("#formDate,#toDate,#fromSection,#toSection").change(function(){
    //$('#example2').DataTable().destroy();
    fill_tbData();
});
</script>

<script>
  $(document).ready(function() {
    if(/Mobi/i.test(navigator.userAgent)) {
      fill_tbData_2();
      //alert("Mobile device detected");
    } else {
      document.onkeydown = fkey;
      document.onkeypress = fkey
      document.onkeyup = fkey;

      var wasPressed = false;

      function fkey(e){
              e = e || window.event;
            if( wasPressed ) return; 

            var userID = "<?php echo $this->session->userdata('inv_userid'); ?>";
            // if(userID=="1"||userID=="43"){

              if (e.keyCode == 113) {
                fill_tbData_2();
                  wasPressed = true;
              }else {
                fill_tbData();
              }
            // }
      }
    }
  });
</script>

<script>
  function fill_tbData(){
        var from_date    = $('#formDate').val();
        var to_date    = $('#toDate').val();
        var from_section = $('#fromSection').val();
        var to_section = $('#toSection').val();

      $.ajax({
        url:"<?php echo site_url('stock/trans_history_info_get')?>",
        type: 'post',
        data: {from_date:from_date,to_date:to_date, from_section:from_section, to_section:to_section},
        dataType: 'json',
        success: function (data) {

          var table;
          table = $('#example2').DataTable();
          
          table.clear();
            $.each(data.data_count_info, function(){
              var dataCount =parseInt(this['d_count']);
              //console.log(dataCount);
              if(dataCount>0) { 

                var indexNo = 1;
                $.each(data.stock_info, function(){
                  var s_id = this['id'];

                      table.row.add([indexNo,this['item_name'],this['stock_qty'],this['username'], this['added_date']]);
                      indexNo++;
                });
                table.draw();
                // table.processing(false);

              }else {
                  $('#example2').DataTable().destroy();
                toastr["warning"]("Something Wrong! , Data Not Found. ");
              }
            });
        },
        error: function (xhr, ajaxOptions, thrownError) {
          console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
      });
  }
</script>


<script src="<?php echo $theme_link; ?>js/sales.js"></script>
<script type="text/javascript">
  function print_invoice(id){
  window.open("<?= base_url();?>pos/print_invoice_pos/"+id, "_blank", "scrollbars=1,resizable=1,height=500,width=500");
}
</script>

<!-- Make sidebar menu hughlighter/selector -->
<script>$(".<?php echo basename(__FILE__,'.php');?>-active-li").addClass("active");</script>

<script>
  function checkAvailabilityChk() {
    var chequeNo    = $('#chequeNo').val();
      jQuery.ajax({
        url:"<?php echo site_url('sales/check_chkNo')?>",
        data:{chequeNo:chequeNo},
        type: "POST",
        success:function(data){
          var c_count = parseInt(data);
          if(c_count>0){
          $('#chequeNo').val("");
          $("#error_chk").html("This cheque no. already exists.");
          }else{
          $("#error_chk").html("");
          }
        },
        error:function (){}
    });
  }
</script>

</body>
</html>
