Costs & lifecycle

Work order costs (labor, parts, vendor), roll-ups by asset, location, department, and project, asset lifecycle alerts (warranty, EOL, contract, replacement), and total cost of ownership. Set tenant context before calling these methods.

Overview

The client.costs resource and client.projects support:

  • Work order costs – labor (from time entries), parts, and vendor costs per work order
  • Cost roll-ups – by asset, location, department, or project (views and RPC with optional date filter)
  • Lifecycle alerts – assets with warranty, end-of-life, contract, or planned replacement due within a window
  • Asset TCO – total cost of ownership for a single asset (optional date range)
  • Projects – list and get by ID (read-only); see the Projects page; use projectId when creating work orders for cost roll-up by project

Labor cost comes from work_order_time_entries (e.g. labor_cost_cents). Parts and vendor costs are stored in work_order_parts and work_order_vendor_costs (see database migrations).

Work order costs

Per-work-order cost totals (labor, parts, vendor, total). All amounts are in cents.

client.costs.listWorkOrderCosts()

await client.setTenant(tenantId)
const costs = await client.costs.listWorkOrderCosts()
// Returns WorkOrderCostRow[] with work_order_id, labor_cents, parts_cents, vendor_cents, total_cents

Cost roll-ups

Pre-aggregated costs by dimension (current tenant only).

client.costs.listAssetCosts()

const byAsset = await client.costs.listAssetCosts()
// Returns AssetCostRow[]: asset_id, labor_cents, parts_cents, vendor_cents, total_cents, work_order_count

client.costs.listLocationCosts()

const byLocation = await client.costs.listLocationCosts()
// Returns LocationCostRow[]

client.costs.listDepartmentCosts()

const byDepartment = await client.costs.listDepartmentCosts()
// Returns DepartmentCostRow[] (via work order → asset → department)

client.costs.listProjectCosts()

const byProject = await client.costs.listProjectCosts()
// Returns ProjectCostRow[]

Cost rollup RPC

Roll-up by dimension with optional date filter on work order completed_at. Use when you need a single API that supports date ranges.

client.costs.costRollup(params)

const rows = await client.costs.costRollup({
  tenantId: 'uuid-of-tenant',
  groupBy: 'asset', // 'asset' | 'location' | 'department' | 'project'
  fromDate: '2025-01-01', // optional, ISO date
  toDate: '2025-12-31',   // optional, ISO date
})
// Returns CostRollupRow[]: group_key, group_name, labor_cents, parts_cents, vendor_cents, total_cents, work_order_count
  • Name
    tenantId
    Description

    Required. Tenant UUID.

  • Name
    groupBy
    Description

    Required. One of: asset, location, department, project.

  • Name
    fromDate
    Description

    Optional. Filter work orders by completed_at on or after this date (ISO date string).

  • Name
    toDate
    Description

    Optional. Filter work orders by completed_at on or before this date (ISO date string).

Asset lifecycle alerts

Assets with upcoming lifecycle events: warranty expiring, end-of-life approaching, service contract expiring, or planned replacement due. The view shows events within the next 365 days; the RPC lets you set the window.

client.costs.listLifecycleAlerts()

const alerts = await client.costs.listLifecycleAlerts()
// Returns AssetLifecycleAlertRow[]: asset_id, alert_type, reference_date, days_until
// alert_type: 'warranty_expiring' | 'eol_approaching' | 'contract_expiring' | 'planned_replacement_due'

client.costs.assetLifecycleAlerts(params)

const alerts = await client.costs.assetLifecycleAlerts({
  tenantId: 'uuid-of-tenant',
  daysAhead: 90, // optional, default 365
})
// Returns AssetLifecycleAlertRow[]

Asset total cost of ownership

Total cost (labor + parts + vendor) and work order count for a single asset, with optional date filter on work order completed_at.

client.costs.assetTotalCostOfOwnership(params)

const tco = await client.costs.assetTotalCostOfOwnership({
  tenantId: 'uuid-of-tenant',
  assetId: 'uuid-of-asset',
  fromDate: '2025-01-01', // optional
  toDate: '2025-12-31',   // optional
})
// Returns AssetTcoRow | null: labor_cents, parts_cents, vendor_cents, total_cents, work_order_count

Projects

Projects group work orders for cost roll-up. The SDK exposes read-only client.projects.list() and getById() against v_projects. Full reference, row shape, and write-path notes are on the Projects page.

When creating a work order, pass projectId so its costs appear in project roll-ups.

Work order with project

await client.workOrders.create({
  tenantId: 'uuid-of-tenant',
  title: 'Overhaul pump P-101',
  projectId: 'uuid-of-project',
  // ... other params
})

Was this page helpful?