From 437ec951bd4f84ee2edd8ed906e6f827e1b97d81 Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Mon, 26 Feb 2024 13:10:50 +0100
Subject: [PATCH] Past inventories used to list all current products, not just
 the ones that existed at the time of inventory. Fixed.

---
 include/Page.php | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/Page.php b/include/Page.php
index e302222..8f79010 100644
--- a/include/Page.php
+++ b/include/Page.php
@@ -295,13 +295,19 @@ abstract class Page extends Responder {
     final protected function build_inventory_details($inventory,
                                                      $interactive = true) {
         $startdate = format_date($inventory->get_starttime());
-        $all_products = get_items('product');
         $seen = $inventory->get_seen_products();
         $unseen = array();
-        foreach($all_products as $product) {
-            if(!in_array($product, $seen)) {
-                $unseen[] = $product;
+        if($interactive) {
+            $all_products = get_items('product');
+            $total_count = count($all_products);
+            foreach($all_products as $product) {
+                if(!in_array($product, $seen)) {
+                    $unseen[] = $product;
+                }
             }
+        } else {
+            $unseen = $inventory->get_unseen_products();
+            $total_count = count($unseen) + count($seen);
         }
         $missing = i18n('Missing products');
         $hidden = 'hidden';
@@ -318,7 +324,7 @@ abstract class Page extends Responder {
             $seen_table = $this->build_seen_table($seen, $inventory);
         }
         return replace(array('start_date' => $startdate,
-                             'total_count' => count($all_products),
+                             'total_count' => $total_count,
                              'seen_count' => count($seen),
                              'hide' => $hidden,
                              'unseen_title' => $missing,