Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/readme-screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: npm run build

- name: Generate screenshots
run: npm run screenshots
run: npm run screenshots:ci

- name: Configure GitHub Pages
uses: actions/configure-pages@v5
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Create DB Migrations (for production)
### Open ToDos
- Automatisches abmelden aller Accounts nach update (via changes)
- Android Zahlentastatur Komma ausgeblendet
- Kostenanpassung bei Gruppenbestellung greift für alle der gleichen Kategorien
#### Nice Improvements:
- Item-Page: Item-Reihenfolge anpassbar machen (persistent)
- Item-Page: Kategorie-filter für user persistieren
- Gruppen-Split
- Verrechnungskonten-Auszahlung für Admins auch selbst möglich
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"lint": "eslint .",
"start": "next start",
"test": "vitest",
"screenshots": "npm run screenshots:seed && npm run screenshots:capture",
"screenshots:seed": "jiti scripts/screenshots/seed.ts",
"screenshots:capture": "jiti scripts/screenshots/capture.ts",
"screenshots": "jiti scripts/screenshots/capture.ts",
"screenshots:ci": "npm run db:seed && npm run screenshots:capture",
"db:generate": "prisma generate",
"db:migrate": "npx prisma migrate dev",
"db:migrate:prod": "npx prisma migrate deploy",
"db:push": "npx prisma db push",
"db:studio": "npx prisma studio"
"db:studio": "npx prisma studio",
"db:seed": "jiti scripts/screenshots/seed.ts"
},
"dependencies": {
"@headlessui/react": "^2.0.3",
Expand Down Expand Up @@ -83,4 +84,4 @@
"@types/react": "19.2.7",
"@types/react-dom": "19.2.3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
-- Add canonical item IDs to preserve logical item identity across immutable item copies
-- Rebuild the tables directly so the migration also recovers from a failed
-- earlier attempt that already added nullable canonicalItemId columns.
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;

DROP TABLE IF EXISTS "new_Item";
DROP TABLE IF EXISTS "new_ItemCategoryMapping";

CREATE TABLE "new_Item" (
"id" TEXT NOT NULL PRIMARY KEY,
"canonicalItemId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"price" REAL NOT NULL,
"is_active" BOOLEAN NOT NULL DEFAULT true,
"for_grouporders" BOOLEAN NOT NULL DEFAULT false,
"accountId" TEXT NOT NULL,
CONSTRAINT "Item_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "ClearingAccount" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Item" ("id", "canonicalItemId", "name", "price", "is_active", "for_grouporders", "accountId")
SELECT "id", "id", "name", "price", "is_active", "for_grouporders", "accountId"
FROM "Item";
DROP TABLE "Item";
ALTER TABLE "new_Item" RENAME TO "Item";
CREATE INDEX IF NOT EXISTS "Item_canonicalItemId_idx" ON "Item"("canonicalItemId");

CREATE TABLE "new_ItemCategoryMapping" (
"id" TEXT NOT NULL PRIMARY KEY,
"canonicalItemId" TEXT NOT NULL,
"itemId" TEXT NOT NULL,
"transactionId" TEXT NOT NULL,
CONSTRAINT "ItemCategoryMapping_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "Item" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "ItemCategoryMapping_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "Transaction" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_ItemCategoryMapping" ("id", "canonicalItemId", "itemId", "transactionId")
SELECT
"ItemCategoryMapping"."id",
(SELECT "Item"."canonicalItemId" FROM "Item" WHERE "Item"."id" = "ItemCategoryMapping"."itemId"),
"ItemCategoryMapping"."itemId",
"ItemCategoryMapping"."transactionId"
FROM "ItemCategoryMapping";
DROP TABLE "ItemCategoryMapping";
ALTER TABLE "new_ItemCategoryMapping" RENAME TO "ItemCategoryMapping";
CREATE INDEX IF NOT EXISTS "ItemCategoryMapping_canonicalItemId_idx" ON "ItemCategoryMapping"("canonicalItemId");

PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
4 changes: 4 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ model Item {
// items must be immutable and shouldn't be deleted (if transactions exists)
// - create copy instead and set is_active=false
id String @id @default(cuid())
canonicalItemId String
name String
categories Category[]
price Float
Expand All @@ -29,6 +30,7 @@ model Item {
is_active Boolean @default(true)
for_grouporders Boolean @default(false)
accountId String
@@index([canonicalItemId])
}

model ProcurementItem {
Expand Down Expand Up @@ -107,11 +109,13 @@ model ClearingAccount {
model ItemCategoryMapping {
id String @id @default(cuid())
item Item @relation(fields: [itemId], references: [id])
canonicalItemId String
categories Category[]

Transaction Transaction @relation(fields: [transactionId], references: [id])
itemId String
transactionId String
@@index([canonicalItemId])
}

model ProcurementItemBilling {
Expand Down
3 changes: 3 additions & 0 deletions scripts/screenshots/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ async function seed() {
await prisma.item.create({
data: {
id: item.id,
canonicalItemId: item.id,
name: item.name,
price: item.price,
for_grouporders: item.for_grouporders ?? false,
Expand Down Expand Up @@ -246,6 +247,7 @@ async function seed() {
items: {
create: {
item: { connect: { id: ids.items[0] } },
canonicalItemId: ids.items[0],
categories: { connect: [{ id: ids.categories[0] }] },
},
},
Expand Down Expand Up @@ -282,6 +284,7 @@ async function seed() {
items: {
create: {
item: { connect: { id: ids.items[1] } },
canonicalItemId: ids.items[1],
categories: { connect: [{ id: ids.categories[1] }] },
},
},
Expand Down
26 changes: 20 additions & 6 deletions src/components/General/Balance.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import type { HTMLProps } from "react"

type Props = {
balance?: number
balance?: number,
allowOverdraw?: boolean
}
export const Balance = (props: Props) => {
if (props.balance === undefined) {
return <div className="skeleton h-5 w-9"></div>
} else {
let color = ""
if (props.balance > 0) {
color = "text-green-600"
} else if (props.balance < 0) {
color = "text-red-700"
let color: HTMLProps<HTMLElement>["className"] = ""
if (props.allowOverdraw) {
if (props.balance > 0) {
color = "text-gray-300"
} else if (props.balance < -150) {
color = "text-amber-700"
} else if (props.balance < 0) {
color = "text-blue-grey-600"
}
}
else {
if (props.balance > 0) {
color = "text-green-600"
} else if (props.balance < 0) {
color = "text-red-700"
}
}
return <span className={`font-bold ${color}`}>{props.balance.toFixed(2)}€</span>
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export default function Header() {
<LowCreditWarningSymbol />
<div className="mr-4">
<Link href="/account" className="transition-transform duration-200 hover:scale-105">
<Balance balance={userData?.balance} />
<Balance balance={userData?.balance} allowOverdraw={userData?.allowOverdraw} />
</Link>
</div>
<div className="avatar placeholder dropdown dropdown-end">
Expand Down
2 changes: 1 addition & 1 deletion src/components/PageComponents/UserOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const UserOverview = () => {
</div>
</td>
<td className="text-right">
<Balance balance={user.balance} />
<Balance balance={user.balance} allowOverdraw={user.allowOverdraw} />
</td>
<td className="text-center hidden md:table-cell">
{user.allowOverdraw ? (
Expand Down
Loading
Loading