From af39340b4bdba3ff293e5f7aff0ac85b33c90b3c Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Fri, 9 Feb 2024 16:17:59 +0100
Subject: [PATCH 1/2] Updated the scrapping emails to include a lot more
 detail.

---
 include/Product.php | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/include/Product.php b/include/Product.php
index a13c1b3..2b246c0 100644
--- a/include/Product.php
+++ b/include/Product.php
@@ -286,21 +286,45 @@ class Product extends Entity {
     }
 
     private function send_discard_email() {
-        $brand = $this->brand;
-        $name = $this->name;
-        $invoice = $this->invoice;
-        $serial = $this->serial;
-        $discardtime = format_date($this->discardtime);
+        $product_data = array('Märke' => $this->get_brand(),
+                              'Namn' => $this->get_name(),
+                              'Serienummer' => $this->get_serial(),
+                              'Fakturanummer' => $this->get_invoice(),
+        );
+        $createtime = format_date($this->get_createtime());
+        $discardtime = format_date($this->get_discardtime());
 
-        $subject = $this->email_subject_prefix.$brand.' '.$name.' skrotad';
+        $subject = $this->email_subject_prefix;
+        $subject .= $this->get_brand().' '.$this->get_name().' skrotad';
         $message = <<<EOF
 Hej!
 
 Följande artikel har skrotats i Boka:
 
-$brand $name, serienummer: $serial, fakturanummer: $invoice
-
 EOF;
+        foreach($product_data as $key => $value) {
+            $message .= "\n$key: $value";
+        }
+        foreach($this->get_info() as $key => $value) {
+            $uckey = ucfirst($key);
+            $message .= "\n$uckey: $value";
+        }
+        $message .= "\nTaggar: ".join(', ', $this->get_tags());
+
+        $message .= "\n\nHistorik:";
+        $message .= "\nSkrotad $discardtime";
+        foreach($this->get_history() as $item) {
+            $starttime = format_date($item->get_starttime());
+            $endtime = format_date($item->get_returntime());
+            $event = "Service";
+            if($item instanceof Loan) {
+                $user = $item->get_user();
+                $event = "Utlånad till ".$user->get_name();
+            }
+            $message .= "\n$event $starttime - $endtime";
+        }
+        $message .= "\nRegistrerad $createtime";
+
         try {
             mb_send_mail($this->discard_email_address,
                          $subject,

From 0ae6b11c216204ca9988b5db63d25e6e9b765a1c Mon Sep 17 00:00:00 2001
From: Erik Thuning <boooink@gmail.com>
Date: Fri, 9 Feb 2024 16:18:23 +0100
Subject: [PATCH 2/2] Indentation fix

---
 include/ProductPage.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/ProductPage.php b/include/ProductPage.php
index bef9807..8f00fa2 100644
--- a/include/ProductPage.php
+++ b/include/ProductPage.php
@@ -114,8 +114,8 @@ class ProductPage extends Page {
                     $end = $event->get_endtime();
                     $extend = format_date(default_loan_end(time()));
                     $note = replace(array('id' => $product->get_id(),
-                                      'end_new' => $extend),
-                                $this->fragments['loan_extend_form']);
+                                          'end_new' => $extend),
+                                    $this->fragments['loan_extend_form']);
                 }
             }
             $rows .= replace(array('status' => $status,