Index.php
1 <?php 2 3 namespace App\Http\Livewire\NonConformity; 4 5 use App\Models\Dossier; 6 use Livewire\Component; 7 use App\Models\NonConformity; 8 use App\Http\Services\NonConformityService; 9 use App\Models\ValidationRequirementResponseType; 10 11 class Index extends Component 12 { 13 public ?string $sortField = 'created_at'; 14 public ?string $sortDirection = 'desc'; 15 public array $filters = [ 16 'created_at_since' => null, 17 'created_at_to' => null, 18 'updated_at_since' => null, 19 'updated_at_to' => null, 20 // 'closure_date_since' => null, 21 // 'closure_date_to' => null, 22 'dossier_id' => null, 23 'status' => null, 24 'type' => [], 25 ]; 26 public ?int $dossierId = null; 27 28 public function mount() 29 { 30 $this->filters['dossier_id'] = $this->dossierId; 31 } 32 public function getNonConformitiesProperty(NonConformityService $service) 33 { 34 return $service->searchNonconformities( 35 $this->sortField, 36 $this->sortDirection, 37 $this->filters 38 ); 39 } 40 41 public function getTypesProperty() 42 { 43 return ValidationRequirementResponseType::all('id', 'name')->map(function ($type) { 44 return [ 45 'id' => $type->id, 46 'name' => $type->getTransalatedName(), 47 ]; 48 }); 49 } 50 51 public function getStatusesProperty() 52 { 53 return [ 54 ['id' => 'Pass', 'name' => 'Cerrada'], 55 ['id' => 'No pass', 'name' => 'Abierta'], 56 ]; 57 } 58 59 60 public function getDossiersProperty() 61 { 62 $dossiers = Dossier::whereIn('id', function ($query) { 63 $query->select('dossier_id') 64 ->from('inbox_files') 65 ->whereIn('validation_id', function ($subQuery) { 66 $subQuery->select('validation_id') 67 ->from('workbook_requirement_validation') 68 ->whereIn('id', function ($subSubQuery) { 69 $subSubQuery->select('validation_requirement_id') 70 ->from('validation_requirement_responses') 71 ->distinct(); 72 }); 73 }); 74 })->get(['id', 'code_year', 'code_seq']); 75 76 return $dossiers; 77 } 78 79 public function fetchData() 80 { 81 $this->readyToLoad = true; 82 } 83 84 public function viewRow($id) 85 { 86 set_dossier_in_session_for_breadcrumb(); 87 $this->redirect(route('non-conformities.view', $id)); 88 } 89 90 public function getCodesProperty() 91 { 92 return NonConformity::all(['code', 'id'])->toArray(); 93 } 94 public function render() 95 { 96 return view('livewire.non-concoformity.index') 97 ->layoutData( 98 [ 99 'title' => 'No conformidades', 100 'breadcrumb' => 'non-conformities.index', 101 ] 102 ); 103 } 104 }