- Primary Asset
- Multiple Assets
- Remove Link
One asset can be marked as primary for each work order. This is typically the main equipment being serviced.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Learn how to create, update, and track assets through their lifecycle in MLM CMMS
Navigate to Assets Module
src/pages/admin/AssetsHomePage.tsx:11).Click 'Nuevo activo' Button
src/components/dashboard/admin/assets/AssetsBoard.tsx:477).Fill Asset Details
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}`);
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).Select Asset
src/components/dashboard/admin/assets/AssetsBoard.tsx:667).Click 'Editar seleccionado'
AssetsBoard.tsx:485, AssetsBoard.tsx:743).Modify Fields
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);
changeAssetStatus function instead of updateAsset to ensure status history is properly tracked.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);
changeAssetStatus function (assetsService.ts:179-220) performs these operations:
asset_status_historyimport { 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}`);
});
is_active flag to preserve historical data.
import { deactivateAsset } from '@/services/assetsService';
const result = await deactivateAsset(123);
console.log(`Asset ${result.id} is now inactive: ${result.is_active}`);
import { activateAsset } from '@/services/assetsService';
const result = await activateAsset(123);
console.log(`Asset ${result.id} is now active: ${result.is_active}`);
includeInactive parameter in listAssetOptions (assetsService.ts:57-75).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);
import { setPrimaryAssetForTicket } from '@/services/assetsService';
await setPrimaryAssetForTicket({
ticket_id: 456,
asset_id: 123
});
// Sets is_primary=true for asset 123, false for all others
const assetIds = [101, 102, 103];
for (const assetId of assetIds) {
await linkAssetToTicket({
ticket_id: 456,
asset_id: assetId,
is_primary: false,
created_by: currentUser.id
});
}
import { unlinkAssetFromTicket } from '@/services/assetsService';
await unlinkAssetFromTicket({
ticket_id: 456,
asset_id: 123
});
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"
}
assetsService.ts:266-321):
maintenance_type to ‘CORRECTIVO’ (corrective)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}`);
});
v_asset_tickets provides enriched work order data including location information (assetsService.ts:365-379).
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`);
});
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);
import { deleteAssetMaintenanceLog } from '@/services/assetsService';
await deleteAssetMaintenanceLog(789);
// Permanently removes the log entry
AssetsBoard.tsx:286-333):
AssetsBoard.tsx:399-431):