diff --git a/src/add_packing_list.php b/src/add_packing_list.php
index 773827e..05c3085 100644
--- a/src/add_packing_list.php
+++ b/src/add_packing_list.php
@@ -161,7 +161,7 @@ require_once 'header.php';
-
diff --git a/src/packing_list_detail.php b/src/packing_list_detail.php
index 1b44930..8bb9270 100644
--- a/src/packing_list_detail.php
+++ b/src/packing_list_detail.php
@@ -58,11 +58,12 @@ $stmt_list_owner->close();
$page_title = "Packliste: " . htmlspecialchars($packing_list['name']);
// Robust SQL: Fetches names from Backpacks/Compartments if article is missing
+// FIX: Include backpack own weight in weight_grams calculation
$sql = "SELECT
pli.id, pli.quantity, pli.parent_packing_list_item_id, pli.carrier_user_id,
pli.backpack_id, pli.backpack_compartment_id,
COALESCE(a.name, pli.name, bp.name, bpc.name, 'Unbekanntes Item') AS article_name,
- COALESCE(a.weight_grams, 0) as weight_grams,
+ COALESCE(a.weight_grams, bp.weight_grams, 0) as weight_grams,
a.image_url, a.product_designation, a.consumable,
c.name AS category_name,
m.name AS manufacturer_name,
@@ -132,6 +133,20 @@ function get_recursive_quantity($parent_id, $items_by_parent) {
return $count;
}
+// Helper for recursive weight calculation
+function get_recursive_weight($parent_id, $items_by_parent) {
+ $weight = 0;
+ if (isset($items_by_parent[$parent_id])) {
+ foreach ($items_by_parent[$parent_id] as $child) {
+ // Child weight
+ $weight += ($child['quantity'] * $child['weight_grams']);
+ // Plus its descendants
+ $weight += get_recursive_weight($child['id'], $items_by_parent);
+ }
+ }
+ return $weight;
+}
+
// Recursive Rendering
function render_item_row($item, $level, $items_by_parent) {
$has_children = isset($items_by_parent[$item['id']]);
@@ -159,11 +174,22 @@ function render_item_row($item, $level, $items_by_parent) {
$indent_px = $level * 25;
$weight_display = $item['weight_grams'] > 0 ? number_format($item['weight_grams'], 0, ',', '.') . ' g' : '-';
- $total_weight_display = $item['weight_grams'] > 0 ? number_format($item['weight_grams'] * $item['quantity'], 0, ',', '.') . ' g' : '-';
-
- // Ensure children rows are initially shown or hidden based on some logic? Default shown.
- // But the toggle button should reflect state. Default expanded -> chevron-down.
+ // Calculate Total Weight display logic
+ $total_weight_val = 0;
+ if ($is_backpack || $is_compartment) {
+ // For containers: Recursive weight of children
+ // For backpacks specifically: Add own weight + children
+ $children_weight = get_recursive_weight($item['id'], $items_by_parent);
+ $own_weight = $item['quantity'] * $item['weight_grams']; // Usually 1 * empty_weight
+ $total_weight_val = $own_weight + $children_weight;
+ } else {
+ // Standard items
+ $total_weight_val = $item['weight_grams'] * $item['quantity'];
+ }
+
+ $total_weight_display = ($total_weight_val > 0) ? number_format($total_weight_val, 0, ',', '.') . ' g' : '-';
+
echo '
';
// Name Column with Indentation