sales
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "SalesQuote" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"documentNumber" TEXT NOT NULL,
|
||||
"customerId" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"issueDate" DATETIME NOT NULL,
|
||||
"expiresAt" DATETIME,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "SalesQuote_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SalesQuoteLine" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"quoteId" TEXT NOT NULL,
|
||||
"itemId" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"quantity" INTEGER NOT NULL,
|
||||
"unitOfMeasure" TEXT NOT NULL,
|
||||
"unitPrice" REAL NOT NULL,
|
||||
"position" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "SalesQuoteLine_quoteId_fkey" FOREIGN KEY ("quoteId") REFERENCES "SalesQuote" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "SalesQuoteLine_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "InventoryItem" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SalesOrder" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"documentNumber" TEXT NOT NULL,
|
||||
"customerId" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"issueDate" DATETIME NOT NULL,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "SalesOrder_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "SalesOrderLine" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"orderId" TEXT NOT NULL,
|
||||
"itemId" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"quantity" INTEGER NOT NULL,
|
||||
"unitOfMeasure" TEXT NOT NULL,
|
||||
"unitPrice" REAL NOT NULL,
|
||||
"position" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "SalesOrderLine_orderId_fkey" FOREIGN KEY ("orderId") REFERENCES "SalesOrder" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "SalesOrderLine_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "InventoryItem" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "SalesQuote_documentNumber_key" ON "SalesQuote"("documentNumber");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "SalesQuoteLine_quoteId_position_idx" ON "SalesQuoteLine"("quoteId", "position");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "SalesOrder_documentNumber_key" ON "SalesOrder"("documentNumber");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "SalesOrderLine_orderId_position_idx" ON "SalesOrderLine"("orderId", "position");
|
||||
@@ -119,6 +119,8 @@ model InventoryItem {
|
||||
bomLines InventoryBomLine[] @relation("InventoryBomParent")
|
||||
usedInBomLines InventoryBomLine[] @relation("InventoryBomComponent")
|
||||
inventoryTransactions InventoryTransaction[]
|
||||
salesQuoteLines SalesQuoteLine[]
|
||||
salesOrderLines SalesOrderLine[]
|
||||
}
|
||||
|
||||
model Warehouse {
|
||||
@@ -163,6 +165,8 @@ model Customer {
|
||||
contacts CrmContact[]
|
||||
parentCustomer Customer? @relation("CustomerHierarchy", fields: [parentCustomerId], references: [id], onDelete: SetNull)
|
||||
childCustomers Customer[] @relation("CustomerHierarchy")
|
||||
salesQuotes SalesQuote[]
|
||||
salesOrders SalesOrder[]
|
||||
}
|
||||
|
||||
model InventoryBomLine {
|
||||
@@ -277,3 +281,64 @@ model CrmContact {
|
||||
customer Customer? @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
||||
vendor Vendor? @relation(fields: [vendorId], references: [id], onDelete: Cascade)
|
||||
}
|
||||
|
||||
model SalesQuote {
|
||||
id String @id @default(cuid())
|
||||
documentNumber String @unique
|
||||
customerId String
|
||||
status String
|
||||
issueDate DateTime
|
||||
expiresAt DateTime?
|
||||
notes String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
||||
lines SalesQuoteLine[]
|
||||
}
|
||||
|
||||
model SalesQuoteLine {
|
||||
id String @id @default(cuid())
|
||||
quoteId String
|
||||
itemId String
|
||||
description String
|
||||
quantity Int
|
||||
unitOfMeasure String
|
||||
unitPrice Float
|
||||
position Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
quote SalesQuote @relation(fields: [quoteId], references: [id], onDelete: Cascade)
|
||||
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
||||
|
||||
@@index([quoteId, position])
|
||||
}
|
||||
|
||||
model SalesOrder {
|
||||
id String @id @default(cuid())
|
||||
documentNumber String @unique
|
||||
customerId String
|
||||
status String
|
||||
issueDate DateTime
|
||||
notes String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
customer Customer @relation(fields: [customerId], references: [id], onDelete: Restrict)
|
||||
lines SalesOrderLine[]
|
||||
}
|
||||
|
||||
model SalesOrderLine {
|
||||
id String @id @default(cuid())
|
||||
orderId String
|
||||
itemId String
|
||||
description String
|
||||
quantity Int
|
||||
unitOfMeasure String
|
||||
unitPrice Float
|
||||
position Int @default(0)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
order SalesOrder @relation(fields: [orderId], references: [id], onDelete: Cascade)
|
||||
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Restrict)
|
||||
|
||||
@@index([orderId, position])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user