<?php

namespace App\Http\Controllers;


use App\Models\IqCallHistory;

use App\Services\ViewExport;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;


class HistoryController extends Controller
{

    public function __construct()
    {

    }

    public function Index(Request $request)
    {
        $items = empty($request->pageLimit) ? config('constant.PAGINATION_LIMIT'):$request->pageLimit;

        $searchData=[
            'pageLimit'=>$items,
            'status_code'=>$request['status_code'],
            'fdate'=>$request['fdate'],
            'tdate'=>$request['tdate']
        ];


        $histories =(new IqCallHistory())->getHistories($searchData) ;
        if(!empty($request['export']) && $request['export'] == 1)
        {
            return Excel::download(new ViewExport($histories,'partials.iq_call_histories'), 'IqCallHistories.xlsx');
        }
        return view('history.list',compact('histories','searchData'));
    }



}
