@extends('layouts.dashboard')

@section('page_title')
	Manage {{ucwords(str_replace('_',' ',$plot_labels['module']))}}
@endsection

@section('page_header_title')
	Manage Inventory
@endsection


@section('page_body')
{{ Breadcrumbs::render('plot') }}


	<div class="row row-cards row-deck">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
              <div class="col-sm-6 col-md-3">
             
               @if(Auth::user()->hasAnyPermission(['All','Store Inventory']))

               <button  class="float-left btn btn-sm btn-outline-primary" data-toggle="modal" data-target="#md_add_inventory" ><i class="fa fa-plus"></i>Add {{ucwords(str_replace('_',' ',$plot_labels['module']))}}</button>

          
               @endif

                @if(Auth::user()->hasAnyPermission(['All','Update Inventory Bulk']))

                 <button    class="float-left btn btn-sm btn-outline-primary ml-3" data-toggle="modal" data-target="#md_update_bulk" ><i class="fas fa-edit"></i> Bulk Update</button> 

               @endif
              </div>
         
              <div class="col-md-3"></div>
               <div class="col-md-3">
                @php($datatable_key = Crypt::encrypt('Plot'))
                
                <select onchange="renderPlotsTable(), showBlocksInDropDown(event,this,'{{$datatable_key}}','block_drop_down')" name="branch" class="form-control form-control-sm float-right branch_list">
                  <option value="{{Crypt::encrypt(0)}}">Select {{ucwords(str_replace('_',' ',EF::branchWhiteLabel()['module']))}}</option>

                  @foreach($branch as $rows)
                    <option value="{{Crypt::encrypt($rows->id)}}">{{$rows->name}} ({{$rows->code}})</option>
                  @endforeach
                </select>
              </div>

              <div class="col-md-3">
                    {{-- @php($datatable_key = Crypt::encrypt('BlockWisePlots')) --}}
                    <select name="block" class="form-control form-control-sm float-right block_drop_down block" onchange="renderPlotsTable();">
                      <option value="{{Crypt::encrypt(0)}}">Select Block</option>
                    </select>
                </div>

            </div>

                	<div class="card-status card-status-left bg-blue"></div>
                  <div class="table-responsive table-height">
                    <table id="plots_table" class="table table-hover table-outline table-vcenter text-nowrap card-table cls_datatable">
                      <thead>
                        <tr>
                          
                          <th>#</th>

                        <th>{{ucwords(str_replace('_',' ',$plot_labels['branch']))}} </th>

                       <th>{{ucwords(str_replace('_',' ',$plot_labels['block']))}}</th>

                     

                          <th>{{ucwords(str_replace('_',' ',$plot_labels['plot_name']))}} </th>

                          <th>{{ucwords(str_replace('_',' ',$plot_labels['type']))}}</th>
                          <th>{{ucwords(str_replace('_',' ',$plot_labels['category']))}}</th>
                          <th>{{ucwords(str_replace('_',' ',$plot_labels['size']))}}</th>

                       

                          <th>{{ucwords(str_replace('_',' ',$plot_labels['dimension']))}}</th>

                          <th>{{ucwords(str_replace('_',' ',$plot_labels['feature_charges']))}}</th>


                          <th>{{ucwords(str_replace('_',' ',$plot_labels['rate']))}}</th>
                          <th>STATUS</th>

                          <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>
                          
                        </tr>
                      </thead>
                    
                      <tbody id="show_plots">
                        {{-- {!! $plot_view !!} --}}
                      </tbody>

                    </table>
                  </div>
                </div>
              </div>
          </div>
@endsection

@section('page_modal')
  @include('inventory.modals.add_inventory')
  <div id="update_plot_modal"></div>
  @include('inventory.modals.bulk_update')

@endsection

@section('page_script')
  @include('scripts.inventory')

  <script type="text/javascript">
  var table = $('#plots_table');

    function renderPlotsTable()
    {
      table.DataTable().clear();
      table.DataTable().destroy();


      var branch  = $(".branch_list").val();
      var block  = $(".block").val();

      table.DataTable( {
        "regex": true ,
        columnDefs: [
                    { "type": "numeric-comma", targets: 0 }
                ],
        cache:true,
        responsive: true,
        bProcessing: true,
        bServerSide: true,
        deferRender: true,
        select: true,
        stateSave: true,
        responsive: true,
        pageLength:100,
        "ajax": {
                "url": "{{route('showdatatableplots')}}",
                "type": "GET",
                'data': {
                  'branch': branch,
                  'block': block,
                },
                  },
        "columns": [
           {
    name: 'count',
    data: 'count'
   },
   {
    name:'branch_name',
    data:'branch_name'
   },
   {
    name: 'block_name',
    data: 'block_name'
   },
   {
    name: 'article_no',
    data: 'article_no'
   },
   {
     name: 'type',
     data: 'type'
    },
   {
    name: 'category',
    data: 'category'
   },
   {
    name: 'size',
    data: 'size'
   },
   {
    name: 'dimensions',
    data: 'dimensions'
   },
   {
    name: 'featurecharges',
    data: 'featurecharges'
   },
   {
    name: 'rate',
    data: 'rate'
   },
   {
    name: 'status',
    data: 'status'
   },
    {
        name: 'action',
        data: 'action'
    },
        ],

    });
    }

    $(document).ready(function(){

      renderPlotsTable();

    });

  </script>
  
@endsection

  