Upload via GUI (364 Dateien)
This commit is contained in:
@@ -49,10 +49,20 @@ function vacation_hand_over(PDO $pdo, int $staffId): int
|
||||
$t = $pdo->prepare("SELECT id, ticket_number, subject FROM tickets WHERE assigned_staff_id = ? AND is_spam = 0 AND status NOT IN ('resolved','closed') ORDER BY id");
|
||||
$t->execute([$staffId]);
|
||||
$tickets = $t->fetchAll();
|
||||
foreach ($tickets as $row) {
|
||||
$pdo->prepare('UPDATE tickets SET assigned_staff_id = ? WHERE id = ?')->execute([$to, $row['id']]);
|
||||
$pdo->prepare('INSERT INTO vacation_moves (ticket_id, from_staff_id, to_staff_id, created_at) VALUES (?,?,?,?)')->execute([$row['id'], $staffId, $to, db_now()]);
|
||||
log_activity($pdo, (int) $row['id'], $staffId, 'An die Vertretung ' . $toName . ' weitergegeben (' . $name . ' ist abwesend)');
|
||||
$own = !$pdo->inTransaction();
|
||||
if ($own) $pdo->beginTransaction(); // entweder alles (Zuweisung und Vermerk zur Rückgabe) oder nichts
|
||||
try {
|
||||
$move = $pdo->prepare('UPDATE tickets SET assigned_staff_id = ? WHERE id = ?');
|
||||
$note = $pdo->prepare('INSERT INTO vacation_moves (ticket_id, from_staff_id, to_staff_id, created_at) VALUES (?,?,?,?)');
|
||||
foreach ($tickets as $row) {
|
||||
$move->execute([$to, $row['id']]);
|
||||
$note->execute([$row['id'], $staffId, $to, db_now()]);
|
||||
log_activity($pdo, (int) $row['id'], $staffId, 'An die Vertretung ' . $toName . ' weitergegeben (' . $name . ' ist abwesend)');
|
||||
}
|
||||
if ($own) $pdo->commit();
|
||||
} catch (Throwable $e) {
|
||||
if ($own && $pdo->inTransaction()) $pdo->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
if ($tickets) {
|
||||
$list = '';
|
||||
@@ -113,9 +123,15 @@ function vacation_apply_change(PDO $pdo, int $staffId, array $before, array $aft
|
||||
function vacation_expand_ids(PDO $pdo, array $ids): array
|
||||
{
|
||||
$out = [];
|
||||
foreach (array_unique(array_map('intval', $ids)) as $id) {
|
||||
if ($id <= 0) continue;
|
||||
$target = staff_is_on_vacation($id) ? vacation_target($pdo, $id) : $id;
|
||||
$ids = array_values(array_filter(array_unique(array_map('intval', $ids)), fn($id) => $id > 0));
|
||||
if (!$ids) return [];
|
||||
// Wer im Urlaub ist, in einer Abfrage ermitteln (statt eine je Mitarbeiter)
|
||||
$inIds = implode(',', array_fill(0, count($ids), '?'));
|
||||
$away = $pdo->prepare("SELECT id FROM staff WHERE is_on_vacation = 1 AND id IN ($inIds)");
|
||||
$away->execute($ids);
|
||||
$awayIds = array_flip(array_map('intval', $away->fetchAll(PDO::FETCH_COLUMN)));
|
||||
foreach ($ids as $id) {
|
||||
$target = isset($awayIds[$id]) ? vacation_target($pdo, $id) : $id;
|
||||
if ($target !== null) $out[$target] = $target;
|
||||
}
|
||||
if (!$out) return [];
|
||||
|
||||
Reference in New Issue
Block a user