<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesResources;
use Illuminate\Http\Request;
use DB;

use Validator;

class TaxController extends Controller
{
    public function LoadTax()
    {
    	$status= 'Deleted';
		$data['Tax']=DB::table('tax_tax')->where([["tax_status","<>",$status]])->get();
    	return view('tax',compact('data'));
    }
	public function InsertTax(Request $req)
    {
		$tax_id = $req->input('tax_id');
    	$taxtype= $req->input('taxtype');
		$taxpercentage= $req->input('taxpercentage');
		$description= $req->input('description');
		$status = $req->input('status');
		$data = array('tax_type'=>$taxtype,'tax_amt'=>$taxpercentage,'tax_description'=>$description,'tax_status'=>$status);
		
		if($tax_id == 0)
		{
			$insertdetails = DB::table('tax_tax')->insert($data);
			if (!is_null($insertdetails))
			{
				return response()->json(['status' => '1', 'message' => trans('Record Inserted Successfully.')]);
			}
			else
			{
				return response()->json(['status' => '0', 'message' => trans('Error in Insertion.. Please Try again..')]);
			}
		}
		else
		{
			$updatedetails = DB::table('tax_tax')->where('tax_id',$tax_id)->update($data);
			if (!is_null($updatedetails))
			{
				return response()->json(['status' => '1', 'message' => trans('Record Updated Successfully.')]);
			}
			else
			{
				return response()->json(['status' => '0', 'message' => trans('Error in Updation.. Please Try again..')]);
			}
		}
		
    }

    public function EditTax(Request $req)
	{
		$id = $req->id;
		$tax = DB::table('tax_tax')->where(['tax_id'=>$id])->get();
		return response()->json($tax);
	}
	
	public function DeleteTax(Request $req)
	{
		$id = $req->id;
		$status= 'Deleted';
		$data = array('tax_status'=>$status);
	
		$UpdateDetails = DB::table('tax_tax')->where('tax_id',$id)->update($data);
		if (!is_null($UpdateDetails))
		{
			return response()->json(['status' => '1', 'message' => trans('Record Deleted Successfully.')]);
		}
		else
		{
			return response()->json(['status' => '0', 'message' => trans('Error in Deletion.. Please Try again..')]);
		}
	}
}

?>
