Add Stock catalog (items/warehouses) and fix session persistence
Stock is scoped to a catalog + cost centers only, per direction that physical GRV/stock-take/recipe transactions belong in an external system (Matrix), not this accounting app. Stock Control/GRN/Variance/ PPV GL accounts are now plain postable accounts rather than locked control accounts. Also fixes session loss on page refresh: auth stores now persist to localStorage, and ProtectedRoute waits for rehydration before deciding to redirect to login. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JWqiUSojMLUoN7mrJqdEbN
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
4acbc03b35
commit
b137176c40
+48
-4
@@ -105,6 +105,7 @@ model AccountSegmentValue {
|
||||
glAccountLinks GLAccountSegmentValue[]
|
||||
customers Customer[]
|
||||
suppliers Supplier[]
|
||||
warehouses Warehouse[]
|
||||
|
||||
@@unique([segmentDefId, code])
|
||||
}
|
||||
@@ -134,7 +135,6 @@ enum DebitCredit {
|
||||
enum ControlAccountType {
|
||||
AR
|
||||
AP
|
||||
STOCK
|
||||
TAX_OUTPUT
|
||||
TAX_INPUT
|
||||
BANK
|
||||
@@ -253,13 +253,11 @@ model JournalEntryLine {
|
||||
credit Decimal @default(0) @db.Decimal(18, 2)
|
||||
description String?
|
||||
branchSegmentValueId Int?
|
||||
// Sub-ledger cross-references for drill-down. arInvoiceId/apInvoiceId are real FKs now that
|
||||
// AR/AP exist; stockMovementId stays a plain id until Stock lands in its own phase.
|
||||
// Sub-ledger cross-references for drill-down.
|
||||
arInvoiceId Int?
|
||||
arInvoice ARInvoice? @relation(fields: [arInvoiceId], references: [id])
|
||||
apInvoiceId Int?
|
||||
apInvoice APInvoice? @relation(fields: [apInvoiceId], references: [id])
|
||||
stockMovementId Int?
|
||||
currencyCode String @default("BASE")
|
||||
exchangeRateToBase Decimal @default(1) @db.Decimal(18, 6)
|
||||
|
||||
@@ -615,6 +613,52 @@ model APAllocation {
|
||||
@@index([debitNoteId])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Stock (catalog + cost centers only — see the comment on Warehouse below)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Deliberately minimal: this is accounting software, not a stock/warehouse system. Physical
|
||||
// stock transactions (goods received, stock takes, recipe production) belong in Matrix (the
|
||||
// external hospitality/retail stock system this app is designed to eventually integrate with)
|
||||
// — this app only needs a catalog of items, a set of cost centers to view SOH by, and a place
|
||||
// for whatever quantities Matrix eventually reports. No costing engine, no movement ledger, no
|
||||
// document workflow live here.
|
||||
model Warehouse {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique
|
||||
name String
|
||||
branchSegmentValueId Int
|
||||
branchSegmentValue AccountSegmentValue @relation(fields: [branchSegmentValueId], references: [id])
|
||||
isActive Boolean @default(true)
|
||||
stockLevels StockLevel[]
|
||||
|
||||
@@index([branchSegmentValueId])
|
||||
}
|
||||
|
||||
model StockItem {
|
||||
id Int @id @default(autoincrement())
|
||||
code String @unique
|
||||
name String
|
||||
unitOfMeasure String
|
||||
isActive Boolean @default(true)
|
||||
stockLevels StockLevel[]
|
||||
createdAt DateTime @default(now())
|
||||
}
|
||||
|
||||
// Quantity on hand per item/warehouse — a read target for a future Matrix feed, not written to
|
||||
// from any UI in this app today.
|
||||
model StockLevel {
|
||||
id Int @id @default(autoincrement())
|
||||
itemId Int
|
||||
item StockItem @relation(fields: [itemId], references: [id])
|
||||
warehouseId Int
|
||||
warehouse Warehouse @relation(fields: [warehouseId], references: [id])
|
||||
quantityOnHand Decimal @default(0) @db.Decimal(18, 4)
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([itemId, warehouseId])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Auth / RBAC
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user