kohabug 2955 GetMarcFromKohaField now requires $framework
[koha.git] / C4 / XSLT.pm
index 4a383fb..eeb2ec7 100644 (file)
@@ -22,6 +22,7 @@ use C4::Branch;
 use C4::Items;
 use C4::Koha;
 use C4::Biblio;
+use C4::Circulation;
 use XML::LibXML;
 use XML::LibXSLT;
 
@@ -56,7 +57,12 @@ sub transformMARCXML4XSLT {
     my $biblio = GetBiblioData($biblionumber);
     my $frameworkcode = GetFrameworkCode($biblionumber);
     my $tagslib = &GetMarcStructure(1,$frameworkcode);
-    my @fields = $record->fields();
+    my @fields;
+    # FIXME: wish there was a better way to handle exceptions
+    eval {
+        @fields = $record->fields();
+    };
+    if ($@) { warn "PROBLEM WITH RECORD"; next; }
     my $list_of_authvalues = getAuthorisedValues4MARCSubfields($frameworkcode);
     for my $authvalue (@$list_of_authvalues) {
         for my $field ( $record->field($authvalue->{tagfield}) ) {
@@ -127,12 +133,17 @@ sub buildKohaItemsNamespace {
     my $xml;
     for my $item (@items) {
         my $status;
-        if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged}) {
+        my ( $transfertwhen, $transfertfrom, $transfertto ) = C4::Circulation::GetTransfers($item->{itemnumber});
+        if ( $item->{notforloan} == -1 || $item->{onloan} || $item->{wthdrawn} || $item->{itemlost} || $item->{damaged} ||
+             ($transfertwhen ne '') || $item->{itemnotforloan} ) {
             if ( $item->{notforloan} == -1) {
                 $status = "On order";
+            } 
+            if ( $item->{itemnotforloan} ) {
+                $status = "Not for loan";
             }
             if ($item->{onloan}) {
-                $status = "On loan";
+                $status = "Checked out";
             }
             if ( $item->{wthdrawn}) {
                 $status = "Withdrawn";
@@ -143,10 +154,16 @@ sub buildKohaItemsNamespace {
             if ($item->{damaged}) {
                 $status = "Damaged"; 
             }
+            if ($transfertwhen ne '') {
+                $status = 'In transit';
+            }
         } else {
             $status = "available";
         }
-        $xml.="<item><homebranch>".$branches->{$item->{homebranch}}->{'branchname'}."</homebranch>"."<status>$status</status></item>";
+        $xml.="<item><homebranch>".$branches->{$item->{homebranch}}->{'branchname'}."</homebranch>".
+               "<status>$status</status>".
+               "<itemcallnumber>".$item->{'itemcallnumber'}."</itemcallnumber></item>";
+
     }
     return "<items xmlns='http://www.koha.org/items'>".$xml."</items>";
 }