CasperSecurity
<?php
namespace App\Http\Livewire\Documentmanagement;
use App\Models\DocumentClassification;
use App\Models\DocumentPermission;
use App\Models\DocumentType;
use App\Models\EmployeeRegistration;
use App\Models\StoreDocument;
use App\Models\Team;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\User;
class DocumentPermissionLivewire extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public $search;
public $perPage = 10;
public $orderBy = 'id';
public $orderAsc = '1';
public $store_doc_id, $pemission_level, $department_id,$view_flag,$download_flag,$employee_id ,$status;
public $modelid;
public $showmodal = false;
public $successmsg = "The Document permission has been submit successfully.";
/* public $rejectmsg = "The Od Type data has been rejetct successfully.";*/
public $errormsg = "Sorry !!! Something went wrong. Please Try Again.";
protected $listeners = ['submit'];
public function closemodalclick()
{
$this->showmodal = false;
$this->resetValidation();
}
public function showmodalclick()
{
$this->resetValidation();
$this->cleanVar();
$this->showmodal=true;
}
public function cleanVar()
{
$this->modelid = null;
$this->status = null;
$this->showmodal = false;
}
public function submitclick()
{
/* $response = StoreDocument::where('id', $this->store_doc_id)->first();*/
// Create a new DocumentPermission record
$permission = DocumentPermission::create([
'store_doc_id' => $response->id,
'pemission_level' => $this->pemission_level,
'department_id' => $this->department_id,
'employee_id' => $this->employee_id,
'view_flag' => $this->view_flag,
'download_flag' => $this->download_flag,
]);
//dd($permission);
if ($permission) {
$permission->update([
'view_flag' => true,
'download_flag' => true,
]);
}
$response->update(['doc_status' => 2]);
$this->dispatchBrowserEvent('closeOffCanvas');
$this->dispatchBrowserEvent('showsuccessmsg', [
'type' => 'success',
'message' => 'Document permission has been given'
]);
}
public function read()
{
$store_documents = StoreDocument::all();
/*foreach ($store_documents as $document) {
$hasPermissions = DocumentPermission::where('store_doc_id', $document->id)->exists();
if ($hasPermissions) {
$document->update(['status' => 2]);
}
}*/
return $store_documents;
}
public function render()
{
$datatable=[];
$datatable = $this->read();
if (sizeof($datatable) > 0) {
foreach ($datatable as $key => $data) {
$type = DocumentType::where('id', $data['document_type_id'])->first();
if ($type) {
$datatable[$key]['document_type'] = $type->document_type; // Store driver's name in driver_id column
} else {
$datatable[$key]['document_type'] = "NA";
}
}
foreach ($datatable as $key => $data) {
$doc = DocumentClassification::where('id',$data['doc_classification_id'])->first();
if($doc){
$datatable[$key]['classification_doc'] =$doc->classification_doc;
}
else{
$datatable[$key]['classification_doc'] ="NA";
}
}
}
/* $ledgertype=LedgerheadType::where('status',1)->get();*/
$doctype = DocumentType::where('status',1)->get();
$classdoc = DocumentClassification::where('status',1)->get();
$users = User::where('id', '>', 1)->get();
$department = Team::where('id', '>', 1)->get();
$employee = EmployeeRegistration::where('id', '>', 1)->get();
return view('livewire.documentmanagement.document-permission-livewire',compact('datatable','users','department','employee','doctype','classdoc'));
}
}