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] 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,