@extends('admin.master')
@section('title') Shop Wise Report | Bus Ticket @endsection
@section('shop-wise-invoice-report') active @endsection
@section('shop-wise-invoice-report') active @endsection
@section('styles')
@endsection


@section('main_content_section')
<div class="row py-3 ps-2">
    <div class="heading d-flex justify-content-start align-items-center">
        <h3 class="mb-0"><span> Shop Wise Report List</span></h3>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <form action="{{route('shop-wise-invoice-report')}}" method="post" enctype="multipart/form-data">
            @csrf
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <div class="form-group custom-select2-form">
                            <label for="year"> Year <span class=" text-danger">(required)</span>
                            </label>
                            <select name="year" id="year" class="form-select select2" required>
                                <option value="" selected disabled>Select Year</option>

                                @foreach($getAllYears as $key=>$singleYear)
                                @if (isset($singleYear) && $singleYear != null)
                                <option value="{{$singleYear}}" {{$singleYear == $currentYear ? 'selected' : ''}}>
                                    {{$singleYear}}</option>
                                @endif
                                @endforeach
                            </select>
                        </div>

                        @error('year')
                        <span class=text-danger>{{$message}}</span>
                        @enderror
                    </div>

                    {{-- <div class="col-md-4 mb-3">
                        <div class="form-group custom-select2-form">
                            <label for="month"> Month <span class=" text-danger">(required)</span>
                            </label>
                            <select name="month" id="month" class="form-select select2" required>
                                <option value="" selected disabled>Select Month</option>

                                @foreach($getAllMonthNames as $key=>$singleMonth)
                                @if (isset($singleMonth) && $singleMonth != null)
                                <option value="{{$singleMonth}}" {{$singleMonth == $currentMonth ? 'selected' : ''}}>
                                    {{$singleMonth}}</option>
                                @endif
                                @endforeach
                            </select>
                        </div>

                        @error('month')
                        <span class=text-danger>{{$message}}</span>
                        @enderror
                    </div> --}}
                    
                    <div class="col-md-6 mb-3">
                        <div class="form-group custom-select2-form">
                            <label for="shop_id"> Shop <span class=" text-danger">(required)</span>
                            </label>
                            <select name="shop_id" id="shop_id" class="form-select select2" required>
                                <option value="" selected disabled>Select Shop</option>
                                @foreach($shopData as $key=>$singleSD)
                                @if (isset($singleSD) && $singleSD != null)
                                <option value="{{$singleSD->id}}" {{$singleSD->id == $selectedShopData->id ? 'selected' : ''}}>
                                    {{$singleSD->shop_name}}</option>
                                @endif
                                @endforeach
                            </select>
                        </div>

                        @error('shop_id')
                        <span class=text-danger>{{$message}}</span>
                        @enderror
                    </div>

                    <div class="col-md-12">
                        <button type="submit" class="btn btn btn-primary m-0 py-2 d-flex custom-float-right-side">
                            <i class="material-symbols-outlined custom-project-icon">
                                tune
                            </i>
                            <span>
                                Search
                            </span>
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="table_wrapper py-1 card mt-4">
    <div class="row my-2 aggregate-section-div">
        <div class="px-3 ">
            <div class=" d-flex justify-content-between align-items-center aggregate-section border">
                <div class="d-flex align-items-center">
                    <p class="mb-0"><a href="{{route('shop-wise-invoice-report')}}"
                            class="text-primary py-2 px-3 active">All({{$totalShopBillCount}})</a>
                    </p>
                </div>
                <div class="d-sm-block">
                    @if(Auth::user()->can('shop-invoice-report-access'))
                    @if(isset($selectedShopData) && $selectedShopData != null)
                    <a href="{{route('print-shop-wise-invoice-report', ['year'=>$currentYear,'shop_id'=>$selectedShopData->id])}}"
                        class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0" target="_blank">
                        <span class="">
                            <i class="fa fa-print"></i>
                            Print Report</span>
                    </a>
                    {{-- <a href="{{route('print-shop-wise-invoice-report', ['year'=>$currentYear,'month'=>$currentMonth])}}"
                        class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0" target="_blank">
                        <span class="">
                            <i class="fa fa-print"></i>
                            Print Report</span>
                    </a> --}}
                    @else
                    <a href="javascript:void(0)"
                        class="btn btn-success rounded-0 d-flex align-items-center px-2 border-0" onclick="checkShopData()">
                        <span class="">
                            <i class="fa fa-print"></i>
                            Print Report</span>
                    </a>
                    @endif
                    @endif
                </div>
            </div>
        </div>
    </div>



    <div class="row px-3">
        <div class="table-container table-responsive">
            <table id="" class="table table-bordered">
                <thead class="text-uppercase">
                    <tr class="me-3">
                        <th class="text-center" scope="col"><span>Serial</span></th>
                        <th class="text-center" scope="col"><span>Month Name</span></th>
                        <th class="text-center" scope="col"><span>Net Amount</span></th>
                        <th class="text-center" scope="col"><span>Paid Amount</span></th>
                        <th class="text-center" scope="col"><span>Due Amount</span></th>
                        <th class="text-center" scope="col"><span>Bill Generate</span></th>
                    </tr>
                </thead>
                <tbody class="text-center">

                    @foreach($shopBillData as $key=>$item)
                    @if(isset($item) && $item != null)
                    <tr class="">

                        <td>
                            <div class="row_title">
                                <b> #{{ $key+1 }}</b>
                            </div>
                            <div class="row-actions mt-2">
                            </div>
                        </td>

                        <td>
                            {{$item->billGenerateData->bill_generated_month}}
                        </td>

                        <td>
                            <span class="fw-normal">{{ $item->net_amount }}tk</span>
                        </td>
                        
                        <td>
                            <span class="fw-normal">{{ $item->paid_amount }}tk</span>
                        </td>
                        
                        <td>
                            <span class="fw-normal">{{ $item->due_amount }}tk</span>
                        </td>

                        <td>
                            {{Carbon\Carbon::parse($item->created_at->toDateString())->format('d-m-Y')}}
                        </td>

                    </tr>

                    @endif
                    @endforeach


                </tbody>
                <tfoot class="">
                    <tr class="custom-invoice-table-footer text-center custom-report-table-footer">
                        <th>Total</th>
                        <th>=</th>
                        <th class="fw-bold text-primary">{{ $totalNetAmount }}tk</th>
                        <th class="fw-bold text-success">{{ $totalPaidAmount }}tk</th>
                        <th class="fw-bold text-danger">{{ $totalDueAmount }}tk</th>
                        <th></th>
                    </tr>
                </tfoot>
            </table>
        </div>

        @if(isset($shopBillData) && $totalShopBillCount > 10)
        <div class="clearfix d-flex">
            <div class="float-left">
                <p class="text-muted">
                    {{ __('Showing') }}
                    <span class="font-weight-bold">{{ $shopBillData->firstItem() }}</span>
                    {{ __('to') }}
                    <span class="font-weight-bold">{{ $shopBillData->lastItem() }}</span>
                    {{ __('of') }}
                    <span class="font-weight-bold">{{ $shopBillData->total() }}</span>
                    {{ __('results') }}
                </p>
            </div>

            <div class="float-right custom-table-pagination">
                {!! $shopBillData->links('pagination::bootstrap-4') !!}
            </div>
        </div>
        @endif
    </div>
</div>

@endsection

@section('scripts')
<script>
    $(document).ready(function(){
        $("#year").select2();
        $("#month").select2();
        $("#shop_id").select2();
    });

    function checkShopData() {
        toastr.error('Sorry, You  have no data.!');
    }
</script>
@endsection