[Koha-patches] [PATCH] bug_5473: add 952 fields MARC21 when receiving an order

Srdjan Jankovic srdjan at catalyst.net.nz
Tue Sep 13 02:27:55 CEST 2011


---
 C4/Biblio.pm           |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 acqui/finishreceive.pl |   11 ++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index 96baaef..b0cb247 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -99,6 +99,7 @@ BEGIN {
       &ModBiblio
       &ModBiblioframework
       &ModZebra
+      &AddMarcFields
     );
 
     # To delete something
@@ -3681,6 +3682,55 @@ sub get_biblio_authorised_values {
     return $authorised_values;
 }
 
+=head2 AddMarcFields
+
+Adds fields/subfields to existing marcxml
+
+parameters:
+    biblionumber
+    fields
+
+returns: nothing
+
+  $fields: { tag1 => val1, tag2 => val2, ... }
+  $valX  : $val for tags < 10,
+           [ subfld1 => subval1, subfld2 => subval2, ... ] for the rest
+
+Notes: no indicator support
+
+=cut
+
+sub AddMarcFields {
+    my ( $biblionumber, $fields ) = @_;
+
+    my $rec = GetMarcBiblio($biblionumber) or die "Invalid biblionumber $biblionumber";
+
+    while ( my ($tag, $val) = each %$fields ) {
+        if ( my ($field) = $rec->field($tag) ) {
+            if (ref $val) {
+                $field->update(@$val);
+            } else {
+                $field->update($val);
+            }
+        }
+        else {
+            my $newfield;
+            if (ref $val) {
+                $newfield = MARC::Field->new( $tag, '', '', @$val );
+            } else {
+                $newfield = MARC::Field->new( $tag, $val );
+            }
+            $rec->insert_fields_ordered($newfield);
+        }
+    }
+
+    my $dbh    = C4::Context->dbh;
+    my $encoding = C4::Context->preference("marcflavour");
+    $dbh->do("UPDATE biblioitems SET marcxml=? WHERE biblionumber=?", undef,
+        $rec->as_xml_record($encoding),
+        $biblionumber );
+}
+
 1;
 
 __END__
diff --git a/acqui/finishreceive.pl b/acqui/finishreceive.pl
index 71b13d6..9391b5c 100755
--- a/acqui/finishreceive.pl
+++ b/acqui/finishreceive.pl
@@ -114,4 +114,15 @@ if ($quantityrec > $origquantityrec ) {
     	$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived);
 	}
 }
+
+if (C4::Context->preference("marcflavour") eq "MARC21") {
+    AddMarcFields( $biblionumber, { 952 => [ e => $supplierid,
+                                             d => $datereceived,
+                                             g => $unitprice,
+                                             v => $replacement,
+                                             w => $datereceived, # XXX
+                                        ],
+                                    } );
+}
+
     print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str");
-- 
1.6.5



More information about the Koha-patches mailing list