From d22a4d20384277fca4270b52f51a179c36f3c427 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 17 Jan 2011 08:17:40 +0000 Subject: [PATCH] Bug 5026 Undefined dates formatted poorly in serials-edit Don't display junk in empty fields Don't generate errors Merged some changes to make variable names moremeaningful in loops ( within loops) Thanks to M De Rooy for spotting a couple of issues in the original patch Signed-off-by: Marcel de Rooy Signed-off-by: Chris Cormack --- C4/Serials.pm | 13 +++-- serials/serials-collection.pl | 1 + serials/serials-edit.pl | 97 +++++++++++++++++++---------------- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 1abebb44c1..5e2fa2235f 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -724,9 +724,16 @@ sub GetSerials2 { my @serials; while ( my $line = $sth->fetchrow_hashref ) { - $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list - $line->{"planneddate"} = format_date( $line->{"planneddate"} ); - $line->{"publisheddate"} = format_date( $line->{"publisheddate"} ); + $line->{ "status" . $line->{status} } = 1; # fills a "statusX" value, used for template status select list + # Format dates for display + for my $datefield ( qw( planneddate publisheddate ) ) { + if ($line->{$datefield} =~m/^00/) { + $line->{$datefield} = q{}; + } + else { + $line->{$datefield} = format_date( $line->{$datefield} ); + } + } push @serials, $line; } return @serials; diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index 10e18e0566..8c7c32bfa2 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -49,6 +49,7 @@ my $biblionumber = $query->param('biblionumber'); my @subscriptionid = $query->param('subscriptionid'); @subscriptionid= uniq @subscriptionid; +@subscriptionid= sort @subscriptionid; my $subscriptiondescs; my $subscriptions; diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index 58936be563..fbf9ad598b 100755 --- a/serials/serials-edit.pl +++ b/serials/serials-edit.pl @@ -92,19 +92,18 @@ my @errseq; # If user comes from subscription details unless (@serialids) { - foreach my $subscriptionid (@subscriptionids) { - my $serstatus = $query->param('serstatus'); - if ($serstatus) { + my $serstatus = $query->param('serstatus'); + if ($serstatus) { + foreach my $subscriptionid (@subscriptionids) { my @tmpser = GetSerials2( $subscriptionid, $serstatus ); - foreach (@tmpser) { - push @serialids, $_->{'serialid'}; - } + push @serialids, map { $_->{serialid} } @tmpser; } } } -unless ( scalar(@serialids) ) { - my $string = "serials-collection.pl?subscriptionid=" . join( ",", uniq @subscriptionids ); +unless ( @serialids ) { + my $string = + 'serials-collection.pl?subscriptionid=' . join ',', uniq @subscriptionids; $string =~ s/,$//; print $query->redirect($string); @@ -112,12 +111,12 @@ unless ( scalar(@serialids) ) { my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "serials/serials-edit.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => {serials => 'receive_serials'}, - debug => 1, + template_name => 'serials/serials-edit.tmpl', + query => $query, + type => 'intranet', + authnotrequired => 0, + flagsrequired => { serials => 1 }, + debug => 1, } ); @@ -125,36 +124,37 @@ my @serialdatalist; my %processedserialid; my $today = C4::Dates->new(); -foreach my $tmpserialid (@serialids) { +foreach my $serialid (@serialids) { #filtering serialid for duplication #NEW serial should appear only once and are created afterwards - if ( defined($tmpserialid) - && $tmpserialid =~ /^[0-9]+$/ - && !$processedserialid{$tmpserialid} ) + if ( $serialid + && $serialid =~ /^[0-9]+$/ + && !$processedserialid{$serialid} ) { - my $data = GetSerialInformation($tmpserialid); - for my $datefield ( qw( publisheddate planneddate) ) { - if ($data->{$datefield} && $data->{$datefield}!~m/^00/) { - $data->{$datefield} = format_date( $data->{$datefield} ); + my $serinfo = GetSerialInformation($serialid); #TODO duplicates work done by GetSerials2 above + for my $d ( qw( publisheddate planneddate )){ + if ( $serinfo->{$d} =~m/^00/ ) { + $serinfo->{$d} = q{}; } else { - $data->{$datefield} = q{}; + $serinfo->{$d} = format_date( $serinfo->{$d} ); } } - $data->{arriveddate}=$today->output('syspref'); - $data->{'editdisable'} = ( + $serinfo->{arriveddate}=$today->output('syspref'); + + $serinfo->{'editdisable'} = ( ( - HasSubscriptionExpired( $data->{subscriptionid} ) == 1 - && $data->{'status1'} + HasSubscriptionExpired( $serinfo->{subscriptionid} ) + && $serinfo->{'status1'} ) - || $data->{'cannotedit'} + || $serinfo->{'cannotedit'} ); - push @serialdatalist, $data; - $processedserialid{$tmpserialid} = 1; + push @serialdatalist, $serinfo; + $processedserialid{$serialid} = 1; } } -my $bibdata = GetBiblioData( $serialdatalist[0]->{'biblionumber'} ); +my $biblio = GetBiblioData( $serialdatalist[0]->{'biblionumber'} ); my @newserialloop; my @subscriptionloop; @@ -164,8 +164,7 @@ my %processedsubscriptionid; foreach my $subscriptionid (@subscriptionids) { #Do not process subscriptionid twice if it was already processed. - if ( defined($subscriptionid) - && !$processedsubscriptionid{$subscriptionid} ) + if ( $subscriptionid && !$processedsubscriptionid{$subscriptionid} ) { my $cell; if ( $serialdatalist[0]->{'serialsadditems'} ) { @@ -177,8 +176,8 @@ foreach my $subscriptionid (@subscriptionids) { $cell->{serialsadditems} = 1; } $cell->{'subscriptionid'} = $subscriptionid; - $cell->{'itemid'} = "NNEW"; - $cell->{'serialid'} = "NEW"; + $cell->{'itemid'} = 'NNEW'; + $cell->{'serialid'} = 'NEW'; $cell->{'issuesatonce'} = 1; $cell->{arriveddate}=$today->output('syspref'); @@ -199,8 +198,16 @@ if ( $op and $op eq 'serialchangestatus' ) { my $newserial; for ( my $i = 0 ; $i <= $#serialids ; $i++ ) { + my ($plan_date, $pub_date); + + if (defined $planneddates[$i] && $planneddates[$i] ne 'XXX') { + $plan_date = format_date_in_iso( $planneddates[$i] ); + } + if (defined $publisheddates[$i] && $publisheddates[$i] ne 'XXX') { + $pub_date = format_date_in_iso( $publisheddates[$i] ); + } - if ( $serialids[$i] && $serialids[$i] eq "NEW" ) { + if ( $serialids[$i] && $serialids[$i] eq 'NEW' ) { if ( $serialseqs[$i] ) { #IF newserial was provided a name Then we have to create a newSerial @@ -210,8 +217,8 @@ if ( $op and $op eq 'serialchangestatus' ) { $subscriptionids[0], $serialdatalist[0]->{'biblionumber'}, $status[$i], - format_date_in_iso( $planneddates[$i] ), - format_date_in_iso( $publisheddates[$i] ), + $plan_date, + $pub_date, $notes[$i] ); } @@ -220,8 +227,8 @@ if ( $op and $op eq 'serialchangestatus' ) { ModSerialStatus( $serialids[$i], $serialseqs[$i], - format_date_in_iso( $planneddates[$i] ), - format_date_in_iso( $publisheddates[$i] ), + $plan_date, + $pub_date, $status[$i], $notes[$i] ); @@ -300,14 +307,14 @@ if ( $op and $op eq 'serialchangestatus' ) { $serialdatalist[0]->{'biblionumber'} ) ); - if ( C4::Context->preference("autoBarcode") eq + if ( C4::Context->preference('autoBarcode') eq 'incremental' ) { if ( !$bib_record->field($barcodetagfield) ->subfield($barcodetagsubfield) ) { my $sth_barcode = $dbh->prepare( - "select max(abs(barcode)) from items"); + 'select max(abs(barcode)) from items'); $sth_barcode->execute; my ($newbarcode) = $sth_barcode->fetchrow; @@ -365,8 +372,8 @@ if ( $op and $op eq 'serialchangestatus' ) { } } else { - my $redirect = "serials-collection.pl?"; - $redirect .= join( '&', map { "subscriptionid=" . $_ } sort @subscriptionids );# ID The sort necessary + my $redirect = 'serials-collection.pl?'; + $redirect .= join( '&', map { 'subscriptionid=' . $_ } @subscriptionids ); print $query->redirect($redirect); } } @@ -380,7 +387,7 @@ my $default_bib_view = get_default_view(); $template->param( serialsadditems => $serialdatalist[0]->{'serialsadditems'}, callnumber => $serialdatalist[0]->{'callnumber'}, - bibliotitle => $bibdata->{'title'}, + bibliotitle => $biblio->{'title'}, biblionumber => $serialdatalist[0]->{'biblionumber'}, serialslist => \@serialdatalist, default_bib_view => $default_bib_view, -- 2.39.5