erp-core-backend-v2/src/modules/financial/entities/invoice-line.entity.ts
Adrian Flores Cortes 6a12ff0844 [TASK-2026-02-05-EJECUCION-REMEDIATION-ERP-CORE] feat: Complete Sprint 0-4 data modeling remediation
Sprint 0: Updated inventories (MASTER/BACKEND/DATABASE) with verified baseline
Sprint 1: Fixed 8 P0 blockers - CFDI entities (schema cfdi→fiscal), auth base DDL,
  billing duplication (→operations), 5 project entities, PaymentInvoiceAllocation,
  core.companies DDL, recreate-database.sh array
Sprint 2: 4 new auth entities, session/role/permission DDL reconciliation,
  CFDI PAC+StampQueue, partner address+contact alignment
Sprint 3: CFDI service+controller+routes, mobile service+controller+routes,
  inventory extended DDL (7 tables)
Sprint 4: timestamp→timestamptz (40 files), field divergences, token/roles/permissions
  service alignment with new DDL-aligned entities

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 21:51:55 -06:00

80 lines
2.2 KiB
TypeScript

import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Index,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { Invoice } from './invoice.entity.js';
import { Account } from './account.entity.js';
@Entity({ schema: 'financial', name: 'invoice_lines' })
@Index('idx_invoice_lines_invoice_id', ['invoiceId'])
@Index('idx_invoice_lines_tenant_id', ['tenantId'])
@Index('idx_invoice_lines_product_id', ['productId'])
export class InvoiceLine {
@PrimaryGeneratedColumn('uuid')
id: string;
@Column({ type: 'uuid', nullable: false, name: 'invoice_id' })
invoiceId: string;
@Column({ type: 'uuid', nullable: false, name: 'tenant_id' })
tenantId: string;
@Column({ type: 'uuid', nullable: true, name: 'product_id' })
productId: string | null;
@Column({ type: 'text', nullable: false })
description: string;
@Column({ type: 'decimal', precision: 15, scale: 4, nullable: false })
quantity: number;
@Column({ type: 'uuid', nullable: true, name: 'uom_id' })
uomId: string | null;
@Column({ type: 'decimal', precision: 15, scale: 2, nullable: false, name: 'price_unit' })
priceUnit: number;
@Column({ type: 'uuid', array: true, default: '{}', name: 'tax_ids' })
taxIds: string[];
@Column({ type: 'decimal', precision: 15, scale: 2, default: 0, nullable: false, name: 'amount_untaxed' })
amountUntaxed: number;
@Column({ type: 'decimal', precision: 15, scale: 2, default: 0, nullable: false, name: 'amount_tax' })
amountTax: number;
@Column({ type: 'decimal', precision: 15, scale: 2, default: 0, nullable: false, name: 'amount_total' })
amountTotal: number;
@Column({ type: 'uuid', nullable: true, name: 'account_id' })
accountId: string | null;
// Relations
@ManyToOne(() => Invoice, (invoice) => invoice.lines, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'invoice_id' })
invoice: Invoice;
@ManyToOne(() => Account)
@JoinColumn({ name: 'account_id' })
account: Account | null;
// Audit fields
@CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
createdAt: Date;
@UpdateDateColumn({
name: 'updated_at',
type: 'timestamptz',
nullable: true,
})
updatedAt: Date | null;
}