Bug 21722: Use Koha::Account->add_debit in chargelostitem
[koha.git] / C4 / Ris.pm
index 4833202..f244bf6 100644 (file)
--- a/C4/Ris.pm
+++ b/C4/Ris.pm
@@ -41,6 +41,7 @@ package C4::Ris;
 # Modified 2008 by BibLibre for Koha
 # Modified 2011 by Catalyst
 # Modified 2011 by Equinox Software, Inc.
+# Modified 2016 by Universidad de El Salvador
 #
 # This file is part of Koha.
 #
@@ -64,7 +65,6 @@ use Modern::Perl;
 use List::MoreUtils qw/uniq/;
 use vars qw(@ISA @EXPORT);
 
-use C4::Biblio qw(GetMarcSubfieldStructureFromKohaField);
 use Koha::SimpleMARC qw(read_field);
 
 
@@ -76,11 +76,7 @@ use Koha::SimpleMARC qw(read_field);
   &marc2ris
 );
 
-our $utf;
-our $intype;
-our $marcprint;
-our $protoyear;
-
+our $marcprint = 0; # Debug flag;
 
 =head1 marc2bibtex - Convert from UNIMARC to RIS
 
@@ -97,8 +93,7 @@ sub marc2ris {
     my $output;
 
     my $marcflavour = C4::Context->preference("marcflavour");
-    $intype = lc($marcflavour);
-    my $marcprint = 0; # Debug flag;
+    my $intype = lc($marcflavour);
 
     # Let's redirect stdout
     open my $oldout, ">&STDOUT";
@@ -113,7 +108,6 @@ sub marc2ris {
     if ( $intype eq "marc21" ) {
         if ( $leader =~ /^.{9}a/ ) {
             print "<marc>---\r\n<marc>UTF-8 data\r\n" if $marcprint;
-            $utf = 1;
         }
         else {
             print "<marc>---\r\n<marc>MARC-8 data\r\n" if $marcprint;
@@ -355,69 +349,75 @@ sub print_typetag {
     ## of the leader of a MARC record, the values are the RIS types
     ## that might appropriately represent these types.
     my %ustypehash = (
-                   "a" => "BOOK",
-                   "c" => "MUSIC",
-                   "d" => "MUSIC",
-                   "e" => "MAP",
-                   "f" => "MAP",
-                   "g" => "ADVS",
-                   "i" => "SOUND",
-                   "j" => "SOUND",
-                   "k" => "ART",
-                   "m" => "DATA",
-                   "o" => "GEN",
-                   "p" => "GEN",
-                   "r" => "ART",
-                   "t" => "GEN",
-               );
-    
+            "a" => "BOOK",
+            "c" => "MUSIC",
+            "d" => "MUSIC",
+            "e" => "MAP",
+            "f" => "MAP",
+            "g" => "ADVS",
+            "i" => "SOUND",
+            "j" => "SOUND",
+            "k" => "ART",
+            "m" => "DATA",
+            "o" => "GEN",
+            "p" => "GEN",
+            "r" => "ART",
+            "t" => "MANSCPT",
+            );
+
     my %unitypehash = (
-                   "a" => "BOOK",
-                   "b" => "BOOK",
-                   "c" => "MUSIC",
-                   "d" => "MUSIC",
-                   "e" => "MAP",
-                   "f" => "MAP",
-                   "g" => "ADVS",
-                   "i" => "SOUND",
-                   "j" => "SOUND",
-                   "k" => "ART",
-                   "l" => "ELEC",
-                   "m" => "ADVS",
-                   "r" => "ART",
-               );
-    
+            "a" => "BOOK",
+            "b" => "MANSCPT",
+            "c" => "MUSIC",
+            "d" => "MUSIC",
+            "e" => "MAP",
+            "f" => "MAP",
+            "g" => "ADVS",
+            "i" => "SOUND",
+            "j" => "SOUND",
+            "k" => "ART",
+            "l" => "ELEC",
+            "m" => "GEN",
+            "r" => "ART",
+            );
+
     ## The type of a MARC record is found at position 06 of the leader
     my $typeofrecord = defined($leader) && length $leader >=6 ?
                        substr($leader, 6, 1): undef;
+    ## Pos 07 == Bibliographic level
+    my $biblevel = defined($leader) && length $leader >=7 ?
+                       substr($leader, 7, 1): '';
 
-    ## ToDo: for books, field 008 positions 24-27 might have a few more
+    ## TODO: for books, field 008 positions 24-27 might have a few more
     ## hints
 
     my %typehash;
-    
-    ## the ukmarc here is just a guess
-    if (! defined $intype) {
-        ## assume MARC21 as default
-        %typehash = %ustypehash;
-    }
-    elsif ($intype eq "marc21" || $intype eq "ukmarc") {
-       %typehash = %ustypehash;
-    }
-    elsif ($intype eq "unimarc") {
-       %typehash = %unitypehash;
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
+    if ($intype eq "unimarc") {
+        %typehash = %unitypehash;
     }
     else {
-       ## assume MARC21 as default
-       %typehash = %ustypehash;
+        %typehash = %ustypehash;
     }
 
     if (!defined $typeofrecord || !exists $typehash{$typeofrecord}) {
-       print "TY  - BOOK\r\n"; ## most reasonable default
-       warn ("no type found - assume BOOK") if $marcprint;
-    }
-    else {
-       print "TY  - $typehash{$typeofrecord}\r\n";
+        print "TY  - GEN\r\n"; ## most reasonable default
+        warn ("no type found - assume GEN") if $marcprint;
+    } elsif ( $typeofrecord =~ "a" ) {
+        if ( $biblevel eq 'a' ) {
+            print "TY  - GEN\r\n"; ## monographic component part
+        } elsif ( $biblevel eq 'b' || $biblevel eq 's' ) {
+            print "TY  - SER\r\n"; ## serial or serial component part
+        } elsif ( $biblevel eq 'm' ) {
+            print "TY  - $typehash{$typeofrecord}\r\n"; ## book
+        } elsif ( $biblevel eq 'c' || $biblevel eq 'd' ) {
+            print "TY  - GEN\r\n"; ## collections, part of collections or made-up collections
+        } elsif ( $biblevel eq 'i' ) {
+            print "TY  - DATA\r\n"; ## updating loose-leafe as Dataset
+        }
+    } else {
+        print "TY  - $typehash{$typeofrecord}\r\n";
     }
 
     ## use $typeofrecord as the return value, just in case
@@ -482,6 +482,8 @@ sub get_author {
 
     ## the sequence of the name parts is encoded either in indicator
     ## 1 (marc21) or 2 (unimarc)
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
     if ($intype eq "unimarc") {
        $indicator = 2;
     }
@@ -552,6 +554,8 @@ $clean_subtitle ||= q{};
        $clean_title =~ s% *[/:;.]$%%;
        $clean_subtitle =~ s%^ *(.*) *[/:;.]$%$1%;
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if (length($clean_title) > 0
            || (length($clean_subtitle) > 0 && $intype ne "unimarc")) {
            print "TI  - ", $clean_title;
@@ -568,6 +572,7 @@ $clean_subtitle ||= q{};
        ## be written and designated. The field is free-form and resistant
        ## to all parsing efforts, so this information is lost on me
     }
+    return;
 }
 
 ##********************************************************************
@@ -591,6 +596,8 @@ sub print_stitle {
            print "T2  - ", $clean_title,"\r\n";
        }
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if ($intype eq "unimarc") {
            print "<marc>Series vol(\$v): ",$titlefield->subfield('v'),"\r\n" if $marcprint;
            if (length($titlefield->subfield('v')) > 0) {
@@ -598,6 +605,7 @@ sub print_stitle {
            }
        }
     }
+    return;
 }
 
 ##********************************************************************
@@ -726,6 +734,8 @@ sub print_pubinfo {
        my $pubsub_publisher;
        my $pubsub_date;
 
+    my $marcflavour = C4::Context->preference("marcflavour");
+    my $intype = lc($marcflavour);
        if ($intype eq "unimarc") {
            $pubsub_place = "a";
            $pubsub_publisher = "c";
@@ -758,7 +768,7 @@ sub print_pubinfo {
                ## the dates are free-form, so we want to extract
                ## a four-digit year and leave the rest as
                ## "other info"
-               $protoyear = @$tuple[1];
+        my $protoyear = @$tuple[1];
                print "<marc>Year (260\$c): $protoyear\r\n" if $marcprint;
 
                ## strip any separator chars at the end