<?php

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

use Illuminate\Http\Request;
use App\Http\Requests\TaxRequest;
use Illuminate\Contracts\Encryption\DecryptException;

use App\User;
use App\Tax;

class TaxController extends Controller
{
public function index()
    {   
        $tax = new Tax;
        
        return view('hr.tax.manage_tax',
        	[

        		'tax_list'       => $tax->gettaxList(),
        		
        	]
    );
       
    }

    public function storeTax(TaxRequest $request)
    {
        $tax = new Tax;

        $curr_tax = $tax->storeTax($request->input());

        if(isset($curr_tax->id))
        {
            parent::setLogMessage('tax "'.$curr_tax->title.'" has been created');

            parent::successMessage('Tax has been created.',parent::getLogMessage());
        }

        return redirect('tax');
    }


     public function updateTax(TaxRequest $request)
    {
 
        try 
        {
            $id = decrypt($request->tax);

            $tax = new Tax;


            $curr_tax = $tax->updateTax($request->input(),$id);

            if(isset($curr_tax))
            {
                parent::setLogMessage('Tax "'.$curr_tax->title.'" has been updated');

                parent::successMessage('Tax has been updated.',parent::getLogMessage());
            }
        } 
        catch (DecryptException $e) 
        {
            
        }

        return redirect('tax');
    }    
}
