    <?php
        $this->load->view('admin/master/header_2');
        $modul=$this->uri->segment(3);
        $menuid=$this->uri->segment(4);
        $id_category=$this->uri->segment(5);
        $code=$this->uri->segment(6);

        $get_name_category=$this->master_model->select_in('ms_inventory_category','name',"WHERE ID=$id_category");


        setlocale(LC_ALL, 'id_ID.UTF-8');
    ?>

    <script>
        $(document).ready(function(e)
        {
            $(".edit").click(function(){
                 var ID = $(this).attr("alt");
                   // alert(id_customer);
                  $.ajax({
                     type: "POST",
                     dataType: "html",
                     url: "<?php echo base_url();?>admin/master/edit_inventory/<?php echo $menuid;?>",
                     data:"ID="+ID,
                     success: function(msg){
                          $(".content-edit").html(msg);
                     }
                  });
            });
        });
    </script>

<div class="content-wrapper">
    <section class="content-header">
        <h1>Details Inventory Log
            <small>Control panel</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="<?php echo base_url();?>admin/home/index/8"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="<?php echo base_url();?>admin/master/inventory_category/<?php echo $menuid;?>">Inventory Category</a></li>
            <li><a href=""><?php echo $get_name_category[0]->name;?></a></li>
            <li class="active">Detail</li>
        </ol>
    </section>
    <section class="content">
        <?php echo $this->session->flashdata('message') ?>
        <?php echo $this->session->flashdata('mdt') ?>
        <div class="row">
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">Filter</h3>
                            <hr>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                            </div>
                            <form action="<?php echo site_url('admin/master/inventory_detail_stock_bal_search/'.$menuid.''); ?>" method="POST">
                                <div class="col-md-4">
                                    <label>DATE START</label>
                                    <div class="form-group">
                                        <div class="form-line">
                                            <input
                                            type="date"
                                            class="form-control date_from"
                                            name="date_start"
                                            value="<?php echo $date_from; ?>"
                                            />
                                        </div>
                                    </div>  
                                </div>
                                <div class="col-md-4">
                                    <label>DATE END</label>
                                    <div class="form-group">
                                        <div class="form-line">
                                            <input
                                            type="date"
                                            class="form-control date_to"
                                            name="date_end"
                                            value="<?php echo $date_to; ?>"
                                            />
                                        </div>
                                    </div>  
                                </div>
                                <div class="col-md-4">
                                    <label>INVENTORY</label>
                                    <div class="form-group">
                                        <div class="form-line">
                                            <select name="catergory" class="form-control ab" required>
                                                <option value="">Choose Inventory</option>
                                                <?php
                                                    $inventory=$this->master_model->mst_data('ms_inventory');
                                                    
                                                    for($a=0; $a < count($inventory); $a++)
                                                    {
                                                        $ID=$inventory[$a]->ID;
                                                        if($id_inventory==$ID)
                                                        {
                                                            $select='selected="selected"';
                                                        }else
                                                        {
                                                            $select='';
                                                        }
                                                        echo'
                                                            <option value="'.$ID.'" '.$select.'>
                                                                '.$inventory[$a]->name.'
                                                            </option>
                                                        ';
                                                    }
                                                ?>
                                            </select>
                                        </div>
                                    </div>  
                                </div>
                                
                                <div class="col-md-12">
                                    <label></label>
                                    <div class="form-group">
                                      <button type="submit" class="btn btn-primary waves-effect">SEARCH</button>
                                      <a class="btn btn-success export_purchase" style="cursor: pointer">
                                            Export to excel
                                        </a>
                                        <script>
                                            $(document).on('click', '.export_purchase', function(){
                                                var date_from = $('.date_from').val();
                                                
                                                var date_to   = $('.date_to').val();
                                                var status    = $('.ab').val();
                                                // alert(status);
                                                window.location.assign("<?php echo base_url();?>admin/transaction/export_inventory_detail_used/<?php echo $menuid;?>/"+date_from+"/"+date_to+"/"+status+"");
                                            });
                                        </script>
                                    </div>  
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-md-12">
                <div class="box box-primary">
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <hr>
                            <div class="box-tools pull-right">
                                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-remove"></i></button>
                            </div>
                            <div class="box-body response-qty">
                                <table class="table table-bordered table-striped" id="table">
                                    <thead>
                                        <tr>
                                            <th>NO</th>
                                            <th>TYPE</th>
                                            <th>NO TRANSAKSI</th>
                                            <th>DATE</th>
                                            <th>QTY IN</th>
                                            <th>QTY OUT</th>
                                            <th>QTY RETURN</th>
                                            <!-- <th>DELTA</th> -->
                                            <th>STOCK BALANCE</th>
                                            
                                        </tr>
                                    </thead>
                                    <tbody class="get_customer">

                                        <?php

                                          for($a=0; $a < count($data_inventory_used); $a++)

                                          {

                                              $b=$a+1;

                                              $ID = $data_inventory_used[$a]->ID;

                                        ?>

                                        <tr>

                                            <td>

                                                <?php

                                                    echo $b;

                                                ?>

                                            </td>
                                            <td>
                                                <?php if($data_inventory_used[$a]->type == 0): ?>
                                                    <?php echo "STOCK IN"; ?>
                                                <?php elseif($data_inventory_used[$a]->type == 1): ?>
                                                    <?php echo "PRODUCTION"; ?>
                                                <?php elseif($data_inventory_used[$a]->type == 2): ?>
                                                    <?php echo "MOVE"; ?>
                                                <?php elseif($data_inventory_used[$a]->type == 3): ?>
                                                    <?php echo "RETURN"; ?>
                                                <?php else: ?>
                                                    <?php echo "OPNAME"; ?>
                                                <?php endif ?>
                                            </td>
                                            <td>
                                                <?php if($data_inventory_used[$a]->type == 0): ?>
                                                    <a href="<?php echo base_url(); ?>admin/transaction/stock_in_view/<?php echo $menuid.'/'.$data_inventory_used[$a]->id_stock_detail.'/'.$data_inventory_used[$a]->id_inventory.'';?>">
                                                    <?php echo $data_inventory_used[$a]->stock_no; ?></a>
                                                <?php elseif($data_inventory_used[$a]->type == 1): ?>
                                                    <a href="<?php echo base_url(); ?>admin/transaction/purchase_production_view/<?php echo $menuid.'/'.$data_inventory_used[$a]->stock_out_id.'/'.$data_inventory_used[$a]->id_inventory.'';?>">
                                                    <?php echo $data_inventory_used[$a]->workorder_no; ?></a>
                                                <?php elseif($data_inventory_used[$a]->type == 3): ?>
                                                    <a href="<?php echo base_url(); ?>admin/transaction/purchase_return_view/<?php echo $menuid.'/'.$data_inventory_used[$a]->stock_retur_id.'/'.$data_inventory_used[$a]->id_inventory.'';?>">
                                                    <?php echo $data_inventory_used[$a]->purchase_return; ?></a>
                                                <?php endif ?>
                                            </td>
                                            <td><?php echo date('d M Y', strtotime($data_inventory_used[$a]->tanggal));?>
                                            </td>
                                            <td style="text-align: right;">
                                                <?php echo number_format($data_inventory_used[$a]->qty_in); ?>
                                            </td>
                                            <td style="text-align: right;">
                                                <?php echo number_format($data_inventory_used[$a]->qty_out); ?>
                                            </td>
                                            <td style="text-align: right;">
                                                <?php echo number_format($data_inventory_used[$a]->qty_ret); ?>
                                            </td>
                                            <!-- <td style="text-align: right;">
                                                <?php echo $data_inventory_used[$a]->qty_delta; ?>
                                            </td> -->
                                            <td style="text-align: right;">
                                                <?php echo number_format($data_inventory_used[$a]->qty_bal); ?>
                                            </td>
                                        </tr>

                                        <?php } ?>

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>    
<script>
  $(function () {
    $("#table").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
</script> 
<?php $this->load->view('admin/master/footer_2');?>