-- CreateTable
CREATE TABLE "public"."shortfall_analytics_daily" (
    "id" TEXT NOT NULL,
    "date" TIMESTAMP(3) NOT NULL,
    "branchId" TEXT,
    "branchKey" TEXT NOT NULL DEFAULT 'GLOBAL',
    "totalShortfallItems" INTEGER NOT NULL DEFAULT 0,
    "totalShortfallQty" DECIMAL(65,30) NOT NULL DEFAULT 0,
    "totalOrdersWithShortfall" INTEGER NOT NULL DEFAULT 0,
    "totalOrders" INTEGER NOT NULL DEFAULT 0,
    "totalShortfallAmount" DECIMAL(65,30) NOT NULL DEFAULT 0,
    "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "updatedAt" TIMESTAMP(3) NOT NULL,

    CONSTRAINT "shortfall_analytics_daily_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "public"."shortfall_analytics_daily"
ADD CONSTRAINT "shortfall_analytics_daily_branchId_fkey" FOREIGN KEY ("branchId") REFERENCES "public"."branches"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- CreateIndex: unique per day per branch
CREATE UNIQUE INDEX "shortfall_analytics_daily_date_branchKey_key" ON "public"."shortfall_analytics_daily"("date", "branchKey");


