1 parent
61fc46df6e
commit
0b39acbf30
4 files changed
+48
-10
No files matched your search
@@ -36,11 +36,13 @@ 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'],
|
||||
]]);
|
||||
}
|
||||
|
||||
@@ -101,6 +103,11 @@ 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]);
|
||||
|
||||
@@ -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, uploaded_at
|
||||
"SELECT id, stock_lot_id, original_filename, mime_type, size_bytes, comment, uploaded_at
|
||||
FROM stock_lot_document
|
||||
WHERE stock_lot_id IN ({$placeholders})
|
||||
ORDER BY stock_lot_id, id"
|
||||
@@ -299,6 +299,7 @@ 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'],
|
||||
];
|
||||
}
|
||||
@@ -308,7 +309,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
|
||||
'SELECT id, stock_lot_id, original_filename, stored_filename, mime_type, size_bytes, comment
|
||||
FROM stock_lot_document WHERE id = :id'
|
||||
);
|
||||
$stmt->execute([':id' => $documentId]);
|
||||
@@ -319,6 +320,22 @@ 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);
|
||||
@@ -336,7 +353,7 @@ function delete_stock_lot_document(PDO $pdo, int $documentId): void
|
||||
}
|
||||
}
|
||||
|
||||
function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $uploadedBy): array
|
||||
function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $comment, string $uploadedBy): array
|
||||
{
|
||||
if ($lotId <= 0 || !is_uploaded_file((string) ($file['tmp_name'] ?? ''))) {
|
||||
throw new InvalidArgumentException('Ungültige Dokumentdatei');
|
||||
@@ -372,8 +389,8 @@ function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $up
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
'INSERT INTO stock_lot_document
|
||||
(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)
|
||||
(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)
|
||||
RETURNING id'
|
||||
);
|
||||
$stmt->execute([
|
||||
@@ -382,6 +399,7 @@ function upload_stock_lot_document(PDO $pdo, int $lotId, array $file, string $up
|
||||
':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());
|
||||
|
||||
Reference in new issue
Block a user