 @extends('admin.layouts.main-layout')
 @section('content')
<div class="card">
        <div class="card-header">
            <h3 class="card-title">Single Digit</h3>
        </div>
        <div>
           <form role="form" method="get" action="{{url('admin/singledigit/excel')}}">
                  <div class="box-body">
                    <div class="row">
                      <div class="col-md-3">
                      <div class="form-group">
                            
                            <select  class="form-control select2 " name="stores_id"  required="required">
                            <option value="" >
                                Select Game
                            </option>
                            @if(!empty($store))
                            @foreach($store as $group)
                            <option value="{{$group->id}}">
                                {{$group->name}}
                            </option>
                            @endforeach
                            @endif
                            
                        </select>
                        </div>
                      </div>
                        <div class="col-md-3">
                      <div class="form-group">
                            
                            <select  class="form-control select2 " name="type"   required="required">
                            <option value="" >
                                Select Type
                            </option>
                          
                            <option value="open">
                                Open
                            </option>
                            <option value="close">
                                Close
                            </option>
                            
                            
                        </select>
                        </div>
                      </div>
                        <div class="col-md-3">
                        <div class="form-group">
                        
                         <input name="excel_date" id="birthday" class="date-picker form-control" placeholder="dd-mm-yyyy" type="text" required="required" type="text" onfocus="this.type='date'" onmouseover="this.type='date'" onclick="this.type='date'" onblur="this.type='text'" onmouseout="timeFunctionLong(this)" value="{{Request::get('search_date')}}">
                        <script>
                          function timeFunctionLong(input) {
                            setTimeout(function() {
                              input.type = 'text';
                            }, 60000);
                          }
                        </script>
                        </div>
                      </div>
                     
                      
                      <div class="col-md-3">
                       <button type="submit" class="btn btn-success mr-2">Excel</button>
                  
                     </div>
                   </div>
                 </div>
               </form>
             <!--  <a href="{{ url('admin/singledigit/excel') }}" class="btn btn-info">Excel </a> -->
          </div>
        <div class="card-body">
            @if(session()->has('message'))
                <div class="alert alert-success">
                    {{ session()->get('message') }}
                </div>
            @endif
            <div id="example1_wrapper" class=" dt-bootstrap4">
              <div class="row">
              <div class="col-xs-12">
                <form role="form" method="get" action="">
                  <div class="box-body">
                    <div class="row">
                      <div class="col-md-6">
                        <div class="form-group">
                         <!--  <input type="text" name="search_date" id="search_by_name-btn" class="form-control" placeholder="Search by  Name " value="{{Request::get('search_date')}}"> -->
                         <input name="search_date" id="birthday" class="date-picker form-control" placeholder="dd-mm-yyyy" type="text" required="required" type="text" onfocus="this.type='date'" onmouseover="this.type='date'" onclick="this.type='date'" onblur="this.type='text'" onmouseout="timeFunctionLong(this)" value="{{Request::get('search_date')}}">
                        <script>
                          function timeFunctionLong(input) {
                            setTimeout(function() {
                              input.type = 'text';
                            }, 60000);
                          }
                        </script>
                        </div>
                      </div>
                     
                      
                      <div class="col-md-6">
                       <button type="submit" class="btn btn-success mr-2">Search</button>
                       <a href="{{url('admin/single-digit')}}" class="btn btn-info">Reset</a>
                     </div>
                   </div>
                 </div>
               </form>
             </div>
                <div class="row">
                    <div class="col-sm-12">
                        @php 
                       $page=1;
                    if(Request::input('page'))
                    $page=Request::input('page');
                    $sort = $lists->perPage();
                  @endphp

                  @forelse($lists as $key => $list)
                      <h3>{{$list->name}}({{isset($list->storeGame) ? timeShow($list->storeGame->opent_time) : '' }}) (Open)</h3>
                        <table id="example1" class="table table-bordered table-striped dataTable" role="grid"
                               aria-describedby="example1_info">
                            <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-sort="ascending"
                                    aria-label="Rendering engine: activate to sort column descending"
                                    style="width: 60px;">S.No
                                </th>
                                
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   User Name
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   0
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   1
                                </th>
                             
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   2
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    3
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    4
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    5
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    6
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    7
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    8
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    9
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    Total
                                </th>
                                
                            </tr>
                            </thead>
                            <tbody>
                               @php $type = 0;@endphp
                            @if(count($list->bit)>0)  
                           @foreach($list->bit as $key => $bits)
                             
                             @if(bitType($bits->id,'open'))
                              @php $type = ++$key;@endphp
                                <tr>
                                  <td>{{++$key}}</td>
                                  <td>{{$bits->username->name}} </td>
                                  
                                  @for($i=0;$i<10;$i++)
                                   <td>{{SingleDigitBitAmount($bits->id,$i)}}</td>
                                  @endfor
                                  <td>{{$bits->amount}}</td>
                                </tr>
                                @endif
                            @endforeach
                            @if($type>0)
                            <tr><td colspan="2" style="text-align: center;">Grand Total </td>
                               @for($i=0;$i<10;$i++)
                                   <td>{{singleDigitUserTotalAmount($i,$list->id,'open')}}</td>
                                  @endfor
                                  <td>{{bitTotalAmountOpen(1,$list->id)}}</td>
                            </tr>
                            @else
                           
                            @endif
                            @endif
                      </tbody>
                   </table>
                    @empty
                      <h3>No Store</h3>
                    @endforelse
                     @forelse($lists as $key => $list)
                      <h3>{{$list->name}}({{isset($list->storeGame) ? timeShow($list->storeGame->close_time) : '' }}) (Close)</h3>
                        <table id="example1" class="table table-bordered table-striped dataTable" role="grid"
                               aria-describedby="example1_info">
                            <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-sort="ascending"
                                    aria-label="Rendering engine: activate to sort column descending"
                                    style="width: 60px;">S.No
                                </th>
                                
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   User Name
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   0
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   1
                                </th>
                             
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   2
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    3
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    4
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    5
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    6
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    7
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    8
                                </th>
                                 <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    9
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Platform(s): activate to sort column ascending" style="width: 183px;">
                                    Total
                                </th>
                                
                            </tr>
                            </thead>
                            <tbody>
                               @php $type = 0;@endphp
                            @if(count($list->bit)>0)  
                           @foreach($list->bit as $key => $bits)
                          
                             @if(bitType($bits->id,'close'))
                              @php $type = $key;@endphp
                                <tr>
                                  <td>{{++$key}}</td>
                                  <td>{{$bits->username->name}} </td>
                                  
                                  @for($i=0;$i<10;$i++)
                                   <td>{{SingleDigitBitAmount($bits->id,$i)}}</td>
                                  @endfor
                                  <td>{{$bits->amount}}</td>
                                </tr>
                              @endif  
                            @endforeach
                            @if($type>0)
                            <tr><td colspan="2" style="text-align: center;">Grand Total </td>
                               @for($i=0;$i<10;$i++)
                                   <td>{{singleDigitUserTotalAmount($i,$list->id,'close')}}</td>
                                  @endfor
                                  <td>{{bitTotalAmountClose(1, $list->id)}}</td>
                            </tr>
                            @else
                            
                            @endif
                            @endif
                      </tbody>
                   </table>
                    @empty
                      <h3>No Store</h3>
                    @endforelse
                    
            </div>
                  </div>
                </div>
              </div>
            </div>
          </div>


 @endsection
@section('js-content')
@endsection