@extends('layouts.pmapp')

@section('content')

{{-- Detail Reports --}}

<div class="card mb-4">
    <div class="card-header">
        <div class="d-flex">
            <div class="mr-auto p-2 align-self-center"><h4>Reports</h4></div>
        </div>    
        <div class="row">
            <div class="col-lg-4 col-sm-4">
                <div class="form-group w-30">
                    <select id="selectgrp" class="form-control @error('status_id')  @enderror" name="status_id" onchange="clicks()">
                        @php
                            echo App\Http\Controllers\StatusController::StatusListForCombo(0);
                        @endphp
                    </select>   
                    @error('status_id')<div class="invalid-feedback">{{ $message }}</div>@enderror
                </div>
            </div>
            <div class="col-lg-4 col-sm-4">
                
            </div>
            <div class="col-lg-4 col-sm-4">             
            
            </div>           
        </div>
    </div>
    <div class="card-body" id="search_section">
        @php $si=0; @endphp
        @foreach($Orders as $Order)
        <div class="table-responsive mb-3">
            <table class="table table-hover" id="search_section">
                <thead class="thead-light">
                    <tr>
                        <th>SLNO.</th>
                        <th>Order No.</th>
                        <th>Customer</th>
                        <th>Status</th>
                        <th>Duration</th>   
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    
                    <tr>
                        <td>{{++$si}}</td>
                        <td>{{$Order->id}}</td>
                        <td>{{$Order->user->name}}</td>
                        <td>{{$Order->status->title}}</td>
                        <td>{{$Order->duration->title}}</td>
                                             
                    </tr>
                    <tr>
                        <table class="table table-sm table-bordered">
                            <thead>
                                <tr>
                                    <th>Product</th>
                                    <th>Service</th>
                                    <th>Quantity</th>
                                </tr>
                            </thead>
                            <tbody>
                            @foreach($Order->order_products as $order_product)
                                <tr>
                                    <td>{{$order_product->product->title}}</td>
                                    <td>
                                        @foreach($order_product->order_product_services as $order_service)
                                        <span class="badge badge-primary">{{$order_service->product_service->servicetype->title}}</span>
                                        @endforeach
                                    </td>
                                    <td>{{$order_product->quantity}}</td> 
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </tr>
                </tbody>
            </table>
        </div>
        @endforeach
    </div>
    <div class="card-footer">
        <div class="row">
            <div class="col-lg-6">
                <div class="d-flex justify-content-start font-weight-bold">
                <a href=""><button class="btn btn-danger">Save Pdf</button></a>     
                </div>
            </div> 
            <div class="col-lg-6">
                <div class="d-flex justify-content-end font-weight-bold">
                    <form method="post" action="{{route('PmDetailPrint')}}">
                    @csrf
                        <input type="hidden" class="form-control @error('selectgrp') is-invalid @enderror"  name="selectgrp" id="SelectGroupforPrint" required>
                        @error('selectgrp')<div class="invalid-feedback">{{ $message }}</div>@enderror
                        <button type="submit" class="btn btn-primary">Print</button>
                    </form>   
                </div>
            </div>
        </div>            
    </div>
</div>

@endsection

<script> 

function clicks() {

    var items = document.getElementById("selectgrp").value;
       
   
    document.getElementById("SelectGroupforPrint").value=items;
     
    $.ajax({
      url: '{{ route('PmReportSelectGroups') }}',
      method: "get",
      data: {_token: '{{ csrf_token() }}',searchitems:items },
                              success: function (response){   

                                document.getElementById('search_section').innerHTML=response; 
                              
                                      }
                      });  

}
</script>

