0) { $query .= " AND sede_id = :sede_id"; } $stmt = $db->prepare($query); $stmt->bindParam(':product_id', $productId, PDO::PARAM_INT); if ($sedeId > 0) { $stmt->bindParam(':sede_id', $sedeId, PDO::PARAM_INT); } $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); if (empty($results)) { echo json_encode(['message' => 'No se encontraron unidades con estado En Almacén.']); } else { echo json_encode($results); } } catch (PDOException $e) { http_response_code(500); echo json_encode(['error' => 'Database error: ' . $e->getMessage()]); } ?>