Skip to main content

Overview

The Activo model represents physical assets (furniture, equipment) that are managed within the GIMA system. Each asset is linked to an article definition, has a location, tracks its operational state, and maintains relationships with maintenance records and reports.

Model Information

table
string
default:"activos"
Database table name
namespace
string
App\Models\Activo

Fillable Fields

The following fields can be mass-assigned:
articulo_id
integer
required
Foreign key reference to the articulos table. Links this asset to its article definition (model, brand, specifications).
ubicacion_id
integer
required
Foreign key reference to the ubicaciones table. Specifies where this asset is physically located.
estado
enum
default:"operativo"
Current operational status of the asset. Uses the EstadoActivo enum.Possible values:
  • operativo - Asset is operational
  • mantenimiento - Asset is under maintenance
  • fuera_servicio - Asset is out of service
  • baja - Asset has been decommissioned
valor
float
default:"null"
Monetary value of the asset. Can be null if value is not specified.

Casts

The model automatically casts the following attributes:
protected $casts = [
    'estado' => EstadoActivo::class,  // Cast to enum
    'valor' => 'float',               // Cast to float
];

Relationships

Belongs To

articulo

Returns the article definition (Articulos model) that this asset is based on.
$activo = Activo::find(1);
$articulo = $activo->articulo;

echo $articulo->modelo;  // Access article model name
echo $articulo->marca;   // Access article brand
Relationship Details:
  • Type: BelongsTo
  • Related Model: App\Models\Articulos
  • Foreign Key: articulo_id

ubicacion

Returns the location (Ubicacion model) where this asset is physically located.
$activo = Activo::find(1);
$ubicacion = $activo->ubicacion;

echo $ubicacion->nombre;  // Access location name
Relationship Details:
  • Type: BelongsTo
  • Related Model: App\Models\Ubicacion
  • Foreign Key: ubicacion_id

Has Many

calendarioMantenimientos

Returns all scheduled maintenance entries for this asset.
$activo = Activo::find(1);
$calendarios = $activo->calendarioMantenimientos;

foreach ($calendarios as $calendario) {
    echo $calendario->fecha_programada;
}
Relationship Details:
  • Type: HasMany
  • Related Model: App\Models\CalendarioMantenimiento
  • Foreign Key: activo_id

mantenimientos

Returns all maintenance records associated with this asset.
$activo = Activo::find(1);
$mantenimientos = $activo->mantenimientos;

foreach ($mantenimientos as $mantenimiento) {
    echo $mantenimiento->tipo;  // preventivo, correctivo, predictivo
    echo $mantenimiento->estado;
}
Relationship Details:
  • Type: HasMany
  • Related Model: App\Models\Mantenimiento
  • Foreign Key: activo_id

reportes

Returns all reports filed for this asset.
$activo = Activo::find(1);
$reportes = $activo->reportes;

foreach ($reportes as $reporte) {
    echo $reporte->descripcion;
    echo $reporte->prioridad;
}
Relationship Details:
  • Type: HasMany
  • Related Model: App\Models\Reporte
  • Foreign Key: activo_id

Usage Examples

Creating a New Asset

use App\Models\Activo;
use App\Enums\EstadoActivo;

$activo = Activo::create([
    'articulo_id' => 1,
    'ubicacion_id' => 5,
    'estado' => EstadoActivo::OPERATIVO,
    'valor' => 1500.50,
]);

Updating Asset State

use App\Enums\EstadoActivo;

$activo = Activo::find(1);
$activo->estado = EstadoActivo::MANTENIMiENTO;
$activo->save();

// Using enum label
echo $activo->estado->label(); // "En mantenimiento"

Querying Assets with Relationships

// Get all operational assets with their locations
$activos = Activo::with('ubicacion')
    ->where('estado', EstadoActivo::OPERATIVO)
    ->get();

// Get asset with all maintenance history
$activo = Activo::with('mantenimientos.tecnicoPrincipal')
    ->find(1);

// Get assets that have pending reports
$activosConReportes = Activo::whereHas('reportes', function($query) {
    $query->where('estado', 'abierto');
})->get();

Accessing Nested Relationships

$activo = Activo::with(['articulo', 'ubicacion', 'mantenimientos'])->find(1);

// Access article details
echo "Modelo: {$activo->articulo->modelo}";
echo "Marca: {$activo->articulo->marca}";

// Access location
echo "Ubicación: {$activo->ubicacion->nombre}";

// Access maintenance records
foreach ($activo->mantenimientos as $mant) {
    echo "Tipo: {$mant->tipo}, Estado: {$mant->estado}";
}

Database Schema

CREATE TABLE activos (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    articulo_id BIGINT UNSIGNED NOT NULL,
    estado VARCHAR(255) DEFAULT 'operativo',
    ubicacion_id BIGINT UNSIGNED NOT NULL,
    valor FLOAT NULL,
    created_at TIMESTAMP NULL,
    updated_at TIMESTAMP NULL,
    
    FOREIGN KEY (articulo_id) REFERENCES articulos(id),
    FOREIGN KEY (ubicacion_id) REFERENCES ubicaciones(id)
);
  • Mantenimiento - Maintenance records for assets
  • Reporte - Issue reports for assets
  • User - Users who interact with assets

Build docs developers (and LLMs) love