@extends('layout')
@section('title', 'ٹرپس')
@section('page_title', 'ٹرپس')
@section('css')

@endsection
@section('page_sub_title')
    @if(auth()->user()->hasPermissionTo('create trip'))

        <a type="button" onclick="add_new_trip()" class="btn pointer btn-primary btn-sm">نئے ٹرپ کا اندراج</a>
    @endif
@endsection
@section('content')
    <div class="row">
        <div class="col-md-4">
            <div class="panel panel-card">
                <div class="panel-heading">ماہانا ٹرپ بچت:</div>
                <div class="panel-body">
                    <form action="" id="monthly_trip_report_form">
                        <div class="row">
                            <div class="col-md-5">
                                <select name="vehicle" id="closed_trip" class="form-control report_select" required>
                                    <option value="">----Vehicle ----</option>
                                    <option value="all">تمام</option>
                                    @forelse($report_vehicles as $vehicle)
                                        <option
                                            value="{{ $vehicle->id }}">{{ $vehicle->vehicle_no }}</option>
                                    @empty
                                    @endforelse
                                </select>
                            </div>
                            <div class="col-md-7">
                                <div class="row">
                                    <div class="col-md-6">
                                        <select name="month" id="month" class="form-control report_select" required>
                                            <option value="">Month</option>
                                            @php
                                                $months = [];
                                                for ($i = 1; $i <= 12; $i++) {
                                                    $month = new DateTime(date('Y-'.$i.'-01'));
                                                    $months[] = $month->format('F');
                                                }
                                            @endphp
                                            <option value="all">تمام</option>
                                            @foreach($months as $key=> $month)
                                                <option
                                                    value="{{ $key+1 }}" @selected($key+1==date('n'))>{{ $month }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="col-md-6">
                                        <select name="year" id="" class="form-control report_select" required>
                                            <option value="">Year</option>
                                            @php
                                                $end_year = date('Y') + 100;
                                                $start_year = (int)$end_year - 110;
                                            @endphp
                                            @for($i = $start_year; $i<=$end_year; $i++)
                                                <option value="{{$i}}" @selected($i == date('Y'))>{{ $i }}</option>
                                            @endfor

                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-2" style="margin-top: 10px;">
                            <div class="col-md-6">
                                <label for="monthly_is_detail"><input type="checkbox" name="is_detail" onchange="checkbox_change('month','is_detail')" id="monthly_is_detail" value="yes"> مکمل
                                    تفصیل</label> &nbsp;&nbsp;&nbsp;&nbsp;
                                <label for="monthly_is_ranking"><input type="checkbox" name="is_ranking" onchange="checkbox_change('month','is_ranking')" id="monthly_is_ranking" value="yes"> درجہ بندی
                                    تفصیل</label>
                            </div>
                            <div class="col-md-6 " style="text-align: left;">
                                @csrf
                                <button class="btn btn-sm btn-info" id="monthly_vehicle_profit_report_btn">رپورٹ
                                </button>
                            </div>
                        </div>
                        <div class="row mt-2">

                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="panel panel-card">
                <div class="panel-heading">سالانہ ٹرپ بچت:</div>
                <div class="panel-body">
                    <form action="" id="yearly_trip_report_form">
                        <div class="row">
                            <div class="col-md-4">
                                <select name="gari" id="" class="form-control report_select" required>
                                    <option value="">---Vehicle---</option>
                                    <option value="all">تمام</option>
                                    @forelse($report_vehicles as $vehicle)
                                        <option
                                            value="{{ $vehicle->id }}">{{ $vehicle->vehicle_no }}</option>
                                    @empty
                                    @endforelse
                                </select>
                            </div>
                            <div class="col-md-8">
                                <div class="row">
                                    <div class="col-md-4">
                                        <select name="year" id="" class="form-control report_select" required>
                                            <option value="">Year</option>
                                            @php
                                                $end_year = date('Y') + 100;
                                                $start_year = (int)$end_year - 110;
                                            @endphp
                                            @for($i = $start_year; $i<=$end_year; $i++)
                                                <option value="{{$i}}" @selected($i == date('Y'))>{{ $i }}</option>
                                            @endfor

                                        </select>
                                    </div>
                                    <div class="col-md-8">
                                        <label for="yearly_is_detail"><input type="checkbox" name="is_detail" onchange="checkbox_change('year','is_detail')" id="yearly_is_detail" value="yes"> مکمل
                                            تفصیل</label> &nbsp;&nbsp;&nbsp;&nbsp;
                                        <label for="yearly_is_ranking"><input type="checkbox" name="is_ranking" onchange="checkbox_change('year','is_ranking')" id="yearly_is_ranking" value="yes"> درجہ بندی
                                            تفصیل</label>

                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row mt-2" style="margin-top: 10px">
                            <div class="col-md-8">

                            </div>
                            <div class="col-md-4" style="text-align: left"> @csrf
                                <button class="btn btn-sm btn-info" id="yearly_vehicle_profit_report_btn">رپورٹ
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-md-4" id="profit_report_dev"></div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-card">
                <div class="panel-body">
                    <table id="trip_table" class="table table-bordered" cellspacing="0" width="100%">
                        <thead class="bg-gold text-white">
                        <tr style="white-space: nowrap;">
                            <th>.</th>
                            <th>ٹرپ نمبر</th>
                            <th> تاریخ ابتدا</th>
                            {{-- <th>تاریخ انتہا</th> --}}
                            {{-- <th>میٹر ریڈنگ</th> --}}
                            <th>گاڑی - ڈرائیور</th>
                            {{-- <th>کل بچت - فی دن بچت</th> --}}
                            {{-- <th>سٹیٹس</th> --}}
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                </div>
            </div>
        </div>

    </div>

    <div class="modal fade" id="addTripModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content panel-card">
                <div class="modal-header">
                    <h4>نئے ٹرپ کا اندراج</h4>
                </div>
                <form id="add_trip_form">
                    <div class="modal-body">
                        <div class="row">
                            <div class="col-md-4">
                                {{-- <div class="form-group"> --}}
                                <label for="vehicle">گاڑی کا نام <span class="text-danger">*</span></label><br>
                                <select id="vehicle" name="vehicle"
                                        class="form-control w-100">
                                    <option value="">-- SELECT--</option>
                                    @forelse ($vehicles as $vehicle)
                                        <option value="{{ $vehicle->id }}">{{ $vehicle->vehicle_no }}</option>
                                    @empty
                                        <option value="">No Vehicle Available</option>
                                    @endforelse
                                </select>
                                <span class="text-danger error" id="vehicle_error"></span>
                                {{-- </div> --}}
                            </div>

                            <div class="col-md-4">
                                <label for="start_date">ٹرپ کی ابتدایئ تاریخ <span class="text-danger">*</span></label>
                                <input value="{{ date('Y-m-d') }}" type="date" id="start_date" name="start_date" class="form-control">
                                {{-- <input type="hidden" name="hidden_start_date" id="hidden_start_date"> --}}
                                <span class="text-danger error" id="start_date_error"></span>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        @csrf
                        <button name="createCitySubmit" id="submit_btn" class="btn btn-sm btn-primary" type="submit">
                            شروع کریں
                        </button>
                    </div>
                </form>

            </div>
        </div>
    </div>
    <div class="modal fade" id="addDieselModel" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg w-90" id="addDieselModelData">

        </div>
    </div>
    <div class="modal fade" id="addTripAdvanceModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content panel-card" id="addTripAdvanceData">
            </div>
        </div>
    </div>
    <div class="modal fade" id="addTripReachModal" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-lg">
            <div class="modal-content panel-card" id="addTripReachData">
            </div>
        </div>
    </div>
@endsection
@section('javascript')
    @include('trips.js')
    @include('trip_details.js')
    {{-- @include('trip_oils.js') --}}
    @include('trip_deposit.js')
    @include('trip_reach_payables.js')
    @include('trip_payables.js')
    @include('trip_receivings.js')
    {{-- @include('trip_salaries.js') --}}
    @include('trip_advance.js')

@endsection
