Remove lot document comments

This commit is contained in:
gitea_admin committed 2026-09-08 12:17:49 +02:00
1 parent f130092d40
commit 3a3de9da22
4 files changed
+10 -48

No files matched your search

-7
View File
@@ -36,13 +36,11 @@ try {
$pdo,
(int) ($_POST['lotId'] ?? 0),
$file,
(string) ($_POST['comment'] ?? ''),
(string) ($currentUser['username'] ?? $currentUser['email'] ?? 'unknown')
);
json_response(201, ['ok' => true, 'document' => [
'id' => (int) $document['id'],
'original_filename' => (string) $document['original_filename'],
'comment' => $document['comment'] === null ? '' : (string) $document['comment'],
]]);
}
@@ -103,11 +101,6 @@ try {
json_response(200, ['ok' => true, 'productId' => $productId, 'availableQty' => get_lager_product_available_qty($pdo, $productId)]);
}
if ($action === 'update_document_comment') {
update_stock_lot_document_comment($pdo, (int) ($data['documentId'] ?? 0), (string) ($data['comment'] ?? ''));
json_response(200, ['ok' => true]);
}
if ($action === 'delete_document') {
delete_stock_lot_document($pdo, (int) ($data['documentId'] ?? 0));
json_response(200, ['ok' => true]);
+5 -23
View File
@@ -286,7 +286,7 @@ function get_stock_lot_documents_by_lot_ids(PDO $pdo, array $lotIds): array
$placeholders = implode(',', array_fill(0, count($lotIds), '?'));
$stmt = $pdo->prepare(
"SELECT id, stock_lot_id, original_filename, mime_type, size_bytes, comment, uploaded_at
"SELECT id, stock_lot_id, original_filename, mime_type, size_bytes, uploaded_at
FROM stock_lot_document
WHERE stock_lot_id IN ({$placeholders})
ORDER BY stock_lot_id, id"
@@ -299,7 +299,6 @@ function get_stock_lot_documents_by_lot_ids(PDO $pdo, array $lotIds): array
'original_filename' => (string) $row['original_filename'],
'mime_type' => (string) $row['mime_type'],
'size_bytes' => (int) $row['size_bytes'],
'comment' => $row['comment'] === null ? '' : (string) $row['comment'],
'uploaded_at' => (string) $row['uploaded_at'],
];
}
@@ -309,7 +308,7 @@ function get_stock_lot_documents_by_lot_ids(PDO $pdo, array $lotIds): array
function get_stock_lot_document(PDO $pdo, int $documentId): array
{
$stmt = $pdo->prepare(
'SELECT id, stock_lot_id, original_filename, stored_filename, mime_type, size_bytes, comment
'SELECT id, stock_lot_id, original_filename, stored_filename, mime_type, size_bytes
FROM stock_lot_document WHERE id = :id'
);
$stmt->execute([':id' => $documentId]);
@@ -320,22 +319,6 @@ function get_stock_lot_document(PDO $pdo, int $documentId): array
return $document;
}
function update_stock_lot_document_comment(PDO $pdo, int $documentId, string $comment): void
{
$document = get_stock_lot_document($pdo, $documentId);
$statusStmt = $pdo->prepare('SELECT status FROM stock_lot WHERE id = :id');
$statusStmt->execute([':id' => (int) $document['stock_lot_id']]);
$status = $statusStmt->fetchColumn();
if ($status !== 'current' && $status !== 'open') {
throw new InvalidArgumentException('Dokumente vergangener Chargen können nicht bearbeitet werden');
}
$stmt = $pdo->prepare('UPDATE stock_lot_document SET comment = :comment WHERE id = :id');
$stmt->execute([':comment' => trim($comment) === '' ? null : trim($comment), ':id' => $documentId]);
if ($stmt->rowCount() !== 1) {
throw new RuntimeException('Dokument nicht gefunden');
}
}
function delete_stock_lot_document(PDO $pdo, int $documentId): void
{
$document = get_stock_lot_document($pdo, $documentId);
@@ -353,7 +336,7 @@ function delete_stock_lot_document(PDO $pdo, int $documentId): void
}
}
function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $comment, string $uploadedBy): array
function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $uploadedBy): array
{
if ($lotId <= 0 || !is_uploaded_file((string) ($file['tmp_name'] ?? ''))) {
throw new InvalidArgumentException('Ungültige Dokumentdatei');
@@ -389,8 +372,8 @@ function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $co
try {
$stmt = $pdo->prepare(
'INSERT INTO stock_lot_document
(stock_lot_id, original_filename, stored_filename, mime_type, size_bytes, comment, uploaded_by)
VALUES (:lot_id, :original_filename, :stored_filename, :mime_type, :size_bytes, :comment, :uploaded_by)
(stock_lot_id, original_filename, stored_filename, mime_type, size_bytes, uploaded_by)
VALUES (:lot_id, :original_filename, :stored_filename, :mime_type, :size_bytes, :uploaded_by)
RETURNING id'
);
$stmt->execute([
@@ -399,7 +382,6 @@ function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $co
':stored_filename' => $storedFilename,
':mime_type' => $mimeType,
':size_bytes' => $size,
':comment' => trim($comment) === '' ? null : trim($comment),
':uploaded_by' => $uploadedBy,
]);
return get_stock_lot_document($pdo, (int) $stmt->fetchColumn());