Compare commits
10 Commits
9c77e90c92
...
00585653c7
| Author | SHA1 | Date | |
|---|---|---|---|
| 00585653c7 | |||
| 9b85476c2b | |||
| a0cceeef78 | |||
| e57eb7277f | |||
| 57c075eb25 | |||
| 12b84ec6be | |||
| fa3dbe180a | |||
| 3047e89326 | |||
| ea3efd3767 | |||
| 56cc400d8f |
13
backend/src/main/java/de/strichliste/dto/TallyEntryDto.java
Normal file
13
backend/src/main/java/de/strichliste/dto/TallyEntryDto.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package de.strichliste.dto;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public record TallyEntryDto(
|
||||||
|
Long id,
|
||||||
|
Long employeeId,
|
||||||
|
String employeeFirstName,
|
||||||
|
String employeeLastName,
|
||||||
|
String productName,
|
||||||
|
int priceCents,
|
||||||
|
LocalDateTime createdAt
|
||||||
|
) {}
|
||||||
@@ -187,6 +187,53 @@ public class CompanyAdminResource {
|
|||||||
return Response.ok(line).build();
|
return Response.ok(line).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/entries")
|
||||||
|
public Response getTallyEntries(@QueryParam("token") String token, @QueryParam("month") String month) {
|
||||||
|
AccessLink link = AccessLink.findByToken(token).orElse(null);
|
||||||
|
if (link == null || link.company == null) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
String monthKey = month != null ? month : LocalDateTime.now().format(MONTH_FORMAT);
|
||||||
|
|
||||||
|
List<TallyEntry> entries = TallyEntry.find(
|
||||||
|
"SELECT t FROM TallyEntry t JOIN FETCH t.employee JOIN FETCH t.product " +
|
||||||
|
"WHERE t.employee.company.id = ?1 AND t.monthKey = ?2 ORDER BY t.createdAt DESC",
|
||||||
|
link.company.id, monthKey).list();
|
||||||
|
|
||||||
|
List<TallyEntryDto> dtos = entries.stream()
|
||||||
|
.map(t -> new TallyEntryDto(
|
||||||
|
t.id,
|
||||||
|
t.employee.id,
|
||||||
|
t.employee.firstName,
|
||||||
|
t.employee.lastName,
|
||||||
|
t.product.name,
|
||||||
|
t.priceCentsAtBooking,
|
||||||
|
t.createdAt))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Response.ok(dtos).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DELETE
|
||||||
|
@Path("/entries/{id}")
|
||||||
|
@Transactional
|
||||||
|
public Response deleteTallyEntry(@QueryParam("token") String token, @PathParam("id") Long id) {
|
||||||
|
AccessLink link = AccessLink.findByToken(token).orElse(null);
|
||||||
|
if (link == null || link.company == null) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
TallyEntry entry = TallyEntry.findById(id);
|
||||||
|
if (entry == null || !entry.employee.company.id.equals(link.company.id)) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.delete();
|
||||||
|
return Response.noContent().build();
|
||||||
|
}
|
||||||
|
|
||||||
static MonthlyReportDto buildCompanyReport(Long companyId, String monthKey) {
|
static MonthlyReportDto buildCompanyReport(Long companyId, String monthKey) {
|
||||||
Company company = Company.findById(companyId);
|
Company company = Company.findById(companyId);
|
||||||
List<Employee> employees = Employee.findAllByCompany(companyId);
|
List<Employee> employees = Employee.findAllByCompany(companyId);
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ quarkus.datasource.username=strichliste
|
|||||||
quarkus.datasource.password=strichliste
|
quarkus.datasource.password=strichliste
|
||||||
quarkus.datasource.jdbc.url=jdbc:mariadb://localhost:3306/strichliste
|
quarkus.datasource.jdbc.url=jdbc:mariadb://localhost:3306/strichliste
|
||||||
|
|
||||||
|
# Agroal connection pool – evict stale connections after a DB restart
|
||||||
|
quarkus.datasource.jdbc.background-validation-interval=30S
|
||||||
|
quarkus.datasource.jdbc.idle-removal-interval=5M
|
||||||
|
quarkus.datasource.jdbc.max-lifetime=10M
|
||||||
|
|
||||||
# Hibernate
|
# Hibernate
|
||||||
quarkus.hibernate-orm.database.generation=none
|
quarkus.hibernate-orm.database.generation=none
|
||||||
|
|
||||||
|
|||||||
112
build.sh
112
build.sh
@@ -1,35 +1,44 @@
|
|||||||
#set -euo pipefail
|
#!/bin/bash
|
||||||
set -u
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# build.sh – Build and push Docker images for Strichliste
|
# build.sh – Build and push Docker images
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./build.sh [OPTIONS]
|
# ./build.sh [OPTIONS]
|
||||||
#
|
#
|
||||||
# Options:
|
# Options:
|
||||||
# -v, --version VERSION Image tag / version (default: git short SHA)
|
# -s, --snapshot Version from git ref for prototyping
|
||||||
# -r, --registry REGISTRY Registry prefix (default: "")
|
# -r, --release Version from .env for releases
|
||||||
|
# -v, --version VERSION Custom version
|
||||||
# -p, --push Push images after build
|
# -p, --push Push images after build
|
||||||
# --backend-only Only build backend
|
# -o, --only SERVICE Only build this service (repeatable)
|
||||||
# --frontend-only Only build frontend
|
|
||||||
# -h, --help Show this help
|
# -h, --help Show this help
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
# ./build.sh -v 1.2.3 -r ghcr.io/aquantico --push
|
# ./build.sh -r -p
|
||||||
# ./build.sh --version latest --registry registry.example.com --push
|
# ./build.sh -s -o frontend
|
||||||
# ./build.sh -v dev # build only, no push
|
# ./build.sh -v dev -o backend -o frontend
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
# -e: Exit immediately if any command returns a non-zero exit code
|
||||||
source ".env"
|
# -u: Treat unset variables as errors
|
||||||
|
# -o pipefail: Make pipelines fail if any command in the pipe fails, not just the last one
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
#default: snapshot
|
#cd to script dir
|
||||||
VERSION=$(git rev-parse --short HEAD 2>/dev/null || echo "local")
|
pushd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null
|
||||||
|
SCRIPT_DIR="$(pwd)"
|
||||||
|
source "${SCRIPT_DIR}/.env"
|
||||||
|
# read from .env:
|
||||||
|
# REGISTRY, IMAGE_NAME, IMAGE_VERSION, SNAPSHOT_TAG
|
||||||
|
# SERVICES (subfolder name = image suffix)
|
||||||
|
popd > /dev/null
|
||||||
|
|
||||||
|
#default: build snapshot
|
||||||
|
VERSION="${IMAGE_VERSION}-${SNAPSHOT_TAG}" # read from .env
|
||||||
|
|
||||||
PUSH=false
|
PUSH=false
|
||||||
BUILD_BACKEND=true
|
ONLY=()
|
||||||
BUILD_FRONTEND=true
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
sed -n '/^# Usage:/,/^# ---/p' "$0" | sed 's/^# //' | sed 's/^#//'
|
sed -n '/^# Usage:/,/^# ---/p' "$0" | sed 's/^# //' | sed 's/^#//'
|
||||||
@@ -39,69 +48,54 @@ usage() {
|
|||||||
# --- parse arguments -------------------------------------------------------
|
# --- parse arguments -------------------------------------------------------
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-s|--snapshot) VERSION=$(git rev-parse --short HEAD 2>/dev/null || echo "local"); shift ;;
|
-s|--snapshot) VERSION="${IMAGE_TAG}-SNAPSHOT$(git rev-parse --short HEAD 2>/dev/null || echo "local")"; shift ;;
|
||||||
-r|--release) VERSION=${IMAGE_TAG}; shift ;;
|
-r|--release) VERSION="${IMAGE_TAG}"; shift ;;
|
||||||
-v|--version) VERSION=$2; shift 2 ;;
|
-v|--version) VERSION="$2"; shift 2 ;;
|
||||||
-p|--push) PUSH=true; shift ;;
|
-p|--push) PUSH=true; shift ;;
|
||||||
-b|--backend-only) BUILD_FRONTEND=false; shift ;;
|
-o|--only) ONLY+=("$2"); shift 2 ;;
|
||||||
-f|--frontend-only) BUILD_BACKEND=false; shift ;;
|
-h|--help) usage ;;
|
||||||
-h|--help) usage ;;
|
|
||||||
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# --- derive image names -----------------------------------------------------
|
# if --only was given, filter SERVICES down to those entries
|
||||||
registry_prefix="${REGISTRY}/"
|
if [[ ${#ONLY[@]} -gt 0 ]]; then
|
||||||
BACKEND_IMAGE="${registry_prefix}${IMAGE_NAME}-backend:${VERSION}"
|
SERVICES=("${ONLY[@]}")
|
||||||
FRONTEND_IMAGE="${registry_prefix}${IMAGE_NAME}-frontend:${VERSION}"
|
fi
|
||||||
|
|
||||||
#SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
|
|
||||||
echo "============================================"
|
echo "============================================"
|
||||||
echo " ${IMAGE_NAME} - Docker Build"
|
echo " Docker Build - ${IMAGE_NAME}"
|
||||||
|
echo ""
|
||||||
|
echo " Services : ${SERVICES[*]}"
|
||||||
echo " Version : ${VERSION}"
|
echo " Version : ${VERSION}"
|
||||||
echo " Registry : ${REGISTRY}"
|
echo " Registry : ${REGISTRY}"
|
||||||
echo " Push : ${PUSH}"
|
echo " Push : ${PUSH}"
|
||||||
echo "============================================"
|
echo "============================================"
|
||||||
|
|
||||||
# --- build ------------------------------------------------------------------
|
# --- build ------------------------------------------------------------------
|
||||||
if $BUILD_BACKEND; then
|
for SERVICE in "${SERVICES[@]}"; do
|
||||||
|
IMAGE="${REGISTRY}/${IMAGE_NAME}-${SERVICE}:${VERSION}"
|
||||||
echo ""
|
echo ""
|
||||||
echo ">>> Building backend: ${BACKEND_IMAGE}"
|
echo ">>> Building ${SERVICE}: ${IMAGE}"
|
||||||
docker build \
|
docker build --tag "${IMAGE}" "${SCRIPT_DIR}/${SERVICE}"
|
||||||
--tag "${BACKEND_IMAGE}" \
|
echo " ${SERVICE} built successfully."
|
||||||
"${SCRIPT_DIR}/backend"
|
done
|
||||||
echo " Backend built successfully."
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $BUILD_FRONTEND; then
|
|
||||||
echo ""
|
|
||||||
echo ">>> Building frontend: ${FRONTEND_IMAGE}"
|
|
||||||
docker build \
|
|
||||||
--tag "${FRONTEND_IMAGE}" \
|
|
||||||
"${SCRIPT_DIR}/frontend"
|
|
||||||
echo " Frontend built successfully."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# --- push -------------------------------------------------------------------
|
# --- push -------------------------------------------------------------------
|
||||||
if $PUSH; then
|
if $PUSH; then
|
||||||
docker login ${REGISTRY}
|
docker login "${REGISTRY}" # read from .env
|
||||||
|
for SERVICE in "${SERVICES[@]}"; do
|
||||||
if $BUILD_BACKEND; then
|
IMAGE="${REGISTRY}/${IMAGE_NAME}-${SERVICE}:${VERSION}"
|
||||||
echo ""
|
echo ""
|
||||||
echo ">>> Pushing ${BACKEND_IMAGE}"
|
echo ">>> Pushing ${IMAGE}"
|
||||||
docker push "${BACKEND_IMAGE}"
|
docker push "${IMAGE}"
|
||||||
fi
|
done
|
||||||
if $BUILD_FRONTEND; then
|
|
||||||
echo ""
|
|
||||||
echo ">>> Pushing ${FRONTEND_IMAGE}"
|
|
||||||
docker push "${FRONTEND_IMAGE}"
|
|
||||||
fi
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Images pushed successfully."
|
echo "Images pushed successfully."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done."
|
echo "Done."
|
||||||
if $BUILD_BACKEND; then echo " Backend → ${BACKEND_IMAGE}"; fi
|
for SERVICE in "${SERVICES[@]}"; do
|
||||||
if $BUILD_FRONTEND; then echo " Frontend → ${FRONTEND_IMAGE}"; fi
|
echo " ${SERVICE} → ${REGISTRY}/${IMAGE_NAME}-${SERVICE}:${VERSION}"
|
||||||
|
done
|
||||||
@@ -8,7 +8,7 @@ while true; do
|
|||||||
FILENAME="${BACKUP_DIR}/strichliste_${TIMESTAMP}.sql.gz"
|
FILENAME="${BACKUP_DIR}/strichliste_${TIMESTAMP}.sql.gz"
|
||||||
|
|
||||||
echo "[$(date)] Starting backup..."
|
echo "[$(date)] Starting backup..."
|
||||||
mariadb-dump -h db -u strichliste -pstrichliste strichliste | gzip > "${FILENAME}"
|
mariadb-dump -h db -u strichliste -pstrichliste --single-transaction --skip-lock-tables strichliste | gzip > "${FILENAME}"
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "[$(date)] Backup saved: ${FILENAME}"
|
echo "[$(date)] Backup saved: ${FILENAME}"
|
||||||
|
|||||||
@@ -1,50 +1,73 @@
|
|||||||
|
version: "3"
|
||||||
|
volumes:
|
||||||
|
db-data:
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: mariadb:11.4
|
image: mariadb:11.4.4
|
||||||
|
container_name: qaffee-db
|
||||||
|
restart: always
|
||||||
|
command: --log-warnings=3
|
||||||
environment:
|
environment:
|
||||||
MARIADB_ROOT_PASSWORD: rootpassword
|
- "MARIADB_ROOT_PASSWORD=rootpassword"
|
||||||
MARIADB_DATABASE: strichliste
|
- "MARIADB_DATABASE=strichliste"
|
||||||
MARIADB_USER: strichliste
|
- "MARIADB_USER=strichliste"
|
||||||
MARIADB_PASSWORD: strichliste
|
- "MARIADB_PASSWORD=strichliste"
|
||||||
ports:
|
|
||||||
- "3306:3306"
|
|
||||||
volumes:
|
volumes:
|
||||||
- db-data:/var/lib/mysql
|
- db-data:/var/lib/mysql
|
||||||
- ./db/seed.sql:/docker-entrypoint-initdb.d/seed.sql
|
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
||||||
interval: 10s
|
interval: 10s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
networks:
|
||||||
|
- traefik-net
|
||||||
backend:
|
backend:
|
||||||
build: ./backend
|
build: ./backend
|
||||||
|
container_name: qaffee-backend
|
||||||
environment:
|
environment:
|
||||||
QUARKUS_DATASOURCE_JDBC_URL: jdbc:mariadb://db:3306/strichliste
|
- "QUARKUS_DATASOURCE_JDBC_URL=jdbc:mariadb://db:3306/strichliste"
|
||||||
QUARKUS_DATASOURCE_USERNAME: strichliste
|
- "QUARKUS_DATASOURCE_USERNAME=strichliste"
|
||||||
QUARKUS_DATASOURCE_PASSWORD: strichliste
|
- "QUARKUS_DATASOURCE_PASSWORD=strichliste"
|
||||||
QUARKUS_HTTP_CORS_ORIGINS: http://localhost:5173,http://localhost:4173
|
- "QUARKUS_HTTP_CORS_ORIGINS=https://qaffee.cloud.aquantico.de"
|
||||||
ports:
|
labels:
|
||||||
- "8080:8080"
|
traefik.enable: "true"
|
||||||
|
traefik.docker.network: "traefik-net"
|
||||||
|
traefik.http.routers.qaffee-backend.entrypoints: "websecure"
|
||||||
|
traefik.http.routers.qaffee-backend.rule: "Host(`qaffee-api.cloud.aquantico.de`)"
|
||||||
|
traefik.http.routers.qaffee-backend.tls: "true"
|
||||||
|
traefik.http.routers.qaffee-backend.tls.certresolver: "myresolver"
|
||||||
|
traefik.http.services.qaffee-backend.loadbalancer.server.port: 8080
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
|
- traefik-net
|
||||||
frontend:
|
frontend:
|
||||||
build: ./frontend
|
build: ./frontend
|
||||||
|
container_name: qaffee-frontend
|
||||||
environment:
|
environment:
|
||||||
API_URL: http://backend:8080
|
- "API_URL=http://backend:8080"
|
||||||
ports:
|
ports:
|
||||||
- "3000:3000"
|
- "3000:3000"
|
||||||
|
labels:
|
||||||
|
traefik.enable: "true"
|
||||||
|
traefik.docker.network: "traefik-net"
|
||||||
|
traefik.http.routers.qaffee-frontend.entrypoints: "websecure"
|
||||||
|
traefik.http.routers.qaffee-frontend.rule: "Host(`qaffee.cloud.aquantico.de`)"
|
||||||
|
traefik.http.routers.qaffee-frontend.tls: "true"
|
||||||
|
traefik.http.routers.qaffee-frontend.tls.certresolver: "myresolver"
|
||||||
|
traefik.http.services.qaffee-frontend.loadbalancer.server.port: 3000
|
||||||
depends_on:
|
depends_on:
|
||||||
- backend
|
- backend
|
||||||
|
networks:
|
||||||
|
- traefik-net
|
||||||
backup:
|
backup:
|
||||||
image: mariadb:11.4.4
|
image: mariadb:11.4.4
|
||||||
|
container_name: qaffee-backup
|
||||||
environment:
|
environment:
|
||||||
MARIADB_HOST: db
|
- "MARIADB_HOST=db"
|
||||||
MARIADB_USER: strichliste
|
- "MARIADB_USER=strichliste"
|
||||||
MARIADB_PASSWORD: strichliste
|
- "MARIADB_PASSWORD=strichliste"
|
||||||
volumes:
|
volumes:
|
||||||
- ./backups:/backups
|
- ./backups:/backups
|
||||||
- ./db/backup.sh:/backup.sh
|
- ./db/backup.sh:/backup.sh
|
||||||
@@ -52,6 +75,8 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
networks:
|
||||||
volumes:
|
- traefik-net
|
||||||
db-data:
|
networks:
|
||||||
|
traefik-net:
|
||||||
|
external: false
|
||||||
@@ -44,6 +44,16 @@ export interface MonthlyTally {
|
|||||||
totalCents: number;
|
totalCents: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TallyEntry {
|
||||||
|
id: number;
|
||||||
|
employeeId: number;
|
||||||
|
employeeFirstName: string;
|
||||||
|
employeeLastName: string;
|
||||||
|
productName: string;
|
||||||
|
priceCents: number;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EmployeeReportLine {
|
export interface EmployeeReportLine {
|
||||||
employeeId: number;
|
employeeId: number;
|
||||||
firstName: string;
|
firstName: string;
|
||||||
@@ -119,7 +129,11 @@ export const api = {
|
|||||||
getReport: (token: string, month?: string) =>
|
getReport: (token: string, month?: string) =>
|
||||||
request<MonthlyReport>(`/admin/company/report?token=${token}${month ? `&month=${month}` : ''}`),
|
request<MonthlyReport>(`/admin/company/report?token=${token}${month ? `&month=${month}` : ''}`),
|
||||||
getEmployeeReport: (token: string, employeeId: number, month?: string) =>
|
getEmployeeReport: (token: string, employeeId: number, month?: string) =>
|
||||||
request<EmployeeReportLine>(`/admin/company/report/employee/${employeeId}?token=${token}${month ? `&month=${month}` : ''}`)
|
request<EmployeeReportLine>(`/admin/company/report/employee/${employeeId}?token=${token}${month ? `&month=${month}` : ''}`),
|
||||||
|
getTallyEntries: (token: string, month?: string) =>
|
||||||
|
request<TallyEntry[]>(`/admin/company/entries?token=${token}${month ? `&month=${month}` : ''}`),
|
||||||
|
deleteTallyEntry: (token: string, id: number) =>
|
||||||
|
request<void>(`/admin/company/entries/${id}?token=${token}`, { method: 'DELETE' })
|
||||||
},
|
},
|
||||||
|
|
||||||
// --- Provider Admin ---
|
// --- Provider Admin ---
|
||||||
|
|||||||
@@ -179,6 +179,17 @@
|
|||||||
</table>
|
</table>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<!-- Einträge verwalten -->
|
||||||
|
<section style="margin-bottom: 40px;">
|
||||||
|
<h2 style="margin-bottom: 12px;">Einträge verwalten</h2>
|
||||||
|
<p style="color: var(--color-text-muted); margin-bottom: 12px; font-size: 0.9rem;">
|
||||||
|
Einzelne Produktbuchungen einsehen und bei Bedarf löschen.
|
||||||
|
</p>
|
||||||
|
<a class="btn btn-secondary" href="/admin/company/entries?token={token}">
|
||||||
|
Einträge anzeigen & löschen
|
||||||
|
</a>
|
||||||
|
</section>
|
||||||
|
|
||||||
<!-- Monatsauswertung -->
|
<!-- Monatsauswertung -->
|
||||||
<section>
|
<section>
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
|
||||||
|
|||||||
147
frontend/src/routes/admin/company/entries/+page.svelte
Normal file
147
frontend/src/routes/admin/company/entries/+page.svelte
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { api, type TallyEntry } from '$lib/api/client';
|
||||||
|
import Header from '$lib/components/Header.svelte';
|
||||||
|
import MonthPicker from '$lib/components/MonthPicker.svelte';
|
||||||
|
|
||||||
|
let token = '';
|
||||||
|
let entries: TallyEntry[] = [];
|
||||||
|
let loading = true;
|
||||||
|
let selectedMonth = new Date().toISOString().slice(0, 7);
|
||||||
|
let deletingId: number | null = null;
|
||||||
|
let confirmId: number | null = null;
|
||||||
|
|
||||||
|
$: token = $page.url.searchParams.get('token') ?? '';
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
if (!token) return;
|
||||||
|
await loadEntries();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function loadEntries() {
|
||||||
|
loading = true;
|
||||||
|
entries = await api.companyAdmin.getTallyEntries(token, selectedMonth);
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function changeMonth(e: CustomEvent<string>) {
|
||||||
|
selectedMonth = e.detail;
|
||||||
|
await loadEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
function askConfirm(id: number) {
|
||||||
|
confirmId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function confirmDelete() {
|
||||||
|
if (confirmId === null) return;
|
||||||
|
const idToDelete = confirmId;
|
||||||
|
deletingId = idToDelete;
|
||||||
|
confirmId = null;
|
||||||
|
await api.companyAdmin.deleteTallyEntry(token, idToDelete);
|
||||||
|
deletingId = null;
|
||||||
|
await loadEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPrice(cents: number): string {
|
||||||
|
return (cents / 100).toFixed(2).replace('.', ',') + ' €';
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDateTime(iso: string): string {
|
||||||
|
const d = new Date(iso);
|
||||||
|
return d.toLocaleDateString('de-DE') + ' ' + d.toLocaleTimeString('de-DE', { hour: '2-digit', minute: '2-digit' });
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<title>Einträge löschen – Qaffee</title>
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
|
<Header title="Einträge verwalten" backHref="/admin/company?token={token}" />
|
||||||
|
|
||||||
|
<div class="admin-container">
|
||||||
|
{#if !token}
|
||||||
|
<p>Kein Zugangstoken angegeben.</p>
|
||||||
|
{:else}
|
||||||
|
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px;">
|
||||||
|
<h2>Produkteinträge</h2>
|
||||||
|
<MonthPicker bind:value={selectedMonth} on:change={changeMonth} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if loading}
|
||||||
|
<p>Laden...</p>
|
||||||
|
{:else if entries.length === 0}
|
||||||
|
<p style="color: var(--color-text-muted); text-align: center; margin-top: 40px;">
|
||||||
|
Keine Einträge in diesem Monat.
|
||||||
|
</p>
|
||||||
|
{:else}
|
||||||
|
<p style="color: var(--color-text-muted); margin-bottom: 12px; font-size: 0.9rem;">
|
||||||
|
{entries.length} Einträge · {formatPrice(entries.reduce((s, e) => s + e.priceCents, 0))} gesamt
|
||||||
|
</p>
|
||||||
|
<table class="admin-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Zeitpunkt</th>
|
||||||
|
<th>Mitarbeiter</th>
|
||||||
|
<th>Produkt</th>
|
||||||
|
<th style="text-align: right;">Preis</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{#each entries as entry}
|
||||||
|
<tr>
|
||||||
|
<td style="color: var(--color-text-muted); font-size: 0.85rem; white-space: nowrap;">
|
||||||
|
{formatDateTime(entry.createdAt)}
|
||||||
|
</td>
|
||||||
|
<td>{entry.employeeFirstName} {entry.employeeLastName}</td>
|
||||||
|
<td>{entry.productName}</td>
|
||||||
|
<td style="text-align: right;" class="price">{formatPrice(entry.priceCents)}</td>
|
||||||
|
<td>
|
||||||
|
{#if deletingId === entry.id}
|
||||||
|
<span style="font-size: 0.85rem; color: var(--color-text-muted);">Löschen...</span>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
class="btn btn-secondary"
|
||||||
|
style="padding: 5px 10px; font-size: 0.8rem; color: #e05555; border-color: #e05555;"
|
||||||
|
on:click={() => askConfirm(entry.id)}
|
||||||
|
>
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/each}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if confirmId !== null}
|
||||||
|
{@const confirmEntry = entries.find(e => e.id === confirmId)}
|
||||||
|
<div class="modal-overlay" on:click|self={() => confirmId = null}>
|
||||||
|
<div class="modal">
|
||||||
|
<h2>Eintrag löschen?</h2>
|
||||||
|
{#if confirmEntry}
|
||||||
|
<p style="margin: 16px 0; color: var(--color-text-muted);">
|
||||||
|
<strong style="color: var(--color-text-muted);">{confirmEntry.employeeFirstName} {confirmEntry.employeeLastName}</strong>
|
||||||
|
– {confirmEntry.productName} ({formatPrice(confirmEntry.priceCents)})
|
||||||
|
am {formatDateTime(confirmEntry.createdAt)}
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
|
<p style="margin-bottom: 20px; font-size: 0.9rem;">Dieser Eintrag wird unwiderruflich gelöscht.</p>
|
||||||
|
<div class="modal-actions">
|
||||||
|
<button class="btn btn-secondary" on:click={() => confirmId = null}>Abbrechen</button>
|
||||||
|
<button
|
||||||
|
class="btn btn-primary"
|
||||||
|
style="background: #e05555; border-color: #e05555;"
|
||||||
|
on:click={confirmDelete}
|
||||||
|
>
|
||||||
|
Löschen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
Reference in New Issue
Block a user