Skip to main content

Overview

The Customer data model represents both vehicle owners (propietarios) and drivers (conductores) in the MotorDesk fleet management system. Customers can own vehicles, be assigned as habitual drivers, or both.

TypeScript Interface

interface Customer {
  id: string;
  tipoDocumentoIdentidad: string;
  numeroDocumento: string;
  nombreRazonSocial: string;
  direccion: string;
  telefono: string;
  email: string;
}

Field Reference

id
string
required
Unique identifier for the customerFormat: cust-XXX where XXX is a sequential numberExample: cust-001
tipoDocumentoIdentidad
string
required
Type of identity documentValid Values:
  • RUC - Tax identification number for companies (11 digits)
  • DNI - National identity document for individuals (8 digits)
Example: RUC or DNI
numeroDocumento
string
required
Identity document numberValidation Rules:
  • Must be numeric
  • DNI: Exactly 8 digits
  • RUC: Exactly 11 digits
Examples: 20987654321 (RUC), 76543210 (DNI)
nombreRazonSocial
string
required
Full name (for individuals) or business name (for companies)Format: Free text, typically in uppercase for companiesExamples:
  • TRANSPORTES RAPIDOS S.A.C. (Company)
  • Juan Perez (Chofer) (Individual)
direccion
string
required
Physical address of the customerFormat: Street address including district/city when applicableExample: Calle Los Camiones 123 or Av. Industrial 500, Ate
telefono
string
required
Contact phone numberFormat: Phone number (can include country code or area code)Examples: 987654321, 01-444-5555
email
string
required
Email address for electronic billing and communicationsValidation: Must be a valid email formatExample: [email protected]

Relationships

A customer can own multiple vehicles. The relationship is established through the propietarioId field in the Vehicle model.
// Find all vehicles owned by a customer
const ownedVehicles = vehicles.filter(v => v.propietarioId === customer.id);
A customer can be assigned as the habitual driver for multiple vehicles. The relationship is established through the conductorHabitualId field in the Vehicle model.
// Find all vehicles driven by a customer
const drivenVehicles = vehicles.filter(v => v.conductorHabitualId === customer.id);
Customers are referenced in sales transactions through the customerId field in the Sale model. They can also be referenced as the driver through the choferId field.
// Find all sales for a customer
const customerSales = sales.filter(s => s.customerId === customer.id);

Example Data

Individual Customer (DNI)

{
  "id": "cust-002",
  "tipoDocumentoIdentidad": "DNI",
  "numeroDocumento": "76543210",
  "nombreRazonSocial": "Juan Perez (Chofer)",
  "direccion": "Av. Su Casa 456",
  "telefono": "999888777",
  "email": "[email protected]"
}

Company Customer (RUC)

{
  "id": "cust-001",
  "tipoDocumentoIdentidad": "RUC",
  "numeroDocumento": "20987654321",
  "nombreRazonSocial": "TRANSPORTES RAPIDOS S.A.C.",
  "direccion": "Calle Los Camiones 123",
  "telefono": "987654321",
  "email": "[email protected]"
}

Validation Rules

Document Type ValidationThe system validates document numbers based on the selected document type:
  • DNI documents must be exactly 8 numeric digits
  • RUC documents must be exactly 11 numeric digits
  • Invalid combinations will be rejected
SUNAT/RENIEC IntegrationMotorDesk integrates with the Decolecta API to validate and auto-fill customer information from SUNAT (for RUC) and RENIEC (for DNI) databases. This ensures data accuracy and reduces manual entry errors.

Business Logic

Customer Creation Flow

  1. User enters document type and number
  2. System queries Decolecta API for validation
  3. If found, auto-fills nombreRazonSocial and direccion
  4. User reviews and completes remaining fields
  5. System validates all required fields
  6. Customer record is created

Decolecta API Integration

const fetchDecolectaData = async (tipoDoc: string, numeroDoc: string) => {
  // Validates document with SUNAT/RENIEC via Decolecta API
  const response = await decolectaAPI.validate(tipoDoc, numeroDoc);
  
  if (response.success) {
    return {
      nombreRazonSocial: response.data.nombre,
      direccion: response.data.direccion
    };
  }
  
  return null;
};

Data Storage

Mock Data Location

/src/data/mock/customers.tsTypeScript export with sample customer data

JSON Data Location

/src/data/json/customers.jsonRaw JSON array of customer objects
  • Vehicles - Customers can own or drive vehicles
  • Sales - Sales transactions reference customers

Usage Examples

Finding Customer’s Total Vehicles

const getCustomerVehicleCount = (customerId: string) => {
  const ownedVehicles = vehicles.filter(
    v => v.propietarioId === customerId && !v.isDeleted
  );
  
  const drivenVehicles = vehicles.filter(
    v => v.conductorHabitualId === customerId && !v.isDeleted
  );
  
  return {
    owned: ownedVehicles.length,
    driven: drivenVehicles.length,
    total: ownedVehicles.length + drivenVehicles.length
  };
};

Searching Customers

const searchCustomers = (searchTerm: string) => {
  const term = searchTerm.toLowerCase();
  
  return customers.filter(c => 
    c.numeroDocumento.toLowerCase().includes(term) ||
    c.nombreRazonSocial.toLowerCase().includes(term) ||
    c.email?.toLowerCase().includes(term)
  );
};

Build docs developers (and LLMs) love