<?php

namespace App\Http\Controllers;
use Yajra\Datatables\Html\Builder;
use Yajra\Datatables\Facades\Datatables;
use App\BeliLog;
use Illuminate\Http\Request;

class StatisticsController extends Controller
{
  if ($request->ajax()) {
         $stats = BeliLog::with('menus','user');

         return Datatables::of($stats)
             ->addColumn('dibatalkan', function($stat){
                 if ($stat->dibatalkan) {
                     return $stat->updated_at;
                 }
                 return "Pesanan Dibatalkan";
             })->make(true);
     }

     $html = $htmlBuilder
         ->addColumn(['data' => 'menus.title', 'name'=>'menus.title', 'title'=>'Menu'])
         ->addColumn(['data' => 'user.name', 'name'=>'user.name', 'title'=>'Pemesan'])
         ->addColumn(['data' => 'created_at', 'name'=>'created_at', 'title'=>'Tanggal Pesan', 'searchable'=>false])
         ->addColumn(['data' => 'returned_at', 'name'=>'returned_at', 'title'=>'Tanggal Kembali',
'orderable'=>false, 'searchable'=>false]);

     return view('statistics.index')->with(compact('html'));
 }
}
