erp-transportistas-backend-v2/src/modules/combustible-gastos/entities/carga-combustible.entity.ts
Adrian Flores Cortes 2722920e12 feat: Add combustible-gastos and tarifas-transporte entities
New entities for combustible-gastos module:
- anticipo-viatico.entity.ts
- carga-combustible.entity.ts
- control-rendimiento.entity.ts
- cruce-peaje.entity.ts
- gasto-viaje.entity.ts

New entities for tarifas-transporte module:
- factura-transporte.entity.ts
- fuel-surcharge.entity.ts
- lane.entity.ts
- linea-factura.entity.ts
- recargo-catalogo.entity.ts
- tarifa.entity.ts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-25 14:15:26 -06:00

142 lines
3.6 KiB
TypeScript

import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
Index,
ManyToOne,
JoinColumn,
} from 'typeorm';
/**
* Tipo de Carga de Combustible
*/
export enum TipoCargaCombustible {
VALE = 'VALE',
TARJETA = 'TARJETA',
EFECTIVO = 'EFECTIVO',
FACTURA_DIRECTA = 'FACTURA_DIRECTA',
}
/**
* Tipo de Combustible
*/
export enum TipoCombustible {
DIESEL = 'DIESEL',
GASOLINA_MAGNA = 'GASOLINA_MAGNA',
GASOLINA_PREMIUM = 'GASOLINA_PREMIUM',
GAS_LP = 'GAS_LP',
GAS_NATURAL = 'GAS_NATURAL',
}
/**
* Estado del Gasto
*/
export enum EstadoGasto {
PENDIENTE = 'PENDIENTE',
APROBADO = 'APROBADO',
RECHAZADO = 'RECHAZADO',
PAGADO = 'PAGADO',
}
@Entity({ schema: 'fuel', name: 'cargas_combustible' })
@Index('idx_carga_unidad', ['unidadId'])
@Index('idx_carga_viaje', ['viajeId'])
@Index('idx_carga_fecha', ['tenantId', 'fechaCarga'])
export class CargaCombustible {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ name: 'tenant_id', type: 'uuid' })
tenantId: string;
// Unidad y viaje
@Column({ name: 'unidad_id', type: 'uuid' })
unidadId: string;
@Column({ name: 'viaje_id', type: 'uuid', nullable: true })
viajeId: string | null;
@Column({ name: 'operador_id', type: 'uuid' })
operadorId: string;
// Carga
@Column({ name: 'tipo_carga', type: 'enum', enum: TipoCargaCombustible })
tipoCarga: TipoCargaCombustible;
@Column({ name: 'tipo_combustible', type: 'varchar', length: 20 })
tipoCombustible: string;
@Column({ type: 'decimal', precision: 10, scale: 3 })
litros: number;
@Column({ name: 'precio_litro', type: 'decimal', precision: 10, scale: 4 })
precioLitro: number;
@Column({ type: 'decimal', precision: 12, scale: 2 })
total: number;
// Odómetro
@Column({ name: 'odometro_carga', type: 'int', nullable: true })
odometroCarga: number | null;
@Column({ name: 'rendimiento_calculado', type: 'decimal', precision: 6, scale: 2, nullable: true })
rendimientoCalculado: number | null;
// Ubicación
@Column({ name: 'estacion_id', type: 'uuid', nullable: true })
estacionId: string | null;
@Column({ name: 'estacion_nombre', type: 'varchar', length: 200, nullable: true })
estacionNombre: string | null;
@Column({ name: 'estacion_direccion', type: 'text', nullable: true })
estacionDireccion: string | null;
@Column({ type: 'decimal', precision: 10, scale: 7, nullable: true })
latitud: number | null;
@Column({ type: 'decimal', precision: 10, scale: 7, nullable: true })
longitud: number | null;
// Vale/Factura
@Column({ name: 'numero_vale', type: 'varchar', length: 50, nullable: true })
numeroVale: string | null;
@Column({ name: 'numero_factura', type: 'varchar', length: 50, nullable: true })
numeroFactura: string | null;
@Column({ name: 'folio_ticket', type: 'varchar', length: 50, nullable: true })
folioTicket: string | null;
// Fecha
@Column({ name: 'fecha_carga', type: 'timestamptz' })
fechaCarga: Date;
// Aprobación
@Column({ type: 'enum', enum: EstadoGasto, default: EstadoGasto.PENDIENTE })
estado: EstadoGasto;
@Column({ name: 'aprobado_por', type: 'uuid', nullable: true })
aprobadoPor: string | null;
@Column({ name: 'aprobado_fecha', type: 'timestamptz', nullable: true })
aprobadoFecha: Date | null;
// Evidencia
@Column({ name: 'foto_ticket_url', type: 'text', nullable: true })
fotoTicketUrl: string | null;
// Auditoría
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@Column({ name: 'created_by_id', type: 'uuid' })
createdById: string;
// Helpers
get costoPorLitro(): number {
return this.litros > 0 ? this.total / this.litros : 0;
}
}