Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/EdgarJr30/proyecto-de-grado-cms/llms.txt

Use this file to discover all available pages before exploring further.

Creating Assets

Assets can be created through the Assets Board interface, which provides a comprehensive form for capturing all asset details.
1

Navigate to Assets Module

Access the assets page from the main navigation. The interface shows the “Maestro de activos” (Asset Master) board with an ERP-style operational view (src/pages/admin/AssetsHomePage.tsx:11).
2

Click 'Nuevo activo' Button

The create button is located in the header section of the Assets Board (src/components/dashboard/admin/assets/AssetsBoard.tsx:477).
3

Fill Asset Details

Complete the asset form with required and optional information:Required Fields:
  • Code (unique identifier)
  • Name
  • Status
  • Criticality (1-5)
Optional Fields:
  • Description
  • Location
  • Category
  • Manufacturer, Model, Serial Number
  • Purchase and installation dates
  • Financial information (cost, salvage value)
  • Warranty end date
4

Save the Asset

The system validates the data and creates the asset record. New assets are immediately available in the asset list.

Programmatic Asset Creation

Assets can also be created programmatically using the assetsService:
import { createAsset } from '@/services/assetsService';
import type { AssetInsert } from '@/types/Asset';

const newAsset: AssetInsert = {
  code: 'HVAC-101',
  name: 'Rooftop Air Conditioning Unit',
  description: 'Main HVAC unit for Building A',
  location_id: 5,
  category_id: 2,
  asset_type: 'HVAC',
  criticality: 4,
  status: 'OPERATIVO',
  is_active: true,
  manufacturer: 'Carrier',
  model: 'AquaEdge 19DV',
  serial_number: 'SN-2024-HVAC-101',
  asset_tag: 'TAG-HVAC-101',
  purchase_date: '2024-01-15',
  install_date: '2024-02-01',
  warranty_end_date: '2026-01-15',
  purchase_cost: 25000.00,
  salvage_value: 5000.00,
  image_url: null
};

const asset = await createAsset(newAsset);
console.log(`Asset created with ID: ${asset.id}`);
The createAsset function is defined in src/services/assetsService.ts:90-98 and automatically handles timestamp fields (created_at, updated_at) and audit fields (created_by, updated_by).

Updating Assets

Asset information can be updated through the edit form or programmatically.

UI-Based Updates

1

Select Asset

Click on any asset row in the assets table to select it. The selected asset is highlighted with an indigo background (src/components/dashboard/admin/assets/AssetsBoard.tsx:667).
2

Click 'Editar seleccionado'

The edit button is available in the header toolbar and in the detail panel (AssetsBoard.tsx:485, AssetsBoard.tsx:743).
3

Modify Fields

Update any asset field including status, location, technical specifications, or preventive maintenance configuration.
4

Save Changes

Changes are persisted to the database and the asset list is refreshed.

Programmatic Updates

import { updateAsset } from '@/services/assetsService';
import type { AssetUpdate } from '@/types/Asset';

const updates: AssetUpdate = {
  id: 123,
  status: 'EN_MANTENIMIENTO',
  location_id: 8,
  updated_by: currentUser.id
};

const updatedAsset = await updateAsset(updates);
When changing asset status, use the changeAssetStatus function instead of updateAsset to ensure status history is properly tracked.

Managing Asset Status

Asset status changes should always be tracked in the status history table.

Status Change Workflow

import { changeAssetStatus } from '@/services/assetsService';

// Proper way to change status with history tracking
const { asset, history } = await changeAssetStatus({
  asset_id: 123,
  to_status: 'EN_MANTENIMIENTO',
  note: 'Starting annual preventive maintenance cycle'
});

console.log('Status changed from', history.from_status, 'to', history.to_status);
console.log('Changed at:', history.changed_at);
The changeAssetStatus function (assetsService.ts:179-220) performs these operations:
  1. Reads the current asset status
  2. Updates the asset record with the new status
  3. Creates a history entry in asset_status_history
  4. Returns both the updated asset and history record

Viewing Status History

import { getAssetStatusHistory } from '@/services/assetsService';

const history = await getAssetStatusHistory(123);
// Returns array sorted by changed_at DESC

history.forEach(entry => {
  console.log(`${entry.from_status}${entry.to_status}`);
  console.log(`Note: ${entry.note}`);
  console.log(`Changed at: ${entry.changed_at}`);
});

Activating and Deactivating Assets

Assets use soft deletion through the is_active flag to preserve historical data.

Deactivate an Asset

import { deactivateAsset } from '@/services/assetsService';

const result = await deactivateAsset(123);
console.log(`Asset ${result.id} is now inactive: ${result.is_active}`);

Reactivate an Asset

import { activateAsset } from '@/services/assetsService';

const result = await activateAsset(123);
console.log(`Asset ${result.id} is now active: ${result.is_active}`);
Deactivated assets remain in the database but can be filtered out of lists using the includeInactive parameter in listAssetOptions (assetsService.ts:57-75).

Linking Assets to Work Orders

Assets and work orders (tickets) have a many-to-many relationship managed through the ticket_assets junction table.
import { linkAssetToTicket } from '@/services/assetsService';
import type { TicketAssetInsert } from '@/types/Asset';

const link: TicketAssetInsert = {
  ticket_id: 456,
  asset_id: 123,
  is_primary: true,
  created_by: currentUser.id
};

const association = await linkAssetToTicket(link);
One asset can be marked as primary for each work order. This is typically the main equipment being serviced.
import { setPrimaryAssetForTicket } from '@/services/assetsService';

await setPrimaryAssetForTicket({
  ticket_id: 456,
  asset_id: 123
});
// Sets is_primary=true for asset 123, false for all others

Automatic Maintenance Logging

When an asset is linked to a work order, the system can automatically create a maintenance log entry:
import { ensureMaintenanceLogForTicketAsset } from '@/services/assetsService';

const log = await ensureMaintenanceLogForTicketAsset({
  asset_id: 123,
  ticket_id: 456,
  ticket_title: 'Replace oil filter',
  ticket_status: 'En progreso',
  requester: 'John Doe'
});

if (log) {
  console.log('Maintenance log created:', log.summary);
  // Example: "OT #456 - Replace oil filter"
}
This function (assetsService.ts:266-321):
  • Checks if a log entry already exists for this asset-ticket pair
  • Creates a new log entry if needed
  • Sets maintenance_type to ‘CORRECTIVO’ (corrective)
  • Includes ticket details in the summary and details fields

Tracking Asset Work Orders

View all work orders associated with a specific asset:
import { getAssetTicketsView } from '@/services/assetsService';

const tickets = await getAssetTicketsView(123);
// Returns work orders sorted by ID descending

tickets.forEach(ticket => {
  console.log(`Ticket #${ticket.id}: ${ticket.title}`);
  console.log(`Status: ${ticket.status}`);
  console.log(`Location: ${ticket.location_name}`);
});
The view v_asset_tickets provides enriched work order data including location information (assetsService.ts:365-379).

Maintenance Log Management

The maintenance log tracks all maintenance activities performed on an asset.

View Maintenance History

import { getAssetMaintenanceLog } from '@/services/assetsService';

const logs = await getAssetMaintenanceLog(123);
// Returns logs sorted by performed_at DESC

logs.forEach(log => {
  console.log(`${log.maintenance_type}: ${log.summary}`);
  console.log(`Performed: ${log.performed_at}`);
  console.log(`Labor cost: $${log.labor_cost}`);
  console.log(`Parts cost: $${log.parts_cost}`);
  console.log(`Downtime: ${log.downtime_minutes} minutes`);
});

Create Manual Maintenance Entry

import { createAssetMaintenanceLog } from '@/services/assetsService';
import type { AssetMaintenanceLogInsert } from '@/types/Asset';

const logEntry: AssetMaintenanceLogInsert = {
  asset_id: 123,
  ticket_id: null, // Can be null for unscheduled maintenance
  maintenance_type: 'PREVENTIVO',
  summary: 'Quarterly inspection and lubrication',
  details: 'Inspected bearings, replaced lubricant, checked alignment',
  performed_at: new Date().toISOString(),
  performed_by: 'Tech: Maria Garcia',
  labor_cost: 150.00,
  parts_cost: 45.00,
  other_cost: 0,
  downtime_minutes: 120,
  created_by: currentUser.id
};

const log = await createAssetMaintenanceLog(logEntry);

Delete Maintenance Log

import { deleteAssetMaintenanceLog } from '@/services/assetsService';

await deleteAssetMaintenanceLog(789);
// Permanently removes the log entry
Unlike assets, maintenance logs are hard-deleted. Ensure you have proper authorization before deleting maintenance records.

Searching and Filtering Assets

The Assets Board provides comprehensive filtering capabilities (AssetsBoard.tsx:286-333):

Available Filters

Text Search

Search across code, name, model, serial number, asset tag, location, and category

Status Filter

Filter by operational status: Operational, In Maintenance, Out of Service, or Retired

Location Filter

Filter assets by physical location

Preventive Maintenance Filter

Filter by preventive plan status:
  • All assets
  • With active plan
  • Without active plan
  • Due within 30 days
  • Overdue

KPI Dashboard

The asset board displays real-time KPIs (AssetsBoard.tsx:399-431):
  • Total: Total number of filtered assets
  • Operational: Assets with status ‘OPERATIVO’
  • In Maintenance: Assets currently under maintenance
  • Out of Service: Non-operational assets
  • Preventive Plan: Assets with active preventive maintenance plans
  • Due ≤ 30d: Preventive maintenance due within 30 days
  • Overdue: Preventive maintenance past due date

Next Steps

Asset Categories

Organize assets with categories for better classification

Build docs developers (and LLMs) love