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\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2023-07-21 09:37:07 +00:00
|
|
|
use Modules\Cetaklabel\Entities\Approval;
|
2023-05-20 14:09:49 +00:00
|
|
|
use Modules\Cetaklabel\DataTables\SubSubJobDataTable;
|
|
|
|
use Modules\Cetaklabel\Entities\Directorat;
|
|
|
|
use Modules\Cetaklabel\Entities\SubSubJob;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\SubSubJob\StoreSubSubJobRequest;
|
|
|
|
use Modules\Cetaklabel\Http\Requests\SubSubJob\UpdateSubSubJobRequest;
|
2023-05-15 10:03:46 +00:00
|
|
|
|
|
|
|
class SubSubJobController 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 Sub Sub Jobs.
|
|
|
|
*
|
2023-05-20 14:09:49 +00:00
|
|
|
* @param \Modules\Cetaklabel\DataTables\SubSubJobDataTable $dataTable
|
2023-05-15 10:03:46 +00:00
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return mixed|void
|
|
|
|
*/
|
|
|
|
public function index(SubSubJobDataTable $dataTable, Request $request)
|
|
|
|
{
|
|
|
|
if (isset($request->sub_job_id) && !empty($request->sub_job_id)) {
|
|
|
|
$this->show($request);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-20 02:42:53 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.read')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
|
|
}
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
addVendor('chained-select');
|
|
|
|
|
|
|
|
$directorat = Directorat::all();
|
|
|
|
return $dataTable->render('cetaklabel::masters.sub-sub-job.index', compact('directorat'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lists the specified Sub Sub Job by Sub Job ID.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function show(Request $request)
|
|
|
|
{
|
|
|
|
|
|
|
|
$subSubJob = SubSubJob::where('sub_job_id', $request->sub_job_id)->get();
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
foreach ($subSubJob as $row) {
|
|
|
|
$result = [
|
|
|
|
$row->id => $row->name,
|
|
|
|
];
|
|
|
|
|
|
|
|
$data[] = $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Sub Sub Job in storage.
|
|
|
|
*
|
2023-05-20 14:09:49 +00:00
|
|
|
* @param \Modules\Cetaklabel\Http\Requests\SubSubJob\StoreSubSubJobRequest $request
|
2023-05-15 10:03:46 +00:00
|
|
|
*
|
|
|
|
* @return false
|
|
|
|
*/
|
|
|
|
public function store(StoreSubSubJobRequest $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 SubSubJob...
|
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-07-20 02:42:53 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'create',
|
|
|
|
'model' => 'SubSubJob',
|
|
|
|
'new_request' => json_encode($validated),
|
|
|
|
'description' => 'Create new Sub Sub Job',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Sub Job created successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Sub Sub Job created failed.']);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Sub Sub Job 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$subJob = SubSubJob::find($id);
|
|
|
|
echo json_encode($subJob);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*/
|
|
|
|
public function update(UpdateSubSubJobRequest $request, SubSubJob $subSubJob)
|
|
|
|
{
|
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 SubSubJob...
|
|
|
|
if ($validated) {
|
|
|
|
try {
|
2023-07-20 02:42:53 +00:00
|
|
|
$approval = [
|
|
|
|
'method' => 'update',
|
|
|
|
'model' => 'SubSubJob',
|
|
|
|
'new_request' => json_encode($validated),
|
|
|
|
'old_request' => json_encode($subSubJob),
|
|
|
|
'description' => 'Update Sub Sub Job',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Sub Job updated successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
//return redirect()->route('job.index')->with('error', 'SubSubJob updated failed.');
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Sub Sub Job updated failed.']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*/
|
|
|
|
public function destroy(SubSubJob $subSubJob)
|
|
|
|
{
|
2023-07-20 02:42:53 +00:00
|
|
|
if (is_null($this->user) || !$this->user->can('master.delete')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any master data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$approval = [
|
|
|
|
'method' => 'delete',
|
|
|
|
'model' => 'SubSubJob',
|
|
|
|
'old_request' => json_encode($subSubJob),
|
|
|
|
'description' => 'Delete Sub Sub Job',
|
|
|
|
'status' => '0',
|
|
|
|
];
|
|
|
|
|
|
|
|
Approval::create($approval);
|
|
|
|
|
2023-05-15 10:03:46 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Sub Sub Job deleted successfully.']);
|
|
|
|
}
|
|
|
|
}
|