mirror of
https://git.meshkee.com/Meshkee/backend.git
synced 2026-08-11 22:30:59 +04:30
Add platform invoices API with item templates and optional name.
Super admins can manage predefined invoice lines and issue invoices to businesses; schema is ready for future business-scoped use. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
136711dfb3
commit
426316d53c
@@ -36,6 +36,7 @@ model User {
|
||||
shoppingCards ShoppingCard[] @relation("ShoppingCardCustomer")
|
||||
transactionsCreated Transaction[] @relation("TransactionCreator")
|
||||
transactions Transaction[] @relation("TransactionCustomer")
|
||||
invoicesIssued Invoice[] @relation("InvoiceIssuer")
|
||||
userRoles UserRole[]
|
||||
|
||||
@@index([cellNumber], map: "idx_users_cell_number")
|
||||
@@ -88,6 +89,9 @@ model Business {
|
||||
storeItems StoreItem[]
|
||||
storeSpecials StoreSpecial[]
|
||||
transactions Transaction[]
|
||||
invoices Invoice[] @relation("InvoiceBusiness")
|
||||
invoicesIssued Invoice[] @relation("InvoiceIssuerBusiness")
|
||||
invoiceItemTemplates InvoiceItemTemplate[]
|
||||
website_brand_groups website_brand_groups[]
|
||||
website_category_groups website_category_groups[]
|
||||
website_sliders website_sliders[]
|
||||
@@ -1125,3 +1129,86 @@ enum TransactionStatus {
|
||||
|
||||
@@map("transaction_status")
|
||||
}
|
||||
|
||||
enum InvoiceOwnerScope {
|
||||
platform
|
||||
business
|
||||
|
||||
@@map("invoice_owner_scope")
|
||||
}
|
||||
|
||||
enum InvoiceStatus {
|
||||
draft
|
||||
issued
|
||||
paid
|
||||
cancelled
|
||||
|
||||
@@map("invoice_status")
|
||||
}
|
||||
|
||||
model InvoiceItemTemplate {
|
||||
id BigInt @id @default(autoincrement())
|
||||
ownerScope InvoiceOwnerScope @map("owner_scope")
|
||||
businessId BigInt? @map("business_id")
|
||||
title String @db.VarChar(255)
|
||||
duration String? @db.VarChar(100)
|
||||
worktime String? @db.VarChar(100)
|
||||
description String?
|
||||
price Decimal @default(0) @db.Decimal(12, 2)
|
||||
discountedPrice Decimal? @map("discounted_price") @db.Decimal(12, 2)
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
business Business? @relation(fields: [businessId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
||||
invoiceItems InvoiceItem[]
|
||||
|
||||
@@index([ownerScope, sortOrder], map: "idx_invoice_item_templates_owner_scope")
|
||||
@@index([businessId, sortOrder], map: "idx_invoice_item_templates_business_id")
|
||||
@@map("invoice_item_templates")
|
||||
}
|
||||
|
||||
model Invoice {
|
||||
id BigInt @id @default(autoincrement())
|
||||
businessId BigInt @map("business_id")
|
||||
ownerScope InvoiceOwnerScope @default(platform) @map("owner_scope")
|
||||
issuerBusinessId BigInt? @map("issuer_business_id")
|
||||
status InvoiceStatus @default(issued)
|
||||
name String? @db.VarChar(255)
|
||||
notes String?
|
||||
issuedBy BigInt? @map("issued_by")
|
||||
issuedAt DateTime @default(now()) @map("issued_at") @db.Timestamptz(6)
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
business Business @relation("InvoiceBusiness", fields: [businessId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
||||
issuerBusiness Business? @relation("InvoiceIssuerBusiness", fields: [issuerBusinessId], references: [id], onUpdate: NoAction)
|
||||
issuer User? @relation("InvoiceIssuer", fields: [issuedBy], references: [id], onUpdate: NoAction)
|
||||
items InvoiceItem[]
|
||||
|
||||
@@index([businessId, createdAt(sort: Desc)], map: "idx_invoices_business_created")
|
||||
@@index([ownerScope, createdAt(sort: Desc)], map: "idx_invoices_owner_scope")
|
||||
@@index([issuerBusinessId, createdAt(sort: Desc)], map: "idx_invoices_issuer_business_id")
|
||||
@@index([status], map: "idx_invoices_status")
|
||||
@@map("invoices")
|
||||
}
|
||||
|
||||
model InvoiceItem {
|
||||
id BigInt @id @default(autoincrement())
|
||||
invoiceId BigInt @map("invoice_id")
|
||||
templateId BigInt? @map("template_id")
|
||||
title String @db.VarChar(255)
|
||||
duration String? @db.VarChar(100)
|
||||
worktime String? @db.VarChar(100)
|
||||
description String?
|
||||
price Decimal @default(0) @db.Decimal(12, 2)
|
||||
discountedPrice Decimal? @map("discounted_price") @db.Decimal(12, 2)
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(6)
|
||||
invoice Invoice @relation(fields: [invoiceId], references: [id], onDelete: Cascade, onUpdate: NoAction)
|
||||
template InvoiceItemTemplate? @relation(fields: [templateId], references: [id], onUpdate: NoAction)
|
||||
|
||||
@@index([invoiceId, sortOrder], map: "idx_invoice_items_invoice_id")
|
||||
@@index([templateId], map: "idx_invoice_items_template_id")
|
||||
@@map("invoice_items")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user