<?php

namespace App\Http\Controllers\Hr;

use App\Http\Controllers\Controller;
use App\Models\EmployeeTaxBand;
use Illuminate\Http\Request;

class EmployeeTaxBandController extends Controller
{
    public function index()
    {
        $bands = EmployeeTaxBand::orderBy('from', 'ASC')->get();

        return view('hr.employees.setup-tax-calculator', compact('bands'));
    }

    /**Display popup window to Add a New Tax Band**/
    public function showAddTaxBand(){
        return view('hr.employees.add-tax-band');
    }

    /**Store the Tax Band Entry**/
    public function storeAddTaxBand(Request $request)
    {
        $from = $request['from'];
        $to = $request['to'];
        $rate = $request['rate'];

        $create = EmployeeTaxBand::create([
            'from' => $from,
            'to' => $to,
            'rate' => $rate,
            'created_by' => auth()->user()->id,
        ]);

        $res = 'error';
        if($create){
            $res = 'success';
        }
        return $res;
    }
}
