import { InvoiceSchema } from '#database/schema' import { belongsTo, column } from '@adonisjs/lucid/orm' import type { BelongsTo } from '@adonisjs/lucid/types/relations' import type { DateTime } from 'luxon' import Organization from '#models/organization' import Client from '#models/client' import Plan from '#models/plan' import type { InvoiceIssuer, InvoiceThemeSlug, } from '#services/invoice_settings' import type { ComputedInvoiceLine, TvaBreakdownItem, } from '#services/invoice_totals' /** * Snapshot du client figé au moment de l'émission. Permet à la facture * de rester intacte si le client change d'adresse ou de raison sociale. */ export interface ClientSnapshot { name: string email: string contactFirstName: string | null contactLastName: string | null phone: string | null siret: string | null siren: string | null tvaIntra: string | null addressLine1: string | null addressLine2: string | null addressZip: string | null addressCity: string | null addressCountry: string | null } export default class Invoice extends InvoiceSchema { /** * Champs ajoutés par la migration `1778800000200_enrich_invoices_for_native_editor`. * Déclarations manuelles en attendant que `schema.ts` soit régénéré par * `node ace migration:run`. */ @column() declare lines: ComputedInvoiceLine[] | null @column() declare clientSnapshot: ClientSnapshot | null @column() declare issuerSnapshot: InvoiceIssuer | null @column() declare amountHtCents: number | null @column() declare amountTvaCents: number | null @column() declare tvaBreakdown: TvaBreakdownItem[] | null @column() declare paymentTermsDays: number | null @column() declare footerNotes: string | null @column() declare themeSlug: InvoiceThemeSlug | null @column() declare themeAccentColor: string | null @column() declare isNative: boolean @column() declare sequenceNumber: number | null @column.dateTime() declare pdfGeneratedAt: DateTime | null @belongsTo(() => Organization) declare organization: BelongsTo @belongsTo(() => Client) declare client: BelongsTo @belongsTo(() => Plan) declare plan: BelongsTo }