2023-06-14 09:20:32 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Modules\Cetaklabel\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Exception;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use Modules\Cetaklabel\DataTables\CardboardDetailDataTable;
|
2023-06-14 10:38:30 +00:00
|
|
|
use Modules\Cetaklabel\DataTables\CardboardOdnerDataTable;
|
2023-06-14 09:20:32 +00:00
|
|
|
use Modules\Cetaklabel\Entities\CardboardDetail;
|
|
|
|
|
|
|
|
class CardboardDetailController 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 Cardboards.
|
|
|
|
*
|
|
|
|
* @param \App\DataTables\CardboardDetailDataTable $dataTable
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2023-06-15 09:41:25 +00:00
|
|
|
public function index(CardboardOdnerDataTable $dataTable, Request $request)
|
2023-06-14 09:20:32 +00:00
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.read')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any document data !');
|
|
|
|
}
|
|
|
|
|
2023-06-15 09:41:25 +00:00
|
|
|
$cardboard_id = $request->id;
|
|
|
|
$current_odner = CardboardDetail::where('cardboard_id', $cardboard_id)->count();
|
2023-07-07 00:57:32 +00:00
|
|
|
$odners = CardboardDetail::where('cardboard_id', $cardboard_id)->pluck('document_id')->toArray();
|
|
|
|
$odners = json_encode($odners);
|
2023-06-15 09:41:25 +00:00
|
|
|
|
2023-07-07 00:57:32 +00:00
|
|
|
return $dataTable->render('cetaklabel::app.cardboard-detail.odner', compact('cardboard_id', 'current_odner','odners'));
|
2023-06-14 09:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created Cardboard in storage.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.create')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any document data !');
|
|
|
|
}
|
|
|
|
|
2023-06-15 09:41:25 +00:00
|
|
|
$documents = explode(',', $request->document_id);
|
|
|
|
|
|
|
|
print_r($documents);
|
|
|
|
|
|
|
|
foreach ($documents as $document) {
|
|
|
|
$data = [
|
|
|
|
'cardboard_id' => $request->cardboard_id,
|
|
|
|
'document_id' => $document
|
|
|
|
];
|
2023-06-14 09:20:32 +00:00
|
|
|
|
|
|
|
try {
|
2023-06-15 09:41:25 +00:00
|
|
|
CardboardDetail::updateOrCreate($data);
|
2023-06-14 09:20:32 +00:00
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Cardboard created successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Cardboard created failed.']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new Cardboard.
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.create')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to create any document data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified Cardboard.
|
|
|
|
*
|
|
|
|
* @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail
|
|
|
|
*/
|
|
|
|
public function show(CardboardDetailDataTable $dataTable)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.read')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to view any document data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $dataTable->render('cetaklabel::app.cardboard-detail.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified Cardboard.
|
|
|
|
*
|
|
|
|
* @param $id
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.update')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any document data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$cardboard = CardboardDetail::find($id);
|
|
|
|
echo json_encode($cardboard);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified Cardboard in storage.
|
|
|
|
*
|
|
|
|
* @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function update(Request $request, CardboardDetail $cardboard_detail)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.update')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to update any document data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the request...
|
|
|
|
$validated = $request->validated();
|
|
|
|
|
|
|
|
// Update the Cardboard...
|
|
|
|
if ($validated) {
|
|
|
|
try {
|
|
|
|
$cardboard_detail->update($validated);
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Cardboard updated successfully.']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Cardboard updated failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo json_encode(['status' => 'error', 'message' => 'Cardboard updated failed.']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified Cardboard from storage.
|
|
|
|
*
|
|
|
|
* @param \Modules\Cetaklabel\Entities\CardboardDetail $cardboard_detail
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function destroy(CardboardDetail $cardboard_detail)
|
|
|
|
{
|
|
|
|
if (is_null($this->user) || !$this->user->can('document.delete')) {
|
|
|
|
abort(403, 'Sorry !! You are Unauthorized to delete any document data !');
|
|
|
|
}
|
|
|
|
|
|
|
|
$cardboard_detail->delete();
|
|
|
|
echo json_encode(['status' => 'success', 'message' => 'Cardboard deleted successfully.']);
|
|
|
|
}
|
|
|
|
}
|