171 lines
5.7 KiB
PHP
171 lines
5.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Cetaklabel\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Modules\Cetaklabel\Entities\Approval;
|
|
use Modules\Cetaklabel\DataTables\DocumentTypeDataTable;
|
|
use Modules\Cetaklabel\Entities\DocumentType;
|
|
use Modules\Cetaklabel\Http\Requests\DocumentType\StoreDocumentTypeRequest;
|
|
use Modules\Cetaklabel\Http\Requests\DocumentType\UpdateDocumentTypeRequest;
|
|
|
|
class DocumentTypeController 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(DocumentTypeDataTable $dataTable)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.read')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to view any master data !');
|
|
}
|
|
|
|
return $dataTable->render('cetaklabel::masters.document-type.index');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreDocumentTypeRequest $request)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.create')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
}
|
|
|
|
// Validate the request...
|
|
$validated = $request->validated();
|
|
|
|
// Store the Document Type...
|
|
if ($validated) {
|
|
try {
|
|
$approval = [
|
|
'method' => 'create',
|
|
'menu' => 'DocumentType',
|
|
'new_request' => json_encode($validated),
|
|
'description' => 'Create new Document Type',
|
|
'status' => '0',
|
|
];
|
|
|
|
Approval::create($approval);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document Type created successfully.']);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Document Type created failed.']);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Document Type created failed.']);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.create')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to create any master data !');
|
|
}
|
|
|
|
abort(404);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(DocumentType $document_type)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.read')) {
|
|
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)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.update')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
}
|
|
|
|
$document_type = DocumentType::find($id);
|
|
echo json_encode($document_type);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdateDocumentTypeRequest $request, DocumentType $document_type)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.update')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to update any master data !');
|
|
}
|
|
|
|
// Validate the request...
|
|
$validated = $request->validated();
|
|
|
|
// Update the Directorat...
|
|
if ($validated) {
|
|
try {
|
|
$approval = [
|
|
'method' => 'update',
|
|
'menu' => 'DocumentType',
|
|
'new_request' => json_encode($validated),
|
|
'old_request' => json_encode($document_type),
|
|
'description' => 'Update Document Type',
|
|
'status' => '0',
|
|
];
|
|
|
|
Approval::create($approval);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document Type updated successfully.']);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['status' => 'error', 'message' => 'Document Type updated failed.']);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Document Type updated failed.']);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(DocumentType $document_type)
|
|
{
|
|
if (is_null($this->user) || !$this->user->can('master.delete')) {
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any master data !');
|
|
}
|
|
|
|
$approval = [
|
|
'method' => 'delete',
|
|
'menu' => 'DocumentType',
|
|
'old_request' => json_encode($document_type),
|
|
'description' => 'Delete Document Type',
|
|
'status' => '0',
|
|
];
|
|
|
|
Approval::create($approval);
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Document Type deleted successfully.']);
|
|
}
|
|
}
|