@extends('layouts.app')

@section('title')
All  Size 
@stop

@section('breadcrumb')
<ol class="breadcrumb pull-right">
        <li><a href="{{route('home')}}"><i class="fa fa-dashboard"></i> Home</a></li>

        <li class="active">All Sizes</li>
      </ol>
@stop
@section('content')

@php
$society = false;
$high_rise = false;
@endphp
@can('isSuperAdmin')
@php

 if(isset($ids[0])){
    if($ids[0] != 'all'){
        $result=   \App\MultiProject::whereIn('id',$ids)->where('project_type_id',\App\ProjectType::society)->first();
   
        if(!empty( $result))
        {
            $society = true;
           $high_rise = true; 
        }
        else {
            $society = false;
           $high_rise = true; 
        }
    }
    else {
      $r=  \App\MultiProject::where('project_type_id',\App\ProjectType::society)->first();
      if(!empty( $r))
        {
            $society = true;
           $high_rise = true; 
        }
        else {
            $society = false;
           $high_rise = true; 
        }
    }
 }

   
  
@endphp
@elsecannot('isSuperAdmin')
@php
if($cookie_project_type == \App\ProjectType::society)
    {
        $society=true;
        $high_rise = false;
    }
    if($cookie_project_type == \App\ProjectType::high_rise ){
        $high_rise = true;
        $society=false;
    }
   
@endphp 
@endcan


            <div class="container-fluid">
                <!-- /row -->
                <div class="row">
                    <div class="col-sm-12">
                        <div class="white-box">
                        	<div class="pull-right" style="margin-top: 10px;">
                                @permission('create-unit-size')
								<a href="{{route('unit.size.addView')}}" class="btn  btn-primary">
									<i class="fa fa-plus-square"></i>&nbsp; Add New Size
								</a>
                                @endpermission
							</div>
                            <h3 class="box-title">All Units Size</h3>

                            <div class="table-responsive">
                                <table id="myTable" class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>Size</th>

                                            <th>Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php $count =1;?>
                                        @foreach($allUnitSizes as $size)
                                        <tr>
                                            <td>{{$count++}}</td>
                                            
                                            <td>{{$size->name}} 
                                                 @if( $high_rise== true  && $society=true)
                                                {{ \App\ProjectType::society_size}}/ {{ \App\ProjectType::high_rise_size}}
                                              
                                              @elseif($high_rise== true  && $society=false)
                                                {{ \App\ProjectType::high_rise_size}}
                                              
                                              @elseif($high_rise== false  && $society=true)
                                              {{ \App\ProjectType::society_size}} 
                                                @endif

                                                
                                                
                                                
                                            
                                            </td>
                                        

                                           @if($size->status == true)
                                            <td><span class="label label-success">Active</span></td>
                                            @else
                                            <td><span class="label label-danger">InActive</span></td>
                                            @endif
                                            <td class="text-nowrap">
                                                @permission('view-unit-size')
                                                <a href="{{route('unit.size.detail',['id'=>$size->id])}}" data-toggle="tooltip" data-original-title="View"> <i class="fa fa-eye text-inverse m-r-10"></i> </a>
                                                @endpermission

                                                @permission('edit-unit-size')
                                                <a href="{{route('unit.size.editView',['id'=>$size->id])}}" data-toggle="tooltip" data-original-title="Edit"> <i class="fa fa-pencil text-inverse m-r-10"></i> </a>
                                                @endpermission

                                                @permission('delete-unit-size')
                                                <a href="{{route('unit.size.delete',['id'=>$size->id])}}" data-toggle="confirmation" data-title="Are you sure to delete?" > <i class="fa fa-close text-danger"></i> </a>
                                                @endpermission
                                            </td>
                                        </tr>
                                        @endforeach

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.row -->
              </div>
            <!-- /.container-fluid -->

@stop

@section('js')
<script>
    $(function() {
        $('#myTable').DataTable();

        var table = $('#example').DataTable({
            "columnDefs": [{
                "visible": false,
                "targets": 2
            }],
            "order": [
                [2, 'asc']
            ],
            "displayLength": 25,
            "drawCallback": function(settings) {
                var api = this.api();
                var rows = api.rows({
                    page: 'current'
                }).nodes();
                var last = null;
                api.column(2, {
                    page: 'current'
                }).data().each(function(group, i) {
                    if (last !== group) {
                        $(rows).eq(i).before('<tr class="group"><td colspan="5">' + group + '</td></tr>');
                        last = group;
                    }
                });
            }
        });
        // Order by the grouping
        $('#example tbody').on('click', 'tr.group', function() {
            var currentOrder = table.order()[0];
            if (currentOrder[0] === 2 && currentOrder[1] === 'asc') {
                table.order([2, 'desc']).draw();
            } else {
                table.order([2, 'asc']).draw();
            }
        });
    });
    $('#example23').DataTable({
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    });
    </script>
@stop