feat(invoices): add billingEntityType/Id for polymorphic billing
This commit is contained in:
@@ -15,7 +15,9 @@ import { files } from './documents';
|
||||
export const expenses = pgTable(
|
||||
'expenses',
|
||||
{
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
id: text('id')
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
portId: text('port_id')
|
||||
.notNull()
|
||||
.references(() => ports.id),
|
||||
@@ -49,12 +51,16 @@ export const expenses = pgTable(
|
||||
export const invoices = pgTable(
|
||||
'invoices',
|
||||
{
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
id: text('id')
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
portId: text('port_id')
|
||||
.notNull()
|
||||
.references(() => ports.id),
|
||||
invoiceNumber: text('invoice_number').notNull(), // INV-YYYYMM-### auto-generated
|
||||
clientName: text('client_name').notNull(),
|
||||
billingEntityType: text('billing_entity_type').notNull().default('client'), // 'client' | 'company'
|
||||
billingEntityId: text('billing_entity_id').notNull().default(''),
|
||||
billingEmail: text('billing_email'),
|
||||
billingAddress: text('billing_address'),
|
||||
dueDate: date('due_date').notNull(),
|
||||
@@ -82,13 +88,20 @@ export const invoices = pgTable(
|
||||
uniqueIndex('idx_invoices_number').on(table.portId, table.invoiceNumber),
|
||||
index('idx_invoices_port').on(table.portId),
|
||||
index('idx_invoices_status').on(table.portId, table.status),
|
||||
index('idx_invoices_billing_entity').on(
|
||||
table.portId,
|
||||
table.billingEntityType,
|
||||
table.billingEntityId,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
export const invoiceLineItems = pgTable(
|
||||
'invoice_line_items',
|
||||
{
|
||||
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
||||
id: text('id')
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
invoiceId: text('invoice_id')
|
||||
.notNull()
|
||||
.references(() => invoices.id, { onDelete: 'cascade' }),
|
||||
|
||||
Reference in New Issue
Block a user