From 1bb75066ce34bef83b6ac11cff5a2907d9aa06a1 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Wed, 11 Mar 2020 03:08:12 +0000
Subject: [PATCH] Bug 5103: (follow-up) Using mapped item fields instead of
 hardcoding subfields

Signed-off-by: David Nind <david@davidnind.com>
---
 catalogue/MARCdetail.pl | 8 ++++++--
 cataloguing/additem.pl  | 8 +++++++-
 opac/opac-MARCdetail.pl | 8 ++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl
index 36b56a37f2..32b51e81f2 100755
--- a/catalogue/MARCdetail.pl
+++ b/catalogue/MARCdetail.pl
@@ -297,8 +297,12 @@ foreach my $field (@fields) {
 
         $norequests = 0 if  $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.notforloan' and $subf[$i][1] == 0;
 
-        if ( $subf[$i][0] eq 'd' || $subf[$i][0] eq 'q' || $subf[$i][0] eq 'r' || $subf[$i][0] eq 's' || $subf[$i][0] eq 'w' ){
-            # date accessioned || on loan || date last seen || date last borrowed || replacement price date
+        if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.dateaccessioned' ||
+             $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.onloan' ||
+             $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastseen' ||
+             $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastborrowed' ||
+             $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.replacementpricedate'
+        ){
             $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });
         }
     }
diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 109c76c0b6..0a7fb2505d 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -864,7 +864,13 @@ for my $row ( @big_array ) {
         } else {
             $item_field->{field} = '';
         }
-        if ( $key eq 'd' || $key eq 'q' || $key eq 'r' || $key eq 's' || $key eq 'w' ){
+
+        my ($tmpa, $dateaccessioned) = &GetMarcFromKohaField( "items.dateaccessioned" );
+        my ($tmpb, $onloan) = &GetMarcFromKohaField( "items.onloan" );
+        my ($tmpc, $datelastseen) = &GetMarcFromKohaField( "items.datelastseen" );
+        my ($tmpd, $datelastborrowed) = &GetMarcFromKohaField( "items.datelastborrowed" );
+        my ($tmpe, $replacementpricedate) = &GetMarcFromKohaField( "items.replacementpricedate" );
+        if ( $key eq $dateaccessioned || $key eq $onloan || $key eq $datelastseen || $key eq $datelastborrowed || $key eq $replacementpricedate ){
             # date accessioned || on loan || date last seen || date last borrowed || replacement price date
             $item_field->{field} = output_pref({ dt => dt_from_string( $row->{$key} ), dateonly => 1 });
         }
diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl
index ada088fb34..0c4b2c7771 100755
--- a/opac/opac-MARCdetail.pl
+++ b/opac/opac-MARCdetail.pl
@@ -313,8 +313,12 @@ foreach my $field (@fields) {
                 $subf[$i][1], '', $tagslib, '', 'opac' );
         }
 
-        if ( $subf[$i][0] eq 'd' || $subf[$i][0] eq 'q' || $subf[$i][0] eq 'r' || $subf[$i][0] eq 's' || $subf[$i][0] eq 'w' ){
-            # date accessioned || on loan || date last seen || date last borrowed || replacement price date
+        if ( $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.dateaccessioned' ||
+            $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.onloan' ||
+            $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastseen' ||
+            $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.datelastborrowed' ||
+            $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield} eq 'items.replacementpricedate'
+        ){
             $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });;
         }
     }
-- 
2.11.0