| Server IP : 3.111.61.48 / Your IP : 216.73.216.67 Web Server : Apache System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.2.31 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/vhost/itms.arukustech.com/public/api/ |
Upload File : |
<?php
require_once __DIR__ . '/../../app/db.php';
require_once __DIR__ . '/../../app/helpers/auth.php';
auth();
// Check if IDs are provided
if (empty($_POST['ids']) || !is_array($_POST['ids'])) {
header("Location: /rented_assign_list.php?error=No items selected");
exit;
}
$pdo = db();
$admin_id = $_SESSION['user_id']; // The admin performing the return
try {
$pdo->beginTransaction();
// 1. Prepare Statement: Mark assignment as returned
$stAssign = $pdo->prepare("
UPDATE rented_assignments
SET status = 'returned',
returned_at = NOW(),
returned_by = ?
WHERE id = ? AND status = 'assigned'
");
// 2. Prepare Statement: Reset inventory status and clear previous user link
$stInv = $pdo->prepare("
UPDATE rented_inventory ri
JOIN rented_assignments ra ON ri.id = ra.rented_inventory_id
SET ri.status = 'available',
ri.assigned_to = NULL,
ri.assigned_at = NULL
WHERE ra.id = ?
");
foreach ($_POST['ids'] as $id) {
$stAssign->execute([$admin_id, $id]);
$stInv->execute([$id]);
}
$pdo->commit();
header("Location: /rented_assign_list.php?msg=Items marked as returned successfully");
exit;
} catch (Exception $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
// You can change 'die' to a redirect with an error message
header("Location: /rented_assign_list.php?error=Return process failed");
exit;
}