202 lines
4.9 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\Controllers\Settings;
2019-11-16 10:21:14 +03:00
use App\Abstracts\Http\Controller;
2017-09-14 22:21:00 +03:00
use App\Http\Requests\Setting\Tax as Request;
2019-11-16 10:21:14 +03:00
use App\Jobs\Setting\CreateTax;
use App\Jobs\Setting\DeleteTax;
use App\Jobs\Setting\UpdateTax;
2017-09-14 22:21:00 +03:00
use App\Models\Setting\Tax;
class Taxes extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$taxes = Tax::collect();
$types = [
2019-11-16 10:21:14 +03:00
'fixed' => trans('taxes.fixed'),
'normal' => trans('taxes.normal'),
'inclusive' => trans('taxes.inclusive'),
2020-07-22 15:11:31 +03:00
'withholding' => trans('taxes.withholding'),
'compound' => trans('taxes.compound'),
];
return view('settings.taxes.index', compact('taxes', 'types'));
2017-09-14 22:21:00 +03:00
}
2018-04-16 13:59:53 +03:00
/**
* Show the form for viewing the specified resource.
*
* @return Response
*/
public function show()
{
2019-11-16 10:21:14 +03:00
return redirect()->route('taxes.index');
2018-04-16 13:59:53 +03:00
}
2017-09-14 22:21:00 +03:00
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
2018-11-06 17:55:31 +03:00
$types = [
2019-11-16 10:21:14 +03:00
'fixed' => trans('taxes.fixed'),
2018-11-06 17:55:31 +03:00
'normal' => trans('taxes.normal'),
2018-11-07 12:07:38 +03:00
'inclusive' => trans('taxes.inclusive'),
2020-07-22 15:11:31 +03:00
'withholding' => trans('taxes.withholding'),
2018-11-06 17:55:31 +03:00
'compound' => trans('taxes.compound'),
];
return view('settings.taxes.create', compact('types'));
2017-09-14 22:21:00 +03:00
}
/**
* Store a newly created resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function store(Request $request)
{
2019-11-16 10:21:14 +03:00
$response = $this->ajaxDispatch(new CreateTax($request));
if ($response['success']) {
$response['redirect'] = route('taxes.index');
$message = trans('messages.success.added', ['type' => trans_choice('general.taxes', 1)]);
flash($message)->success();
} else {
$response['redirect'] = route('taxes.create');
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
$message = $response['message'];
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
flash($message)->error();
}
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
return response()->json($response);
2017-09-14 22:21:00 +03:00
}
/**
* Show the form for editing the specified resource.
*
* @param Tax $tax
*
* @return Response
*/
public function edit(Tax $tax)
{
2018-11-06 17:55:31 +03:00
$types = [
2019-11-16 10:21:14 +03:00
'fixed' => trans('taxes.fixed'),
2018-11-06 17:55:31 +03:00
'normal' => trans('taxes.normal'),
2018-11-07 12:07:38 +03:00
'inclusive' => trans('taxes.inclusive'),
2020-07-22 15:11:31 +03:00
'withholding' => trans('taxes.withholding'),
2018-11-06 17:55:31 +03:00
'compound' => trans('taxes.compound'),
];
return view('settings.taxes.edit', compact('tax', 'types'));
2017-09-14 22:21:00 +03:00
}
/**
* Update the specified resource in storage.
*
2019-11-16 10:21:14 +03:00
* @param Tax $tax
* @param Request $request
2017-09-14 22:21:00 +03:00
*
* @return Response
*/
public function update(Tax $tax, Request $request)
{
2019-11-16 10:21:14 +03:00
$response = $this->ajaxDispatch(new UpdateTax($tax, $request));
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
if ($response['success']) {
$response['redirect'] = route('taxes.index');
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
$message = trans('messages.success.updated', ['type' => $tax->name]);
2017-09-14 22:21:00 +03:00
flash($message)->success();
} else {
2019-11-16 10:21:14 +03:00
$response['redirect'] = route('taxes.edit', $tax->id);
2019-11-16 10:21:14 +03:00
$message = $response['message'];
2019-11-16 10:21:14 +03:00
flash($message)->error();
}
2019-11-16 10:21:14 +03:00
return response()->json($response);
2017-09-14 22:21:00 +03:00
}
2018-06-11 11:53:45 +03:00
/**
* Enable the specified resource.
*
2019-11-16 10:21:14 +03:00
* @param Tax $tax
2018-06-11 11:53:45 +03:00
*
* @return Response
*/
public function enable(Tax $tax)
{
2019-11-16 10:21:14 +03:00
$response = $this->ajaxDispatch(new UpdateTax($tax, request()->merge(['enabled' => 1])));
2018-06-11 11:53:45 +03:00
2019-11-16 10:21:14 +03:00
if ($response['success']) {
$response['message'] = trans('messages.success.enabled', ['type' => $tax->name]);
}
2018-06-11 11:53:45 +03:00
2019-11-16 10:21:14 +03:00
return response()->json($response);
2018-06-11 11:53:45 +03:00
}
/**
* Disable the specified resource.
*
2019-11-16 10:21:14 +03:00
* @param Tax $tax
2018-06-11 11:53:45 +03:00
*
* @return Response
*/
public function disable(Tax $tax)
{
2019-11-16 10:21:14 +03:00
$response = $this->ajaxDispatch(new UpdateTax($tax, request()->merge(['enabled' => 0])));
2018-06-11 11:53:45 +03:00
2019-11-16 10:21:14 +03:00
if ($response['success']) {
$response['message'] = trans('messages.success.disabled', ['type' => $tax->name]);
2018-06-11 11:53:45 +03:00
}
2019-11-16 10:21:14 +03:00
return response()->json($response);
2018-06-11 11:53:45 +03:00
}
2017-09-14 22:21:00 +03:00
/**
* Remove the specified resource from storage.
*
2019-11-16 10:21:14 +03:00
* @param Tax $tax
2017-09-14 22:21:00 +03:00
*
* @return Response
*/
public function destroy(Tax $tax)
{
2019-11-16 10:21:14 +03:00
$response = $this->ajaxDispatch(new DeleteTax($tax));
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
$response['redirect'] = route('taxes.index');
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
if ($response['success']) {
$message = trans('messages.success.deleted', ['type' => $tax->name]);
2017-09-14 22:21:00 +03:00
flash($message)->success();
} else {
2019-11-16 10:21:14 +03:00
$message = $response['message'];
2017-09-14 22:21:00 +03:00
2019-11-16 10:21:14 +03:00
flash($message)->error();
2017-09-14 22:21:00 +03:00
}
2019-11-16 10:21:14 +03:00
return response()->json($response);
2017-09-14 22:21:00 +03:00
}
}