2023-05-15 10:03:46 +00:00
|
|
|
<?php
|
|
|
|
|
2023-05-20 14:09:49 +00:00
|
|
|
namespace Modules\Cetaklabel\Http\Controllers;
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Exception;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-07-20 02:42:53 +00:00
|
|
|
use Modules\Approval\Entities\Approval;
|
2023-05-20 14:09:49 +00:00
|
|
|
use Modules\Cetaklabel\DataTables\SpecialCodeDataTable;
|
|
|
|
use Modules\Cetaklabel\Entities\SpecialCode;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\SpecialCode\StoreSpecialCodeRequest;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\SpecialCode\UpdateSpecialCodeRequest;
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
class SpecialCodeController extends Controller
|
|
|
|
{
|
|
|
|
public $user;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware(function ($request, $next) {
|
|
|
|
$this->user = Auth::guard('web')->user();
|
|
|
|
return $next($request);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*/
|
|
|
|
public function index(SpecialCodeDataTable $dataTable)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.read')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dataTable->render('cetaklabel::masters.special-code.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*/
|
|
|
|
public function store(StoreSpecialCodeRequest $request)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.create')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
// Store the Special Code...
|
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-07-20 02:42:53 +00:00
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'create',
|
|
|
|
'model' => 'SpecialCode',
|
|
|
|
'new_request' => json_encode($validated),
|
|
|
|
'description' => 'Create new Special Code',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code created successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code created failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code created failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.create')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*/
|
|
|
|
public function show(SpecialCode $special_code)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.read')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.update')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$special_code = SpecialCode::find($id);
|
|
|
|
echo json_encode($special_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
|
|
|
public function update(UpdateSpecialCodeRequest $request, SpecialCode $special_code)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.update')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
// Update the Directorat...
|
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-07-20 02:42:53 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'update',
|
|
|
|
'model' => 'SpecialCode',
|
|
|
|
'new_request' => json_encode($validated),
|
|
|
|
'old_request' => json_encode($special_code),
|
|
|
|
'description' => 'Update Special Code',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code updated successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code updated failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Special Code updated failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy(SpecialCode $special_code)
|
|
|
|
{
|
2023-06-08 08:12:23 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.delete')) {
|
2023-05-15 10:03:46 +00:00
|
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any master data !');
|
|
|
|
}
|
|
|
|
|
2023-07-20 02:42:53 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
|
|
|
'model' => 'SpecialCode',
|
|
|
|
'old_request' => json_encode($special_code),
|
|
|
|
'description' => 'Delete Special Code',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Special Code deleted successfully.']);
|
|
|
|
}
|
|
|
|
}
|