<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Allowance;
use Input;
use Excel;
use PDF;


class PayslipController extends Controller
{
    
    public function index(){
        Return view('Payslip.index');
    }

    public function process_payslip(Request $request){
        #Get the user details of this employee
        #Pull payslip details for given year
        #Return results
        $employee = DB::table('main_users')
            ->where('id', $request->userId)
            ->first();

        $payslip = DB::table('payslips')
            ->where([
                ['user_id', $employee->id],
                ['year', $request->year],
                ['month', $request->month]
            ])
            ->get();

        return view('Payslip.payslip', compact(['employee', 'payslip']));
    } 
    public function downloadPDF($id){
        $allowance = Allowance::find($id);
  
        $pdf = PDF::loadView('pdf', compact('user'));
        return $pdf->download('Payslip.pdf');
  
      }
  

    

}
