Skip to content

Yajra datatable date range report #1694

@Ghafoorfahim

Description

@Ghafoorfahim

Hi for everyone on the cross of the globe.
I use Yajra datatable to filter my report as bellow.
Dear @yajra and anyone knows my problem, please help me to solve this issue.
This is my issue.

This is my view.

adsfafads

It's my script.

    <script>  
        $("#dbutton").click(function()
        {
            $('#servicestable').DataTable( 
                {
                    ajax: {
                        url:'{{route("report.show")}}',  
                              data: function (d) 
                                {
                                    d.from       = $('input   [name=from]').val();
                                    d.to         = $('input   [name=to]').val();
                                    type:      'service'
                                }
                        }, 
                        columns: 
                        [
                            { data: 'number',        name: 'number' },
                            { data: 'name',          name: 'name' },
                            { data: 'description',   name: 'description' },
                            { data: 'income',        name: 'income' },
                            { data: 'rate',          name: 'rate' },
                            { data: 'measure',       name: 'measure' },
                            { data: 'cost_account',  name: 'cost_account' },
                            { data: 'amount',        name: 'amount' },
                        ]
                });
        });
    </script> 

It's my report controller with its functions.

  public function index(Request $equest ,$type)
 {

    if($type == "services")
    {
 	    return view('services.report');
    }
 } 
 public function show(Request $request)
{
  
    if($request->ajax()) // This is check ajax request
    {
        if($request->has('type') && $request->get('type') == 'service')
        {
            if($request->has('from') && $request->has('to'))
            {
                $from   = $request->get('from');
                $to     = $request->get('to');
                  $service=$this->item->getServices($from,$to); 
                  return Datatables::of($service)->make(true);
            }
         
        } 
    } 
}

Its my model codes

 public  function getServices($from , $to)
    {
        return $this->leftjoin('accounts as incomes', 'items.account_id', '=', 'incomes.id')
            ->leftjoin('costs', 'costs.item_id', '=', 'items.id')
            ->leftjoin('measure_units', 'items.um_id', '=', 'measure_units.id')
            ->leftjoin('accounts as cost_accounts', 'costs.account_id', '=', 'cost_accounts.id')
            ->where('items.type','service')
            ->whereBetween('items.created_at',[$from],[$to])
            ->orderBy('item_id', 'desc')
            ->get(
                [
                'items.id',
                'items.um_id',
                'items.number',
                'items.name',
                'items.description',
                'measure_units.name as measure',
                'incomes.name as income',
                'cost_accounts.name as cost_account',
                'items.rate',
                'costs.amount',
                ]);
    }

And finally its my routes.

 Route::get('report/{type}',['as'=>'report.index','uses'=>'ReportController\ReportController@index']); 
 Route::post('report/',['as'=>'report.show','uses'=>'ReportController\ReportController@show']); 

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions