Merge remote branch 'kc/new/bug_5327' into kcmaster
authorChris Cormack <chrisc@catalyst.net.nz>
Tue, 18 Jan 2011 03:25:58 +0000 (16:25 +1300)
committerChris Cormack <chrisc@catalyst.net.nz>
Tue, 18 Jan 2011 03:25:58 +0000 (16:25 +1300)
C4/Biblio.pm
C4/Koha.pm
C4/Serials.pm
acqui/addorderiso2709.pl
acqui/basketgroup.pl
docs/history.txt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tmpl
serials/serials-collection.pl
serials/serials-edit.pl

index 232ffb3..0cc63ab 100644 (file)
@@ -83,7 +83,6 @@ BEGIN {
       &GetMarcStructure
       &GetMarcFromKohaField
       &GetFrameworkCode
-      &GetPublisherNameFromIsbn
       &TransformKohaToMarc
 
       &CountItemsIssued
@@ -1633,36 +1632,6 @@ sub GetFrameworkCode {
     return $frameworkcode;
 }
 
-=head2 GetPublisherNameFromIsbn
-
-    $name = GetPublishercodeFromIsbn($isbn);
-    if(defined $name){
-        ...
-    }
-
-=cut
-
-sub GetPublisherNameFromIsbn($) {
-    my $isbn = shift;
-    $isbn =~ s/[- _]//g;
-    $isbn =~ s/^0*//;
-    my @codes = ( split '-', DisplayISBN($isbn) );
-    my $code  = $codes[0] . $codes[1] . $codes[2];
-    my $dbh   = C4::Context->dbh;
-    my $query = qq{
-        SELECT distinct publishercode
-        FROM   biblioitems
-        WHERE  isbn LIKE ?
-        AND    publishercode IS NOT NULL
-        LIMIT 1
-    };
-    my $sth = $dbh->prepare($query);
-    $sth->execute("$code%");
-    my $name = $sth->fetchrow;
-    return $name if length $name;
-    return undef;
-}
-
 =head2 TransformKohaToMarc
 
     $record = TransformKohaToMarc( $hash )
index f2931a3..4f7b50f 100644 (file)
@@ -35,7 +35,6 @@ BEGIN {
        @ISA    = qw(Exporter);
        @EXPORT = qw(
                &slashifyDate
-               &DisplayISBN
                &subfield_is_koha_internal_p
                &GetPrinters &GetPrinter
                &GetItemTypes &getitemtypeinfo
@@ -106,109 +105,6 @@ sub slashifyDate {
     return ("$dateOut[2]/$dateOut[1]/$dateOut[0]");
 }
 
-
-=head2 DisplayISBN
-
-  my $string = DisplayISBN( $isbn );
-
-=cut
-
-sub DisplayISBN {
-    my ($isbn) = @_;
-               if (!length ($isbn)==13 && !length ($isbn)==10) {
-                       $isbn=_isbn_cleanup($isbn);
-               }
-    if (length ($isbn)<13){
-    my $seg1;
-    if ( substr( $isbn, 0, 1 ) <= 7 ) {
-        $seg1 = substr( $isbn, 0, 1 );
-    }
-    elsif ( substr( $isbn, 0, 2 ) <= 94 ) {
-        $seg1 = substr( $isbn, 0, 2 );
-    }
-    elsif ( substr( $isbn, 0, 3 ) <= 995 ) {
-        $seg1 = substr( $isbn, 0, 3 );
-    }
-    elsif ( substr( $isbn, 0, 4 ) <= 9989 ) {
-        $seg1 = substr( $isbn, 0, 4 );
-    }
-    else {
-        $seg1 = substr( $isbn, 0, 5 );
-    }
-    my $x = substr( $isbn, length($seg1) );
-    my $seg2;
-    if ( substr( $x, 0, 2 ) <= 19 ) {
-
-        # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
-        $seg2 = substr( $x, 0, 2 );
-    }
-    elsif ( substr( $x, 0, 3 ) <= 699 ) {
-        $seg2 = substr( $x, 0, 3 );
-    }
-    elsif ( substr( $x, 0, 4 ) <= 8399 ) {
-        $seg2 = substr( $x, 0, 4 );
-    }
-    elsif ( substr( $x, 0, 5 ) <= 89999 ) {
-        $seg2 = substr( $x, 0, 5 );
-    }
-    elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
-        $seg2 = substr( $x, 0, 6 );
-    }
-    else {
-        $seg2 = substr( $x, 0, 7 );
-    }
-    my $seg3 = substr( $x, length($seg2) );
-    $seg3 = substr( $seg3, 0, length($seg3) - 1 );
-    my $seg4 = substr( $x, -1, 1 );
-    return "$seg1-$seg2-$seg3-$seg4";
-    } else {
-      my $seg1;
-      $seg1 = substr( $isbn, 0, 3 );
-      my $seg2;
-      if ( substr( $isbn, 3, 1 ) <= 7 ) {
-          $seg2 = substr( $isbn, 3, 1 );
-      }
-      elsif ( substr( $isbn, 3, 2 ) <= 94 ) {
-          $seg2 = substr( $isbn, 3, 2 );
-      }
-      elsif ( substr( $isbn, 3, 3 ) <= 995 ) {
-          $seg2 = substr( $isbn, 3, 3 );
-      }
-      elsif ( substr( $isbn, 3, 4 ) <= 9989 ) {
-          $seg2 = substr( $isbn, 3, 4 );
-      }
-      else {
-          $seg2 = substr( $isbn, 3, 5 );
-      }
-      my $x = substr( $isbn, length($seg2) +3);
-      my $seg3;
-      if ( substr( $x, 0, 2 ) <= 19 ) {
-  
-          # if(sTmp2 < 10) sTmp2 = "0" sTmp2;
-          $seg3 = substr( $x, 0, 2 );
-      }
-      elsif ( substr( $x, 0, 3 ) <= 699 ) {
-          $seg3 = substr( $x, 0, 3 );
-      }
-      elsif ( substr( $x, 0, 4 ) <= 8399 ) {
-          $seg3 = substr( $x, 0, 4 );
-      }
-      elsif ( substr( $x, 0, 5 ) <= 89999 ) {
-          $seg3 = substr( $x, 0, 5 );
-      }
-      elsif ( substr( $x, 0, 6 ) <= 9499999 ) {
-          $seg3 = substr( $x, 0, 6 );
-      }
-      else {
-          $seg3 = substr( $x, 0, 7 );
-      }
-      my $seg4 = substr( $x, length($seg3) );
-      $seg4 = substr( $seg4, 0, length($seg4) - 1 );
-      my $seg5 = substr( $x, -1, 1 );
-      return "$seg1-$seg2-$seg3-$seg4-$seg5";       
-    }    
-}
-
 # FIXME.. this should be moved to a MARC-specific module
 sub subfield_is_koha_internal_p ($) {
     my ($subfield) = @_;
index 1abebb4..5e2fa22 100644 (file)
@@ -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;
index 781df61..29f8143 100755 (executable)
@@ -37,7 +37,7 @@ use C4::Biblio;
 use C4::Items;
 use C4::Koha qw/GetItemTypes/;
 use C4::Budgets qw/GetBudgets/;
-use C4::Acquisition qw/NewOrderItem/;
+use C4::Acquisition qw/NewOrderItem GetBasket/;
 use C4::Bookseller qw/GetBookSellerFromId/;
 
 my $input = new CGI;
@@ -145,8 +145,6 @@ if ($op eq ""){
               if ($orderinfo{'listprice'} =~ /^([\d\.,]*)/) {
                   $orderinfo{'listprice'} = $1;
                   $orderinfo{'listprice'} =~ s/,/\./;
-                  eval "use C4::Acquisition qw/GetBasket/;";
-                  eval "use C4::Bookseller qw/GetBookSellerFromId/;";
                   my $basket = GetBasket($orderinfo{basketno});
                   my $bookseller = GetBookSellerFromId($basket->{booksellerid});
                   # '//' is like '||' but tests for defined, rather than true
@@ -163,8 +161,6 @@ if ($op eq ""){
               if ($orderinfo{'listprice'} =~ /^([\d\.,]*)/) {
                   $orderinfo{'listprice'} = $1;
                   $orderinfo{'listprice'} =~ s/,/\./;
-                  eval "use C4::Acquisition qw/GetBasket/;";
-                  eval "use C4::Bookseller qw/GetBookSellerFromId/;";
                   my $basket = GetBasket($orderinfo{basketno});
                   my $bookseller = GetBookSellerFromId($basket->{booksellerid});
                   my $gst = $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
index aba32d4..2a35f3a 100755 (executable)
@@ -4,6 +4,7 @@
 #written by john.soros@biblibre.com 01/10/2008
 
 # Copyright 2008 - 2009 BibLibre SARL
+# Parts Copyright Catalyst 2010
 #
 # This file is part of Koha.
 #
@@ -183,8 +184,9 @@ sub printbasketgrouppdf{
     my ($basketgroupid) = @_;
     
     my $pdfformat = C4::Context->preference("OrderPdfFormat");
-    eval "use $pdfformat" ;
-    eval "use C4::Branch";
+    eval "use $pdfformat";
+    # FIXME consider what would happen if $pdfformat does not
+    # contain the name of a valid Perl module.
     
     my $basketgroup = GetBasketgroup($basketgroupid);
     my $bookseller = GetBookSellerFromId($basketgroup->{'booksellerid'});
@@ -244,7 +246,6 @@ sub printbasketgrouppdf{
     );
     my $pdf = printpdf($basketgroup, $bookseller, $baskets, \%orders, $bookseller->{gstrate} // C4::Context->preference("gist")) || die "pdf generation failed";
     print $pdf;
-    exit;
 }
 
 my $op = $input->param('op');
@@ -382,10 +383,12 @@ if ( $op eq "add" ) {
     CloseBasketgroup($basketgroupid);
     
     printbasketgrouppdf($basketgroupid);
+    exit;
 }elsif ($op eq 'print'){
     my $basketgroupid = $input->param('basketgroupid');
     
     printbasketgrouppdf($basketgroupid);
+    exit;
 }elsif( $op eq "delete"){
     my $basketgroupid = $input->param('basketgroupid');
     DelBasketgroup($basketgroupid);
index 155907e..e2a072d 100644 (file)
@@ -518,3 +518,4 @@ December 19 2010    Edward Allen becomes the 123rd developer to have a patch pushed
 December 22 2010       Koha 3.2.2 released
 January 5 2011 General IRC meeting http://wiki.koha-community.org/wiki/General_IRC_Meeting,_5_January_2011
 January 12 2011        Brice Sanchez becomes the 124th developer to have a patch pushed
+January 17 2011        Zach Sim becomes the 125th developer to have a patch pushed
index a76cb5c..45ef2ef 100644 (file)
@@ -68,7 +68,7 @@ ff.submit();
 //]]>
 </script>
 </head>
-<body onload="calcNeworderTotal()">
+<body>
 
 <!-- TMPL_INCLUDE NAME="header.inc" -->
 <!-- TMPL_INCLUDE NAME="acquisitions-search.inc" -->
index 10e18e0..8c7c32b 100755 (executable)
@@ -49,6 +49,7 @@ my $biblionumber = $query->param('biblionumber');
 my @subscriptionid = $query->param('subscriptionid');
 
 @subscriptionid= uniq @subscriptionid;
+@subscriptionid= sort @subscriptionid;
 my $subscriptiondescs;
 my $subscriptions;
 
index 58936be..fbf9ad5 100755 (executable)
@@ -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,