FastAPI backend (Python 3.11, MSSQL ODBC for SambaPOS, Azure DI OCR),
kitchen_db on central PG. React/TS/Vite frontend with navy sidebar layout.
Backend: auth.py (APP_SLUG=kitchen, SimpleNamespace — archive routes use
.kitchen_id/.is_admin without modification), main.py (51 migrations, scheduler,
internal router for KDS bookings feed), api/internal.py, full archive API
(31 routers: invoices, recipes, menus, sambapos, resos, newbook, disputes,
purchase_orders, etc.), models, migrations, OCR pipeline.
kitchen_id pinned to 1 (B1 — single hotel).
Frontend: AuthGate (app=kitchen, token shim for archive compat — B5b pending),
Layout (navy sidebar, 6 sections, Lucide icons, teal --app-primary),
App.tsx (Outlet pattern, UploadApp outside Layout), index.css (full :root block).
strict: false — archive components have type issues; build clean.
Note: 45 archive components call fetch('/api/...') without /kitchen/ prefix
(B5b). Runtime 404s; deferred until after initial testing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
from datetime import datetime, date
|
|
from decimal import Decimal
|
|
from sqlalchemy import String, DateTime, Date, ForeignKey, Numeric, Text, JSON
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from database import Base
|
|
|
|
|
|
class RevenueEntry(Base):
|
|
"""Daily revenue entries for GP calculation"""
|
|
__tablename__ = "revenue_entries"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
kitchen_id: Mapped[int] = mapped_column(ForeignKey("kitchens.id"), nullable=False)
|
|
|
|
date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
amount: Mapped[Decimal] = mapped_column(Numeric(10, 2), nullable=False)
|
|
|
|
# Category breakdown (e.g., "food", "beverages", "other")
|
|
category: Mapped[str] = mapped_column(String(50), default="total")
|
|
|
|
notes: Mapped[str] = mapped_column(Text, nullable=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relationships
|
|
kitchen: Mapped["Kitchen"] = relationship("Kitchen", back_populates="revenue_entries")
|
|
|
|
|
|
class GPPeriod(Base):
|
|
"""Calculated GP for a specific period"""
|
|
__tablename__ = "gp_periods"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
kitchen_id: Mapped[int] = mapped_column(ForeignKey("kitchens.id"), nullable=False)
|
|
|
|
start_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
end_date: Mapped[date] = mapped_column(Date, nullable=False)
|
|
|
|
# Calculated values
|
|
total_revenue: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False)
|
|
total_costs: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False)
|
|
gp_amount: Mapped[Decimal] = mapped_column(Numeric(12, 2), nullable=False)
|
|
gp_percentage: Mapped[Decimal] = mapped_column(Numeric(5, 2), nullable=False)
|
|
|
|
# Breakdown by category (JSON)
|
|
# {"food": {"revenue": 1000, "cost": 300, "gp": 70}, ...}
|
|
category_breakdown: Mapped[dict | None] = mapped_column(JSON, default=dict)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
|
|
|
# Relationships
|
|
kitchen: Mapped["Kitchen"] = relationship("Kitchen", back_populates="gp_periods")
|
|
|
|
|
|
# Forward reference
|
|
from .user import Kitchen
|