@ksi Thank you my friend for your support
I have a few questions.
should I set the $from and $to variable to be empty like this:
$from = date('');
$to = date('');
when I set the dates while inspecting the page, the console doesn't show anything, if you noticed I have a search button, how can I make it execute the script?
My Controller and view after modifications:
Controller:
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Gate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Response;
class VouchersAccountingController extends Controller
{
public function index()
{
abort_if(Gate::denies('vouchers_accounting_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$from = date('');
$to = date('');
$Reports = DB::table('create_vouchers')
->select('create_vouchers.id', 'client_name', 'night', 'hotels.hotel_name', 'arrivaldate', 'departuredate', 'total_amount', 'number_of_room', 'payment_mode')
->join('hotels', 'hotels.id', 'create_vouchers.hotel_name_id')
->whereBetween('arrivaldate', [$from, $to])->get();
//return view('admin.vouchersAccountings.index', compact(['Reports']));
// send from & to to the view
return view('admin.vouchersAccountings.index', compact('Reports', 'from', 'to'));
}
}
View:
@extends('layouts.admin')
@section('content')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<link href="{{ asset('css/arrivaldeparture.css') }}" rel="stylesheet" />
<div class="content">
<div class="row">
<div class="col-md-12 mt-4">
<div class="panel panel-default">
<div class="panel-heading">
{{ trans('cruds.vouchersAccounting.title') }}
</div>
<div class="panel-body">
<div class="card">
<div class="card-header">
<h4 class="Green">Reports</h4>
<script type="text/javascript">
$(function() {
$('#datetimepicke').datetimepicker();
});
</script>
<script>
$(function() {
$('#date-from').datepicker({
'dateFormat': 'yyyy-mm-dd'
});
$('#date-from').datepicker('setDate', '{{ $from }}');
$('#date-to').datepicker({
'dateFormat': 'yyyy-mm-dd'
});
$('#date-to').datepicker('setDate', '{{ $to }}');
})
</script>
<div class="form-group">
From
<div class='input-group date' id='CalendarDateTime'>
<input id="date-from" type='text' class="form-control" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
<div class="form-group">
To
<div class='input-group date' id='CalendarDateTime'>
<input id="date-to" type='text' class="form-control" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>
</div>
<button type="button" class="btn btn-primary">Search</button>
<div class="card-body">
<table class="table">
<thead>
<tr>
<th>Voucher #</th>
<th>Client</th>
<th>Hotel</th>
<th>Arrival</th>
<th>Departure</th>
<th>Nights</th>
<th>Rooms</th>
<th>Payment Mode</th>
<th>Paid Amount</th>
</tr>
</thead>
<tbody>
@foreach($Reports as $Report)
<tr>
<th> {{$Report->id}} </th>
<th> {{$Report->client_name}} </th>
<th> {{$Report->hotel_name}} </th>
<th> {{$Report->arrivaldate}} </th>
<th> {{$Report->departuredate}} </th>
<th> {{$Report->night}} </th>
<th> {{$Report->number_of_room}}</th>
<th> {{$Report->payment_mode}}</th>
<th> {{$Report->total_amount}}</th>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="{{ asset('js/va.js')}}"></script>
@endsection