first commit

This commit is contained in:
mdares
2026-04-07 08:54:41 -06:00
commit 3d1a8ba07e
92 changed files with 15392 additions and 0 deletions

View File

@@ -0,0 +1,121 @@
-- CreateTable
CREATE TABLE "Machine" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"type" TEXT NOT NULL,
"relayChannel" INTEGER NOT NULL,
"defaultPriceCents" INTEGER NOT NULL,
"defaultDurationMinutes" INTEGER NOT NULL,
"outOfService" BOOLEAN NOT NULL DEFAULT false,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "Employee" (
"id" TEXT NOT NULL PRIMARY KEY,
"name" TEXT NOT NULL,
"pin" TEXT NOT NULL,
"isAdmin" BOOLEAN NOT NULL DEFAULT false,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "Transaction" (
"id" TEXT NOT NULL PRIMARY KEY,
"machineId" TEXT NOT NULL,
"employeeId" TEXT NOT NULL,
"amountCents" INTEGER NOT NULL,
"paymentMethod" TEXT NOT NULL,
"startedAt" DATETIME NOT NULL,
"expectedEndAt" DATETIME NOT NULL,
"status" TEXT NOT NULL DEFAULT 'pending_relay',
"endedAt" DATETIME,
"relayOnAttemptedAt" DATETIME,
"relayTurnedOnAt" DATETIME,
"relayOffAttemptedAt" DATETIME,
"relayTurnedOffAt" DATETIME,
"relayFailureReason" TEXT,
"voidReason" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Transaction_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "Machine" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Transaction_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "TransactionExtension" (
"id" TEXT NOT NULL PRIMARY KEY,
"transactionId" TEXT NOT NULL,
"employeeId" TEXT NOT NULL,
"extraMinutes" INTEGER NOT NULL,
"extraAmountCents" INTEGER NOT NULL,
"reason" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "TransactionExtension_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "Transaction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "TransactionExtension_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "Shift" (
"id" TEXT NOT NULL PRIMARY KEY,
"employeeId" TEXT NOT NULL,
"startTime" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"endTime" DATETIME,
"startingCashCents" INTEGER NOT NULL,
"expectedCashCents" INTEGER,
"actualCashCents" INTEGER,
"differenceCashCents" INTEGER,
"notes" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Shift_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "CashMovement" (
"id" TEXT NOT NULL PRIMARY KEY,
"shiftId" TEXT NOT NULL,
"employeeId" TEXT NOT NULL,
"type" TEXT NOT NULL,
"amountCents" INTEGER NOT NULL,
"reason" TEXT NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "CashMovement_shiftId_fkey" FOREIGN KEY ("shiftId") REFERENCES "Shift" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "CashMovement_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "AppConfig" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 1,
"businessName" TEXT NOT NULL DEFAULT 'La Burbuja',
"timezone" TEXT NOT NULL DEFAULT 'America/Monterrey',
"currency" TEXT NOT NULL DEFAULT 'MXN',
"serialPortPath" TEXT NOT NULL DEFAULT 'COM3',
"serialBaudRate" INTEGER NOT NULL DEFAULT 9600,
"relayMockMode" BOOLEAN NOT NULL DEFAULT true,
"relayConnected" BOOLEAN NOT NULL DEFAULT false,
"updatedAt" DATETIME NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "Machine_name_key" ON "Machine"("name");
-- CreateIndex
CREATE UNIQUE INDEX "Machine_relayChannel_key" ON "Machine"("relayChannel");
-- CreateIndex
CREATE INDEX "Transaction_expectedEndAt_idx" ON "Transaction"("expectedEndAt");
-- CreateIndex
CREATE INDEX "Transaction_status_idx" ON "Transaction"("status");
-- CreateIndex
CREATE INDEX "Shift_startTime_idx" ON "Shift"("startTime");
-- CreateIndex
CREATE INDEX "CashMovement_createdAt_idx" ON "CashMovement"("createdAt");

View File

@@ -0,0 +1,31 @@
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_AppConfig" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 1,
"businessName" TEXT NOT NULL DEFAULT 'La Burbuja',
"timezone" TEXT NOT NULL DEFAULT 'America/Monterrey',
"currency" TEXT NOT NULL DEFAULT 'MXN',
"serialPortPath" TEXT NOT NULL DEFAULT 'COM3',
"serialBaudRate" INTEGER NOT NULL DEFAULT 9600,
"relayMockMode" BOOLEAN NOT NULL DEFAULT true,
"relayConnected" BOOLEAN NOT NULL DEFAULT false,
"selfServiceWashPriceCents" INTEGER NOT NULL DEFAULT 4500,
"selfServiceDryPriceCents" INTEGER NOT NULL DEFAULT 4500,
"selfServiceCycleMinutes" INTEGER NOT NULL DEFAULT 50,
"encargoPricePerKgCents" INTEGER NOT NULL DEFAULT 3300,
"encargoMinimumChargeCents" INTEGER NOT NULL DEFAULT 12000,
"xlEdredonIndividualCents" INTEGER NOT NULL DEFAULT 15000,
"xlEdredonMatrimonialCents" INTEGER NOT NULL DEFAULT 18000,
"xlEdredonKingCents" INTEGER NOT NULL DEFAULT 20000,
"xlCobijaGruesaCents" INTEGER NOT NULL DEFAULT 12000,
"xlAlmohadaParCents" INTEGER NOT NULL DEFAULT 8000,
"dryCleaningMinimumCents" INTEGER NOT NULL DEFAULT 15000,
"dryCleaningUrgentSurchargePct" INTEGER NOT NULL DEFAULT 50,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_AppConfig" ("businessName", "currency", "id", "relayConnected", "relayMockMode", "serialBaudRate", "serialPortPath", "timezone", "updatedAt") SELECT "businessName", "currency", "id", "relayConnected", "relayMockMode", "serialBaudRate", "serialPortPath", "timezone", "updatedAt" FROM "AppConfig";
DROP TABLE "AppConfig";
ALTER TABLE "new_AppConfig" RENAME TO "AppConfig";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -0,0 +1,157 @@
/*
Warnings:
- Added the required column `baseAmountCents` to the `Transaction` table without a default value. This is not possible if the table is not empty.
- Added the required column `customerId` to the `Transaction` table without a default value. This is not possible if the table is not empty.
- Added the required column `ticketNumber` to the `Transaction` table without a default value. This is not possible if the table is not empty.
*/
-- CreateTable
CREATE TABLE "Customer" (
"id" TEXT NOT NULL PRIMARY KEY,
"firstName" TEXT NOT NULL,
"lastName" TEXT NOT NULL,
"phone" TEXT NOT NULL,
"email" TEXT,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "Customer" ("id", "firstName", "lastName", "phone", "email", "isActive", "createdAt", "updatedAt")
VALUES ('legacy-customer', 'Cliente', 'Mostrador', 'LEGACY-UNASSIGNED', NULL, true, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_AppConfig" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 1,
"businessName" TEXT NOT NULL DEFAULT 'La Burbuja',
"timezone" TEXT NOT NULL DEFAULT 'America/Monterrey',
"currency" TEXT NOT NULL DEFAULT 'MXN',
"serialPortPath" TEXT NOT NULL DEFAULT 'COM3',
"serialBaudRate" INTEGER NOT NULL DEFAULT 9600,
"relayMockMode" BOOLEAN NOT NULL DEFAULT true,
"relayConnected" BOOLEAN NOT NULL DEFAULT false,
"selfServiceWashPriceCents" INTEGER NOT NULL DEFAULT 4500,
"selfServiceDryPriceCents" INTEGER NOT NULL DEFAULT 4500,
"selfServiceCycleMinutes" INTEGER NOT NULL DEFAULT 50,
"encargoPricePerKgCents" INTEGER NOT NULL DEFAULT 3300,
"encargoMinimumChargeCents" INTEGER NOT NULL DEFAULT 12000,
"xlEdredonIndividualCents" INTEGER NOT NULL DEFAULT 15000,
"xlEdredonMatrimonialCents" INTEGER NOT NULL DEFAULT 18000,
"xlEdredonKingCents" INTEGER NOT NULL DEFAULT 20000,
"xlCobijaGruesaCents" INTEGER NOT NULL DEFAULT 12000,
"xlAlmohadaParCents" INTEGER NOT NULL DEFAULT 8000,
"dryCleaningMinimumCents" INTEGER NOT NULL DEFAULT 15000,
"dryCleaningUrgentSurchargePct" INTEGER NOT NULL DEFAULT 50,
"detergentAddonCents" INTEGER NOT NULL DEFAULT 500,
"softenerAddonCents" INTEGER NOT NULL DEFAULT 500,
"bleachAddonCents" INTEGER NOT NULL DEFAULT 500,
"loyaltyEveryNTransactions" INTEGER NOT NULL DEFAULT 10,
"loyaltyDiscountPct" INTEGER NOT NULL DEFAULT 50,
"updatedAt" DATETIME NOT NULL
);
INSERT INTO "new_AppConfig" ("businessName", "currency", "dryCleaningMinimumCents", "dryCleaningUrgentSurchargePct", "encargoMinimumChargeCents", "encargoPricePerKgCents", "id", "relayConnected", "relayMockMode", "selfServiceCycleMinutes", "selfServiceDryPriceCents", "selfServiceWashPriceCents", "serialBaudRate", "serialPortPath", "timezone", "updatedAt", "xlAlmohadaParCents", "xlCobijaGruesaCents", "xlEdredonIndividualCents", "xlEdredonKingCents", "xlEdredonMatrimonialCents") SELECT "businessName", "currency", "dryCleaningMinimumCents", "dryCleaningUrgentSurchargePct", "encargoMinimumChargeCents", "encargoPricePerKgCents", "id", "relayConnected", "relayMockMode", "selfServiceCycleMinutes", "selfServiceDryPriceCents", "selfServiceWashPriceCents", "serialBaudRate", "serialPortPath", "timezone", "updatedAt", "xlAlmohadaParCents", "xlCobijaGruesaCents", "xlEdredonIndividualCents", "xlEdredonKingCents", "xlEdredonMatrimonialCents" FROM "AppConfig";
DROP TABLE "AppConfig";
ALTER TABLE "new_AppConfig" RENAME TO "AppConfig";
CREATE TABLE "new_Transaction" (
"id" TEXT NOT NULL PRIMARY KEY,
"ticketNumber" INTEGER NOT NULL,
"machineId" TEXT NOT NULL,
"employeeId" TEXT NOT NULL,
"customerId" TEXT NOT NULL,
"baseAmountCents" INTEGER NOT NULL,
"discountCents" INTEGER NOT NULL DEFAULT 0,
"loyaltyDiscountApplied" BOOLEAN NOT NULL DEFAULT false,
"addonDetergentQty" INTEGER NOT NULL DEFAULT 0,
"addonSoftenerQty" INTEGER NOT NULL DEFAULT 0,
"addonBleachQty" INTEGER NOT NULL DEFAULT 0,
"addonAmountCents" INTEGER NOT NULL DEFAULT 0,
"amountCents" INTEGER NOT NULL,
"paymentMethod" TEXT NOT NULL,
"startedAt" DATETIME NOT NULL,
"expectedEndAt" DATETIME NOT NULL,
"status" TEXT NOT NULL DEFAULT 'pending_relay',
"endedAt" DATETIME,
"relayOnAttemptedAt" DATETIME,
"relayTurnedOnAt" DATETIME,
"relayOffAttemptedAt" DATETIME,
"relayTurnedOffAt" DATETIME,
"relayFailureReason" TEXT,
"voidReason" TEXT,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
CONSTRAINT "Transaction_machineId_fkey" FOREIGN KEY ("machineId") REFERENCES "Machine" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Transaction_employeeId_fkey" FOREIGN KEY ("employeeId") REFERENCES "Employee" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Transaction_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "Customer" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Transaction" (
"id",
"ticketNumber",
"machineId",
"employeeId",
"customerId",
"baseAmountCents",
"discountCents",
"loyaltyDiscountApplied",
"addonDetergentQty",
"addonSoftenerQty",
"addonBleachQty",
"addonAmountCents",
"amountCents",
"paymentMethod",
"startedAt",
"expectedEndAt",
"status",
"endedAt",
"relayOnAttemptedAt",
"relayTurnedOnAt",
"relayOffAttemptedAt",
"relayTurnedOffAt",
"relayFailureReason",
"voidReason",
"createdAt",
"updatedAt"
)
SELECT
"id",
ROW_NUMBER() OVER (ORDER BY "createdAt", "id") AS "ticketNumber",
"machineId",
"employeeId",
'legacy-customer' AS "customerId",
"amountCents" AS "baseAmountCents",
0 AS "discountCents",
false AS "loyaltyDiscountApplied",
0 AS "addonDetergentQty",
0 AS "addonSoftenerQty",
0 AS "addonBleachQty",
0 AS "addonAmountCents",
"amountCents",
"paymentMethod",
"startedAt",
"expectedEndAt",
"status",
"endedAt",
"relayOnAttemptedAt",
"relayTurnedOnAt",
"relayOffAttemptedAt",
"relayTurnedOffAt",
"relayFailureReason",
"voidReason",
"createdAt",
"updatedAt"
FROM "Transaction";
DROP TABLE "Transaction";
ALTER TABLE "new_Transaction" RENAME TO "Transaction";
CREATE UNIQUE INDEX "Transaction_ticketNumber_key" ON "Transaction"("ticketNumber");
CREATE INDEX "Transaction_expectedEndAt_idx" ON "Transaction"("expectedEndAt");
CREATE INDEX "Transaction_status_idx" ON "Transaction"("status");
CREATE INDEX "Transaction_customerId_idx" ON "Transaction"("customerId");
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
-- CreateIndex
CREATE UNIQUE INDEX "Customer_phone_key" ON "Customer"("phone");
-- CreateIndex
CREATE INDEX "Customer_lastName_firstName_idx" ON "Customer"("lastName", "firstName");

View File

@@ -0,0 +1 @@
ALTER TABLE "Transaction" ADD COLUMN "serviceType" TEXT NOT NULL DEFAULT 'autoservicio';

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"