@extends('layouts.backend')

@section('extraCss')  
<style type="text/css">
  .modal {
                text-align: center;
            }
 
</style>
@endsection
@php 
$Discounts = [ 1 => 'Clearence' , 2 => 'Non Clearence' ];
@endphp
@section('mainContentArea')
<div class="card card-default">
        <div class="card-header">
            <h4>Date Wise Stock Report</h4>
        </div>       
         
        <div class="alert alert-default" style="overflow-x:auto;">
            <form action="{{ route('pos-date-wise-stock-report') }}" id="articlereport">
                <h4>Filter  </h4>
                <table class="table filterPosSo" >        
                    
                    <tr>
                      
                        <td >Store</td>
                        <td>Date</td>                       
                        <td colspan="2">ACTION</td>
                    </tr>
                    <tr>
                         <tr>  
                         <a class="btn btn-md btn-primary" style="float:right; margin-bottom:10px;" href="{{ ($warehouseName) ? route('stockDateWiseExport',[implode(",",$pos_id),$date] ) : '#' }}" id="eexcel">Export Excel</a> 
                        </tr>                       

                        <td>
                            <select name="warehouse_id[]" id="Pos" class="input-md" >
                                <option value=''>Select</option>                                
                                @foreach($ALL_POS as $warehouse)
                                <option value="{{ $warehouse->id }}" {{ ( !empty(request("warehouse_id")) && in_array($warehouse->id, request("warehouse_id")) ? "selected" : "") }}>{{ $warehouse->warehouse_code . ' ('.$warehouse->name.')' }}</option>
                                @endforeach
                            </select>
                        </td>    

                        <td >
                            <input type="text" name="stockdate" id="stockdate" readonly class="form-control datepicker" placeholder="Enter date" value="<?php echo empty(request('stockdate')) ? date("Y-m-d") : request('stockdate') ?>" >
                             @if ($errors->has('stockdate'))
                             <span class="text-danger">{{ $errors->first('stockdate') }}</span>
                             @endif
                        </td>                    
                       
                        <td><button class="btn btn-block btn-success"><i class="fa fas fa-search" id="submit"></i></button></td>
                        <td><button class="btn btn-block btn-warning" type="button" onclick="window.location.href='{{ route('pos-date-wise-stock-report') }}';"><i class="fa fas fa-refresh"></i></button></td>
                    </tr>
                </table>
            </form>
        </div>

        <div class="card-body table-responsive" >            
            <table class="table table-striped table-bordered " id="dateStockTables">
                <thead>
                   
                    <tr>
                        <th>#</th>
                       
                        <th>Section</th>
                        <th>Subsection</th>
                     
                        <th>Article</th>
                        <th>Color</th>                       
                        <th>Size</th>  
                        <th>Barcode</th>  
                        <th>HSN</th> 
                        <th>MRP</th> 
                        <th>Tax</th>
                        <th>Qty</th>                    
                       
                    </tr>
                </thead>
                @if(count($warehouseProducts) > 0)
                <tbody>
                
                @php $gtotalqty  = 0 ;  $i = 1; @endphp 
                @foreach($warehouseProducts as $key => $row)
                    
                    <tr>
                         @php   $article = \App\Article::with('category')->with('maincategory')->select('image')->where('code',$row['article'])->first();
                               
                          @endphp
                         
                        <td> {{$i }}</td>
                       
                        <td>{{ !empty($article->maincategory) ? $article->maincategory->name : $row['section'] }}</td>
                        <td>{{ !empty($article->category) ? $article->category->name : $row['subsection'] }}</td>

                        <td><a data-toggle="tooltip"  style="width:100px;" class="img-fluid center-block img-rounded" title='<img src="{{  empty($article->image) || $article->image == 'NULL' ? 'https://via.placeholder.com/100x100.png?text=No Photo' : asset('/uploads/articles/'.$article->image) }}" 
                            style="width:100px;" class="img-fluid center-block img-rounded">'> {{ $row['article'] }} </a> </td> 
                        <td>{{ $row['color'] }}</td>
                        <td>{{ $row['size'] }}</td>
                        <td>{{ $row['barcode'] }}</td>
                        <td>{{ $row['hsn'] }}</td>
                        <td>{{ $row['mrp'] }}</td>
                        @php 
                             if($row['mrp'] >= 1000)
                             {
                                  $tax = 12;
                             }else
                             {
                                  $tax = 5;
                             }
                        @endphp
                         <td>{{ $tax }}</td>
                         @php 
                                if($row['qty'] > 1)
                                {
                                     $row['qty'] = 1;
                                }
                         $gtotalqty += $row['qty']; @endphp
                        <td>{{ $row['qty'] }}</td>
                        
                        
                    </tr>
                  @php $i++; @endphp
                @endforeach

                </tbody>
                 <tfoot>
                            <tr>
                            <td colspan =10></td>
                            <td>{{$gtotalqty}}</td>
                            </tr>  
                                            
                </tfoot>
                @endif
            </table>
              
        </div>

        
</div>

<div class="modal fade " id="ImageModal" tabindex="-1" role="dialog" aria-hidden="true" >
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div id="carouselExample" class="carousel slide" data-ride="carousel">
          
          <div class="carousel-inner">
            <div class="carousel-item active " >
             
              <img id='articlepop'  src="" alt="First slide" style="max-height:300px;">
             
            </div>
            
          </div>
          
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary"  data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
@endsection

@section('extraJs')

<script type="text/javascript">  


    $("#submit").click(function () {    

        if ($('#Pos').val() == '') {

            alert("Please Select Store");
           
            $("#dateStockTables").attr("disabled", "disabled");

            return false;
        }  
        
    });
$(document).ready(function() {
    $('#dateStockTables').DataTable( {
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],         
          dom: 'Bfrtip',
          buttons: ['colvis'],         
          colReorder: true,  
          paging: false 
       } );       
          } );

$(function () {
  $('#ImageModal').on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget); // Button that triggered the modal
    var newSrc = button.data('image'); // Extract info from data-* attributes
    
   console.log(newSrc);
     $('#articlepop').attr('src', newSrc);
  });
});
</script>



@endsection