finance
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "FinanceProfile" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"currencyCode" TEXT NOT NULL DEFAULT 'USD',
|
||||
"standardLaborRatePerHour" REAL NOT NULL DEFAULT 45,
|
||||
"overheadRatePerHour" REAL NOT NULL DEFAULT 18,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "FinanceCustomerPayment" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"salesOrderId" TEXT NOT NULL,
|
||||
"paymentType" TEXT NOT NULL,
|
||||
"paymentMethod" TEXT NOT NULL,
|
||||
"paymentDate" DATETIME NOT NULL,
|
||||
"amount" REAL NOT NULL,
|
||||
"reference" TEXT NOT NULL,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdById" TEXT,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "FinanceCustomerPayment_salesOrderId_fkey" FOREIGN KEY ("salesOrderId") REFERENCES "SalesOrder" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT "FinanceCustomerPayment_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "FinanceManufacturingCostSnapshot" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"workOrderId" TEXT NOT NULL,
|
||||
"materialCost" REAL NOT NULL DEFAULT 0,
|
||||
"laborCost" REAL NOT NULL DEFAULT 0,
|
||||
"overheadCost" REAL NOT NULL DEFAULT 0,
|
||||
"totalCost" REAL NOT NULL DEFAULT 0,
|
||||
"materialIssueCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"laborEntryCount" INTEGER NOT NULL DEFAULT 0,
|
||||
"calculatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "FinanceManufacturingCostSnapshot_workOrderId_fkey" FOREIGN KEY ("workOrderId") REFERENCES "WorkOrder" ("id") ON DELETE CASCADE ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "CapexEntry" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"title" TEXT NOT NULL,
|
||||
"category" TEXT NOT NULL,
|
||||
"status" TEXT NOT NULL,
|
||||
"vendorId" TEXT,
|
||||
"purchaseOrderId" TEXT,
|
||||
"plannedAmount" REAL NOT NULL,
|
||||
"actualAmount" REAL NOT NULL,
|
||||
"requestDate" DATETIME NOT NULL,
|
||||
"targetInServiceDate" DATETIME,
|
||||
"purchasedAt" DATETIME,
|
||||
"notes" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" DATETIME NOT NULL,
|
||||
CONSTRAINT "CapexEntry_vendorId_fkey" FOREIGN KEY ("vendorId") REFERENCES "Vendor" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT "CapexEntry_purchaseOrderId_fkey" FOREIGN KEY ("purchaseOrderId") REFERENCES "PurchaseOrder" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "FinanceCustomerPayment_salesOrderId_paymentDate_idx" ON "FinanceCustomerPayment"("salesOrderId", "paymentDate");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "FinanceCustomerPayment_createdAt_idx" ON "FinanceCustomerPayment"("createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "FinanceManufacturingCostSnapshot_workOrderId_key" ON "FinanceManufacturingCostSnapshot"("workOrderId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "FinanceManufacturingCostSnapshot_calculatedAt_idx" ON "FinanceManufacturingCostSnapshot"("calculatedAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "CapexEntry_status_requestDate_idx" ON "CapexEntry"("status", "requestDate");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "CapexEntry_vendorId_createdAt_idx" ON "CapexEntry"("vendorId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "CapexEntry_purchaseOrderId_createdAt_idx" ON "CapexEntry"("purchaseOrderId", "createdAt");
|
||||
@@ -29,6 +29,7 @@ model User {
|
||||
workOrderOperationLaborEntries WorkOrderOperationLaborEntry[]
|
||||
assignedWorkOrderOperations WorkOrderOperation[]
|
||||
shipmentPicks ShipmentPick[]
|
||||
financeCustomerPayments FinanceCustomerPayment[]
|
||||
approvedSalesQuotes SalesQuote[] @relation("SalesQuoteApprovedBy")
|
||||
approvedSalesOrders SalesOrder[] @relation("SalesOrderApprovedBy")
|
||||
salesQuoteRevisionsCreated SalesQuoteRevision[] @relation("SalesQuoteRevisionCreatedBy")
|
||||
@@ -401,6 +402,7 @@ model Vendor {
|
||||
contactEntries CrmContactEntry[]
|
||||
contacts CrmContact[]
|
||||
purchaseOrders PurchaseOrder[]
|
||||
capexEntries CapexEntry[]
|
||||
preferredSupplyItems InventoryItem[]
|
||||
}
|
||||
|
||||
@@ -496,6 +498,7 @@ model SalesOrder {
|
||||
revisions SalesOrderRevision[]
|
||||
workOrders WorkOrder[]
|
||||
purchaseOrderLines PurchaseOrderLine[]
|
||||
customerPayments FinanceCustomerPayment[]
|
||||
}
|
||||
|
||||
model SalesOrderLine {
|
||||
@@ -665,6 +668,7 @@ model WorkOrder {
|
||||
materialIssues WorkOrderMaterialIssue[]
|
||||
completions WorkOrderCompletion[]
|
||||
reservations InventoryReservation[]
|
||||
financeCostSnapshot FinanceManufacturingCostSnapshot?
|
||||
|
||||
@@index([itemId, createdAt])
|
||||
@@index([projectId, dueDate])
|
||||
@@ -788,6 +792,74 @@ model WorkOrderCompletion {
|
||||
@@index([workOrderId, createdAt])
|
||||
}
|
||||
|
||||
model FinanceProfile {
|
||||
id String @id @default(cuid())
|
||||
currencyCode String @default("USD")
|
||||
standardLaborRatePerHour Float @default(45)
|
||||
overheadRatePerHour Float @default(18)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model FinanceCustomerPayment {
|
||||
id String @id @default(cuid())
|
||||
salesOrderId String
|
||||
paymentType String
|
||||
paymentMethod String
|
||||
paymentDate DateTime
|
||||
amount Float
|
||||
reference String
|
||||
notes String
|
||||
createdById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
salesOrder SalesOrder @relation(fields: [salesOrderId], references: [id], onDelete: Cascade)
|
||||
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([salesOrderId, paymentDate])
|
||||
@@index([createdAt])
|
||||
}
|
||||
|
||||
model FinanceManufacturingCostSnapshot {
|
||||
id String @id @default(cuid())
|
||||
workOrderId String @unique
|
||||
materialCost Float @default(0)
|
||||
laborCost Float @default(0)
|
||||
overheadCost Float @default(0)
|
||||
totalCost Float @default(0)
|
||||
materialIssueCount Int @default(0)
|
||||
laborEntryCount Int @default(0)
|
||||
calculatedAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
workOrder WorkOrder @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([calculatedAt])
|
||||
}
|
||||
|
||||
model CapexEntry {
|
||||
id String @id @default(cuid())
|
||||
title String
|
||||
category String
|
||||
status String
|
||||
vendorId String?
|
||||
purchaseOrderId String?
|
||||
plannedAmount Float
|
||||
actualAmount Float
|
||||
requestDate DateTime
|
||||
targetInServiceDate DateTime?
|
||||
purchasedAt DateTime?
|
||||
notes String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
vendor Vendor? @relation(fields: [vendorId], references: [id], onDelete: SetNull)
|
||||
purchaseOrder PurchaseOrder? @relation(fields: [purchaseOrderId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([status, requestDate])
|
||||
@@index([vendorId, createdAt])
|
||||
@@index([purchaseOrderId, createdAt])
|
||||
}
|
||||
|
||||
model PurchaseOrder {
|
||||
id String @id @default(cuid())
|
||||
documentNumber String @unique
|
||||
@@ -803,6 +875,7 @@ model PurchaseOrder {
|
||||
lines PurchaseOrderLine[]
|
||||
receipts PurchaseReceipt[]
|
||||
revisions PurchaseOrderRevision[]
|
||||
capexEntries CapexEntry[]
|
||||
}
|
||||
|
||||
model PurchaseOrderLine {
|
||||
|
||||
Reference in New Issue
Block a user