<?php

namespace App\Http\Controllers\Endocapture;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use DB;
// use Excel;
use App\Imports\scopeinformationImport;
use App\Imports\preventiveImport;
use App\Imports\repairImport;
use App\Imports\trainingImport;
use Maatwebsite\Excel\Facades\Excel;

class ScopeinformationController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('track.import');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $r)
    {
        try {
            if(isset($r->scope)){
                Excel::import(new scopeinformationImport,$r->file('file')->store('temp'));
            }elseif(isset($r->ptrventive)){
                Excel::import(new preventiveImport,$r->file('file_pm')->store('temp'));
            }elseif(isset($r->repair)){
                Excel::import(new repairImport,$r->file('file_repair')->store('temp'));
            }elseif(isset($r->training)){
                Excel::import(new trainingImport,$r->file('file_training')->store('temp'));
            }
            return redirect()->back();
        } catch(\Throwable $e) {
            return redirect('track/create?alert=1');
        }

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
