Storage Management
Manage storage locations and view stored items
Add New Storage Location
Storage Locations
| Name | Address | Contact Info | Actions |
|---|---|---|---|
Stored Items by Location
No items currently stored in any location.
$data): ?>...
Found by:
Location:
```php getConnection(); // Handle storage location actions if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['add_location'])) { $name = $_POST['name']; $address = $_POST['address']; $contactInfo = $_POST['contactInfo']; $query = "INSERT INTO storage_locations (name, address, contactInfo) VALUES (:name, :address, :contactInfo)"; $stmt = $connection->prepare($query); $stmt->bindParam(':name', $name); $stmt->bindParam(':address', $address); $stmt->bindParam(':contactInfo', $contactInfo); if ($stmt->execute()) { $success = "Storage location added successfully!"; } else { $error = "Error adding storage location."; } } elseif (isset($_POST['delete_location'])) { $locationID = $_POST['locationID']; // Check if location has items $checkQuery = "SELECT COUNT(*) as itemCount FROM items WHERE storageLocationID = :locationID"; $checkStmt = $connection->prepare($checkQuery); $checkStmt->bindParam(':locationID', $locationID); $checkStmt->execute(); $result = $checkStmt->fetch(PDO::FETCH_ASSOC); if ($result['itemCount'] > 0) { $error = "Cannot delete storage location that has items assigned. Reassign items first."; } else { $deleteQuery = "DELETE FROM storage_locations WHERE locationID = :locationID"; $deleteStmt = $connection->prepare($deleteQuery); $deleteStmt->bindParam(':locationID', $locationID); if ($deleteStmt->execute()) { $success = "Storage location deleted successfully!"; } else { $error = "Error deleting storage location."; } } } } // Get all storage locations $locationsQuery = "SELECT * FROM storage_locations ORDER BY name"; $locationsStmt = $connection->prepare($locationsQuery); $locationsStmt->execute(); $storageLocations = $locationsStmt->fetchAll(PDO::FETCH_ASSOC); // Get items by storage location $itemsQuery = " SELECT i.*, sl.name as storageName, r.locationFound, u.name as finderName FROM items i LEFT JOIN storage_locations sl ON i.storageLocationID = sl.locationID LEFT JOIN reports r ON i.reportID = r.reportID LEFT JOIN users u ON r.userId = u.userId WHERE i.storageLocationID IS NOT NULL ORDER BY sl.name, i.createdAt DESC "; $itemsStmt = $connection->prepare($itemsQuery); $itemsStmt->execute(); $storedItems = $itemsStmt->fetchAll(PDO::FETCH_ASSOC); // Group items by storage location $itemsByLocation = []; foreach ($storedItems as $item) { $locationID = $item['storageLocationID']; if (!isset($itemsByLocation[$locationID])) { $itemsByLocation[$locationID] = [ 'location' => $item['storageName'], 'items' => [] ]; } $itemsByLocation[$locationID]['items'][] = $item; } ?>
Manage storage locations and view stored items
| Name | Address | Contact Info | Actions |
|---|---|---|---|
No items currently stored in any location.
$data): ?>...
Found by:
Location: