1 | generator client {
|
---|
2 | provider = "prisma-client-js"
|
---|
3 | }
|
---|
4 |
|
---|
5 | datasource db {
|
---|
6 | provider = "postgresql"
|
---|
7 | url = env("DATABASE_URL")
|
---|
8 | }
|
---|
9 |
|
---|
10 | model Client {
|
---|
11 | id String @id @default(uuid())
|
---|
12 | tenantId String @map("tenant_id")
|
---|
13 | name String
|
---|
14 | email String @unique
|
---|
15 | address Json
|
---|
16 | logoUrl String? @map("logo_url")
|
---|
17 | phoneNumber String? @map("phone_number")
|
---|
18 | vatNumber String? @map("vat_number")
|
---|
19 | companyNumber String? @map("company_number")
|
---|
20 | representative String
|
---|
21 | status ClientStatus @default(active)
|
---|
22 | createdAt DateTime @default(now()) @map("created_at")
|
---|
23 | updatedAt DateTime @updatedAt @map("updated_at")
|
---|
24 |
|
---|
25 | tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
---|
26 | invoicesReceived Invoice[] @relation("InvoiceTo")
|
---|
27 | }
|
---|
28 |
|
---|
29 | model Service {
|
---|
30 | id String @id @default(uuid())
|
---|
31 | name String
|
---|
32 | sprint Float
|
---|
33 | hour Float
|
---|
34 | month Float
|
---|
35 | tenantId String @map("tenant_id")
|
---|
36 | tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
---|
37 |
|
---|
38 | lineItems LineItem[]
|
---|
39 | }
|
---|
40 |
|
---|
41 | model Invoice {
|
---|
42 | id String @id @default(uuid())
|
---|
43 | sent Int?
|
---|
44 | dueDate DateTime @map("due_date")
|
---|
45 | status InvoiceStatus
|
---|
46 | currency Currency
|
---|
47 | quantityType QuantityType @map("quantity_type")
|
---|
48 | subTotal Float @map("sub_total")
|
---|
49 | issueDate DateTime @map("issue_date")
|
---|
50 | month Month
|
---|
51 | discount Float?
|
---|
52 | taxes Float?
|
---|
53 | totalAmount Float @map("total_amount")
|
---|
54 | invoiceNumber String @unique @map("invoice_number")
|
---|
55 | pdfRef String? @map("pdf_ref")
|
---|
56 | createdAt DateTime @default(now()) @map("created_at")
|
---|
57 | updatedAt DateTime @updatedAt @map("updated_at")
|
---|
58 |
|
---|
59 | invoiceFromId String @map("tenant_id")
|
---|
60 | invoiceFrom Tenant @relation(fields: [invoiceFromId], references: [id], onDelete: Cascade)
|
---|
61 |
|
---|
62 | invoiceToId String @map("client_id")
|
---|
63 | invoiceTo Client @relation("InvoiceTo", fields: [invoiceToId], references: [id], onDelete: Cascade)
|
---|
64 |
|
---|
65 | items LineItem[]
|
---|
66 | }
|
---|
67 |
|
---|
68 | model LineItem {
|
---|
69 | id String @id @default(uuid())
|
---|
70 | title String
|
---|
71 | price Float
|
---|
72 | total Float
|
---|
73 | quantity Int
|
---|
74 | description String?
|
---|
75 | serviceId String @map("service_id")
|
---|
76 | service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
|
---|
77 | invoiceId String @map("invoice_id")
|
---|
78 | invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
|
---|
79 | }
|
---|
80 |
|
---|
81 | model Tenant {
|
---|
82 | id String @id @default(cuid())
|
---|
83 | name String
|
---|
84 | email String @unique
|
---|
85 | address Json
|
---|
86 | bankAccounts Json? @map("bank_accounts")
|
---|
87 | logoUrl String? @map("logo_url")
|
---|
88 | phoneNumber String? @map("phone_number")
|
---|
89 | vatNumber String? @map("vat_number")
|
---|
90 | companyNumber String? @map("company_number")
|
---|
91 | representative String
|
---|
92 | lastInvoiceNumber String @default("0") @map("last_invoice_number")
|
---|
93 | createdAt DateTime @default(now()) @map("created_at")
|
---|
94 | updatedAt DateTime @updatedAt @map("updated_at")
|
---|
95 | invoicesSent Invoice[]
|
---|
96 | services Service[]
|
---|
97 | employees Employee[]
|
---|
98 | clients Client[]
|
---|
99 | users User[]
|
---|
100 | }
|
---|
101 |
|
---|
102 | model Employee {
|
---|
103 | id String @id @default(uuid())
|
---|
104 | name String
|
---|
105 | email String @unique
|
---|
106 | status EmployeeStatus @default(active)
|
---|
107 | iban String?
|
---|
108 | cv String?
|
---|
109 | photo String?
|
---|
110 | project String?
|
---|
111 | tenantId String @map("tenant_id")
|
---|
112 | tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
---|
113 | createdAt DateTime @default(now()) @map("created_at")
|
---|
114 | updatedAt DateTime @updatedAt @map("updated_at")
|
---|
115 | }
|
---|
116 |
|
---|
117 | model User {
|
---|
118 | id String @id @default(uuid())
|
---|
119 | uid String @unique // Firebase UID
|
---|
120 | email String @unique
|
---|
121 | displayName String @map("display_name")
|
---|
122 | role UserRole
|
---|
123 | tenantId String @map("tenant_id")
|
---|
124 | tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
---|
125 | createdAt DateTime @default(now()) @map("created_at")
|
---|
126 | updatedAt DateTime @updatedAt @map("updated_at")
|
---|
127 | }
|
---|
128 |
|
---|
129 | enum UserRole {
|
---|
130 | ADMIN @map("ADMIN")
|
---|
131 | MANAGER @map("MANAGER")
|
---|
132 | USER @map("USER")
|
---|
133 | }
|
---|
134 |
|
---|
135 | enum ClientStatus {
|
---|
136 | active @map("ACTIVE")
|
---|
137 | banned @map("BANNED")
|
---|
138 | inactive @map("INACTIVE")
|
---|
139 | }
|
---|
140 |
|
---|
141 | enum InvoiceStatus {
|
---|
142 | draft @map("DRAFT")
|
---|
143 | processing @map("PROCESSING")
|
---|
144 | pending @map("PENDING")
|
---|
145 | overdue @map("OVERDUE")
|
---|
146 | paid @map("PAID")
|
---|
147 | }
|
---|
148 |
|
---|
149 | enum Currency {
|
---|
150 | EUR @map("EUR")
|
---|
151 | USD @map("USD")
|
---|
152 | }
|
---|
153 |
|
---|
154 | enum QuantityType {
|
---|
155 | Unit @map("UNIT")
|
---|
156 | Hour @map("HOUR")
|
---|
157 | Sprint @map("SPRINT")
|
---|
158 | Month @map("MONTH")
|
---|
159 | }
|
---|
160 |
|
---|
161 | enum Month {
|
---|
162 | January @map("JANUARY")
|
---|
163 | February @map("FEBRUARY")
|
---|
164 | March @map("MARCH")
|
---|
165 | April @map("APRIL")
|
---|
166 | May @map("MAY")
|
---|
167 | June @map("JUNE")
|
---|
168 | July @map("JULY")
|
---|
169 | August @map("AUGUST")
|
---|
170 | September @map("SEPTEMBER")
|
---|
171 | October @map("OCTOBER")
|
---|
172 | November @map("NOVEMBER")
|
---|
173 | December @map("DECEMBER")
|
---|
174 | }
|
---|
175 |
|
---|
176 | enum EmployeeStatus {
|
---|
177 | active @map("ACTIVE")
|
---|
178 | inactive @map("INACTIVE")
|
---|
179 | }
|
---|