@extends('admin.master')
@section('title') Daily Expense Report | Bus Ticket @endsection
@section('expense-daily-report') active @endsection
@section('expense-daily-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> Daily Expense Report List</span></h3>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <form action="{{route('expense-daily-report')}}" method="post" enctype="multipart/form-data">
            @csrf
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-12 mb-3">
                        <div>
                            <div class="form-group">
                                <label for="selected_from_date">Select A Date<span class=" text-danger">*</span> </label>
                    
                                <input type="text" class=" form-control flatpickr-basic custom-date-picker" name="selected_from_date"
                                    id="selected_from_date" placeholder="DD-MM-YYYY"
                                    value="{{Carbon\Carbon::parse($selectedDate)->format('d-m-Y')}}" required>
                            </div>
                    
                            @error('selected_from_date')
                            <span class=text-danger>{{$message}}</span>
                            @enderror
                        </div>
                    </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('expense-daily-report')}}"
                            class="text-primary py-2 px-3 active">All({{$unpaidExpenseReceiptData->count()}})</a>
                    </p>
                </div>
                <div class="d-none d-sm-block">
                    @if(Auth::user()->can('expense-daily-report-access'))
                    <a href="{{route('print-expense-daily-report', ['selected_date'=>$selectedDate])}}"
                        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>
                    @endif
                </div>
            </div>

            @if(Auth::user()->can('expense-daily-report-access'))
            <div class="mt-2 btn btn-success d-block rounded-0 d-sm-none">
                <a href="{{route('print-expense-daily-report', ['selected_date'=>$selectedDate])}}"
                    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>
            </div>
            @endif
        </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>Expense ID</span></th>
                        <th class="text-center" scope="col"><span>Receipt By</span></th>
                        <th class="text-center" scope="col"><span>Notes</span></th>
                        <th class="text-center" scope="col"><span>Expense Qty</span></th>
                        <th class="text-center" scope="col"><span>Expense Amount</span></th>
                        <th class="text-center" scope="col"><span>Date</span></th>
                    </tr>
                </thead>
                <tbody class="text-center">

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

                        <td>
                            <div class="row_title">
                                <b> #{{ $item->expense_receipt_id }}</b>
                            </div>
                            <div class="row-actions mt-2">
                            </div>
                        </td>

                        <td>
                            <a href="#"
                                class="text-primary">{{ $item->receipt_by }}</a>
                        </td>

                        <td>
                            <span class="fw-normals">{{ $item->receipt_notes }}</span>
                        </td>
                        @php
                        // To get expense total qty and amount...
                        $totalExpenseQty = App\Models\ExpenseReceiptService::getTotalExpenseReceiptServiceQty($item->id);
                        $totalExpenseAmount = App\Models\ExpenseReceiptService::getTotalExpenseReceiptServiceAmount($item->id);
                        @endphp
                        <td>
                            <span class="fw-normal">{{ $totalExpenseQty }}</span>
                        </td>
                        <td>
                            <span class="fw-normal">{{ $totalExpenseAmount }}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></th>
                        <th class="fw-bold text-info">{{ $totalExpenseServiceQty }}</th>
                        <th class="fw-bold text-success">{{ $totalExpenseServiceAmount }}tk</th>
                        <th></th>
                    </tr>
                </tfoot>
            </table>
        </div>

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

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

@endsection

@section('scripts')
<script>
    $(document).ready(function(){
        $("#selected_from_date").flatpickr({
            allowInput: true,
            dateFormat: "d-m-Y",
        });
    });
</script>
@endsection