Bug 5103: Format dates in MARC detail using dateformat syspref
authorAleisha Amohia <aleishaamohia@hotmail.com>
Wed, 26 Feb 2020 02:52:24 +0000 (02:52 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 16 Mar 2020 10:56:25 +0000 (10:56 +0000)
This patch fixes the formatting of dates on the following pages:
- catalogue/MARCdetail.pl (staff)
- cataloguing/additem.pl (staff)
- opac-MARCdetail.pl (opac)

To test:
1) Ensure that the following fields are visible in the opac, intranet
and editor. You may need to edit the subfields in your default
bibliographic framework
952$d date accessioned
952$q date due/on loan
952$r date last seen
952$s date last borrowed
952$w replacement price date

Also ensure you have dateformat system preference set

2) Go to cataloguing/additem.pl for a biblio. Fill in the fields above
if required. Save
3) Remain on cataloguing/additem.pl. Notice the items table at the top
of the page, the dates are in the generic yyyy-mm-dd format
4) Go to catalogue/MARCdetail.pl for that biblio. Notice dates in wrong
format
5) View this biblio in the opac opac-MARCdetail.pl. Scroll to bottom to
items table. Notice dates in wrong format.
6) Apply patch, restart memcached and plack and refresh pages
7) Dates should now be formatted according to dateformat preference
8) Confirm that changing the preference changes the format of the dates

Sponsored-by: Catalyst IT
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

catalogue/MARCdetail.pl
cataloguing/additem.pl
opac/opac-MARCdetail.pl

index 7c67ffb..36b56a3 100755 (executable)
@@ -61,6 +61,7 @@ use C4::Search;               # enabled_staff_search_views
 use Koha::Biblios;
 use Koha::BiblioFrameworks;
 use Koha::Patrons;
+use Koha::DateUtils;
 
 use List::MoreUtils qw( uniq );
 
@@ -267,6 +268,7 @@ my %witness
 my @item_subfield_codes;
 my @item_loop;
 my $norequests = 1;
+
 foreach my $field (@fields) {
     next if ( $field->tag() < 10 );
     my @subf = $field->subfields;
@@ -294,6 +296,11 @@ 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
+            $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });
+        }
     }
     push @item_loop, $item if $item;
 }
index 1f51db0..109c76c 100755 (executable)
@@ -800,7 +800,6 @@ if ( C4::Context->preference('EasyAnalyticalRecords') ) {
     }
 }
 
-
 foreach my $field (@fields) {
     next if ( $field->tag() < 10 );
 
@@ -857,7 +856,21 @@ my @item_value_loop;
 my @header_value_loop;
 for my $row ( @big_array ) {
     my %row_data;
-    my @item_fields = map +{ field => $_ || '' }, @$row{ sort keys(%witness) };
+    my @item_fields;
+    foreach my $key (sort keys %witness){
+        my $item_field;
+        if ( $row->{$key} ){
+            $item_field->{field} = $row->{$key};
+        } else {
+            $item_field->{field} = '';
+        }
+        if ( $key eq 'd' || $key eq 'q' || $key eq 'r' || $key eq 's' || $key eq 'w' ){
+            # 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 });
+        }
+
+        push @item_fields, $item_field;
+    }
     $row_data{item_value} = [ @item_fields ];
     $row_data{itemnumber} = $row->{itemnumber};
     #reporting this_row values
index 545af32..ada088f 100755 (executable)
@@ -63,6 +63,7 @@ use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
 use Koha::RecordProcessor;
+use Koha::DateUtils;
 
 my $query = CGI->new();
 
@@ -290,6 +291,7 @@ foreach my $field (@fields) {
         my $sf_def = $tagslib->{ $field->tag() }->{ $subf[$i][0] };
         next if ( ($sf_def->{tab}||0) != 10 );
         next if ( ($sf_def->{hidden}||0) > 0 );
+
         push @item_subfield_codes, $subf[$i][0];
         $witness{ $subf[$i][0] } = $sf_def->{lib};
 
@@ -310,6 +312,11 @@ foreach my $field (@fields) {
             $item->{ $subf[$i][0] } .= GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
                 $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
+            $item->{$subf[$i][0]} = output_pref({ dt => dt_from_string( $item->{$subf[$i][0]} ), dateonly => 1 });;
+        }
     }
     push @item_loop, $item if $item;
 }