HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/8.0.30
System: Linux multiplicar 3.10.0-1160.102.1.el7.x86_64 #1 SMP Tue Oct 17 15:42:21 UTC 2023 x86_64
User: root (0)
PHP: 8.0.30
Disabled: NONE
Upload Files
File: /var/www/html/performance.sumar.com.py/app/Http/Livewire/Tableros.php
<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Tablero;
use App\Models\Notificacion;
use Livewire\WithPagination;
use App\Models\Usuariotablero;
use Auth;

class Tableros extends Component{

    use WithPagination;

    protected $queryString = ['buscar' => ['except' => '']];

    protected $paginationTheme = 'bootstrap';

    public $buscar='';

    public $objetivo_id,$objetivos,$indicadores,$meta,$planes,$responsable,$inicio,$fin,$porcentaje,$status;
    
    public $updateMode = false;

    public function render(){

        $objetivoss=Tablero::where('usuario_id',Auth::user()->id)->where('estado',1)
            ->orderBy('id','desc')->paginate(20);
        
        $asignaciones=Usuariotablero::where('evaluador_id',Auth::user()->id)->count();

        return view('livewire.tableros',["objetivoss" => $objetivoss,"asignaciones" => $asignaciones]);
    }

    private function resetInputFields(){
        $this->objetivo_id='';
        $this->objetivos='';
        $this->indicadores='';
        $this->meta='';
        $this->planes='';
        $this->responsable='';
        $this->inicio='';
        $this->fin='';
        $this->porcentaje=0;
        $this->status='';
    }
 
    public function store()
    {
        $validatedDate = $this->validate([
            'objetivos'=>'required',
            'indicadores'=>'required',
            'meta'=>'required',
            'planes'=>'required',
            'responsable'=>'required',
            'inicio'=>'required',
            'fin'=>'required',
            'porcentaje'=>'required',            
            'status'=>'required',        
        ]);
 
        Tablero::create([
            'objetivos'=>$this->objetivos,
            'indicadores'=>$this->indicadores,
            'meta'=>$this->meta,
            'planes'=>$this->planes,
            'responsable'=>$this->responsable,
            'inicio'=>$this->inicio,
            'fin'=>$this->fin,
            'porcentaje'=>$this->porcentaje,            
            'status'=>$this->status, 
            'usuario_id' => Auth::user()->id,
        ]);
        if($evaluador=Usuariotablero::where('evaluado_id',Auth::user()->id)->first()){
            Notificacion::create([
                'usuario_id' => $evaluador->evaluador_id,
                'mensaje' => Auth::user()->name.' ha agregado un nuevo objetivo.',
                'enlace' => '/admin/tableros/vertableros/'.Auth::user()->id,
            ]);
        }
 
        $this->emit('alert', ['type' => 'success', 'message' => 'Objetivo creado correctamente.']);
        
        $this->resetInputFields();
        $this->emit('cerrarmodal');
 
    }
 
    public function edit($id)
    {
        $this->updateMode = true;
        $objetivo = Tablero::find($id);

        $this->objetivo_id = $objetivo->id;
        $this->objetivos=$objetivo->objetivos;
        $this->indicadores=$objetivo->indicadores;
        $this->meta=$objetivo->meta;
        $this->planes=$objetivo->planes;
        $this->responsable=$objetivo->responsable;
        $this->inicio=$objetivo->inicio;
        $this->fin=$objetivo->fin;
        $this->porcentaje=$objetivo->porcentaje;            
        $this->status=$objetivo->status; 
    }
 
    public function cancel(){
        $this->updateMode = false;
        $this->emit('cerrarmodal');
        $this->resetInputFields();
    }
 
    public function update()
    {
        $validatedDate = $this->validate([
            'objetivos'=>'required',
            'indicadores'=>'required',
            'meta'=>'required',
            'planes'=>'required',
            'responsable'=>'required',
            'inicio'=>'required',
            'fin'=>'required',
            'porcentaje'=>'required',            
            'status'=>'required',
        ]);
 
        if ($this->objetivo_id) {
            $objetivo = Tablero::find($this->objetivo_id);
            $objetivo->update([
                'objetivos'=>$this->objetivos,
                'indicadores'=>$this->indicadores,
                'meta'=>$this->meta,
                'planes'=>$this->planes,
                'responsable'=>$this->responsable,
                'inicio'=>$this->inicio,
                'fin'=>$this->fin,
                'porcentaje'=>$this->porcentaje,            
                'status'=>$this->status, 
            ]);
            $this->updateMode = false;
            $this->emit('alert', ['type' => 'info', 'message' => 'Objetivo actualizado correctamente.']);
            $this->resetInputFields();
            $this->emit('cerrarmodal');
 
        }
    }
 
    public function delete($id){
        if($id){
            $objetivo = Tablero::find($id);
            $objetivo->update([
                'estado' => 0,
            ]);
            $this->emit('alert', ['type' => 'error', 'message' => '¡Objetivo eliminado correctamente.!']);
        }
    }
}