@extends('adminlte::page') @section('content')
@include('administrator.construction.warehouse.create')
@include('administrator.construction.warehouse.edit')
<?php Fun::lang()?>
<div class="title-page">
    <div class="page-bar">
        <ul class="page-breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li><a href="#">Construction</a></li>
            <li><a href="#">Set Up Information</a></li>
            <li><a href="#">Warehouse</a></li>
        </ul>
    </div>
</div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-page">
                        <div class="pull-left">
                            <h3>Warehouse List</h3>
                        </div>
                    </div>
                    <div class="pull-right">
                        <a class="button_sm button_info" href="javascript:void(0)" id="filter-toggle-search"><span class="fa fa-plus"></span>  Filter Toggle</a>
                        @can('Construction-Warehouse-Create')
                            <a class="button_sm button_primary" href="#form-modal-create-warehouse" data-toggle="modal"><span class="fa fa-plus"></span>  Create New</a>
                        @endcan
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body table-responsive">
            <div class="row" id="toggle-seaching">
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Name :</strong>
                        {!! Form::text('warehouse_name',null, array('class' => 'form-control')) !!}
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-group">
                        <strong >Project :</strong>
                        {!! Form::select('project',$projects,null, array('class' => 'form-control select2')) !!}
                    </div>
                </div>
                <div class="col-md-12" style="text-align:right;margin-bottom:40px !important;">
                    <a class="button_sm button_success" href="javascript:void(0)" id="search-submit" onclick="searching()"><span class="fa fa-search"></span> Search</a>
                </div>
            </div>      
            <table id="datatable_warehouse" width="100%" class="table table-striped table-bordered table-hover nowrap">
                <thead>
                    <tr>
                        <th>NO</th>
                        <th>Name</th>
                        <th>Project</th>
                        <th>Description</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                   
                </tbody>
            </table>

        </div>
    </div>
    @endsection
    @section('js')
    <script type="text/javascript">
            function edit(id)
            {
                $("#main-spinner").show();
                var route = "{{route('warehouse-construction.get_for_edit',':id')}}";
                route = route.replace(":id",id);
                $.ajax({
                    url:route,
                    type:"GET",
                    dataType:"JSON",
                    success:function(data){
                        $("#main-spinner").hide();
                        $("#form-modal-edit-warehouse").modal('show');
                        $("#warehouse-id").val(id);
                        $("#warehouse-name").val(data['warehouse'].name);
                        $("#warehouse-description").val(data['warehouse'].description);
                        $("#warehouse-project_id").empty();
                        $("#warehouse-project_id").append(`<option value="">Please Select</option>`);
                        $.each(data['projects'],function(index,value)
                        {
                            if(value.id==data['warehouse'].project_id){
                                $("#warehouse-project_id").append(`<option value="${value.id}" selected>${value.project_name}</option>`);
                            }
                            else{
                                $("#warehouse-project_id").append(`<option value="${value.id}" selected>${value.project_name}</option>`);
                            }
                        });
                    }
                });
            }
            $(document).ready(function() {
                $('#main-spinner').show();
                var table = $('#datatable_warehouse').DataTable({
                    ordering: false,
                    "serverSide": true,
                    "scrollY":"600px",
                    "scrollCollapse": true,
                    "lengthMenu": [
                    [20, 25, 50, 100, 500],
                    [20, 25, 50, 100, 500]
                ],
                    ajax:{
                        url:"{{ route('warehouse-construction.get_data_index') }}",
                        type:"GET",
                        data:function(d){
                            var warehouse_name = $("input[name=warehouse_name]").val();
                            var project = $("select[name=project]").val();
                            d.warehouse_name = warehouse_name;
                            d.project = project;
                        }
                    },
                    columns: [
                    {
                        data: 'DT_RowIndex'
                    }, {
                        data: 'name'
                    }, {
                        data: 'project_name'
                    }
                    ,{
                        data: 'description'
                    }
                    , {
                        data: 'action'
                    }, ],
                    "initComplete": function(settings, json) {
                        $('#main-spinner').hide();
                    }
                });

                $.fn.dataTable.ext.errMode = 'throw';
            });
            function searching(){
                $('#datatable_warehouse').DataTable().draw(true);
            }
    </script>
    
    @endsection