<?php

namespace Modules\Lpj\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
    use Maatwebsite\Excel\Facades\Excel;
use Modules\Lpj\Exports\LaporanUserLimitExport;
use Modules\Lpj\Services\LaporanUserService;

class LaporanUserController extends Controller
{


    private $laporanUserService;

    public function __construct(LaporanUserService $laporanUserService)
    {
        $this->laporanUserService = $laporanUserService;
    }

    /**
     * Display a listing of the resource.
     */
    public function index()
    {
        // $user = $this->laporanUserService->getUserPemohon();
        return view('lpj::laporan-user.index');
    }

    public function searchUserPemohon(Request $request)
    {
        $search = $request->get('search');
        $user = $this->laporanUserService->getUserPemohon($search);
        return response()->json($user);
    }

    public function dataTableForUserPemohon(Request $request)
    {
        return $this->laporanUserService->dataForDatatables($request);
    }

     public function export(Request $request)
    {
        $startDate = $request->start_date;
        $endDate = $request->end_date;
        // name of the file
        $fileName = 'laporan_user_limit' . $startDate . '_' . $endDate . '.xlsx';
        return Excel::download(new LaporanUserLimitExport($request), $fileName);
    }
}
