What do you get when:
$sales = Sales_details::where('date',$request->date)->get()
dd($sales);
Guys my project milkfarm, I have used barryvdh/laravel-dompdf to convert html to pdf convertor for my report generation
This is my view.blade
<a href="{{ route('download') }}" class="btn btn-success btn-sm" </td>download</a>
<th> {{ Form::text('search_name',null,array('class'=>'form-control','id'=>'search_date','name'=>'search_date')) }}</th>
And this is my controller
if i give simply
$sales = Sales_details::get()
it fetches whole record and pdf conversion is done correctly but if i give like this below
public function download(Request $request)
{
$sales = Sales_details::where(function ($query) use ($request)
{
if (!empty($request->search_date)) {
$query->Where('date', 'LIKE', '%' . $request->search_date . '%');
}
})->orderBy('id','asc')->get();
$pdf=PDF::loadView('Sales_details.view1',['sales'=>$sales],['date'=>$request->search_date]);
$pdf->setPaper('A4');
return $pdf->download('salesdetails.pdf');
}
this not works. it not fetching any record simply the table heading is displayed.
i tried this also
$sales = Sales_details::where('date','=', $request->date)->get();
and this alsoo
$sales = Sales_details::where('date',$request->date)->get()
In the view file I have a button download and a textx box. My problem is the value given in the textbox must be taken to the controller and according that data must be fetched and converted into pdf. The value given in the text box must also to be displayed the pdf
That is if I give date. That value must be taken to controller and based on that values are fetched from db and returned and converted in the pdf. The pdf has label Date: That must also be filled. This date is the request given in the view file in textbox
this is my view1.blade
<caption><h2 align="center">SALES ENTRY PREVIEW</h2></caption><br>
{{ Form::label('Date','Date :') }}{{ $date }}
<table>
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Time</th>
<th>Customer Type</th>
<th>Customer Name</th>
<th>Customer Area</th>
<th>Customer Booth</th>
<th>Employee</th>
<th>Rate/Litre</th>
<th>No of Litres (Lt)</th>
<th>Total (Rs)</th>
</tr>
</thead>
<tbody>
@foreach($sales as $sal)
<tr>
<td>{{ $sal->id }}</td>
<td>{{ $sal->date->format('d-m-Y') }}</td>
<td>{{ $sal->time }}</td>
<td>{{ $sal->customer_type }}</td>
<td>{{ $sal->customer_name }}</td>
<td>{{ $sal->customer_area }}</td>
<td>{{ $sal->customer_booth }}</td>
<td>{{ $sal->emp }}</td>
<td>{{ $sal->rate_per_litre }}</td>
<td>{{ $sal->no_of_litre }}</td>
<td>{{ $sal->total }}</td>
</tr>
@endforeach
</tbody>
</table>
in the
{{ Form::label('Date','Date :') }}{{ $date }} the date given in the view blade $request it must be filled
i also need the sum of the columns.
i knew that to sum just we can use
sum('amount')
this sums the whole columns of amount but how could i display this in my view1.blade file as last row
Kindly some one please help.. suggest me.. please
The porblem solved this the correct code
the mistake done is in the ajax . format is improper
this is the right code
$('#search_frmdate,#search_date,#search_time,#search_nl,#search_note').on('keyup',function(){
$.ajax({
dataType: 'json',
type : 'get',
url : '{{URL::to('search_excess_milk_details')}}',
data:{ 'search_frmdate': $('#search_frmdate').val(),
'search_todate': $('#search_date').val(),
'search_time': $('#search_time').val(),
'search_nl': $('#search_nl').val(),
'search_note': $('#search_note').val()
},
success:function(data)
{
console.log(data);
var res='';
$.each (data, function (key, value) {
res +=
'<tr>'+
'<td>'+value.date+'</td>'+
'<td>'+value.time+'</td>'+
'<td>'+value.no_of_litre+'</td>'+
'<td>'+value.note+'</td>'+
'</tr>';
});
$('tbody').html(res);
}
});
})
and the search in controller is
public function search_excess_milk_details( Request $request )
{
$xcess_milks = Excess_milk::where(function ($query) use ($request)
{
if (!empty($request->search_time)) {
$query->Where('time', 'LIKE', '%' . $request->search_time . '%');
}
})->orderBy('date','asc')->get;
return Response($xcess_milks);
}
Here the contoller just searches only the time.. but i send data of fromdate, todate etc.. you can modify the controller search option based on your project
Please or to participate in this conversation.