BUGfixes in availability management
authorPaul POULAIN <paul@koha-fr.org>
Sun, 14 Oct 2007 21:20:51 +0000 (16:20 -0500)
committerJoshua Ferraro <jmf@liblime.com>
Mon, 15 Oct 2007 00:10:53 +0000 (19:10 -0500)
- the availability status was not available on result list. This patch reintroduces that
- notforloan as itemtype was not properly managed : an itemtype that was notforloan resulted in nothing in detail. Not, the user can't place a reserve anymore, and the status is correctly displayed

the fix is for OPAC as well as staff

(owen, pls, validate cat-toolbar.inc & catalogue/detail.tmpl)

Signed-off-by: Chris Cormack <crc@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Biblio.pm
C4/Search.pm
koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tmpl
koha-tmpl/opac-tmpl/prog/en/opac-detail.tmpl
koha-tmpl/opac-tmpl/prog/en/opac-results.tmpl

index f99ca5d..11df070 100644 (file)
@@ -697,7 +697,7 @@ sub GetBiblioData {
     my $dbh = C4::Context->dbh;
 
     my $query = "
-        SELECT * , biblioitems.notes AS bnotes, biblio.notes
+        SELECT * , biblioitems.notes AS bnotes, itemtypes.notforloan as bi_notforloan, biblio.notes
         FROM biblio
             LEFT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber
             LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype
index 391f6f3..3f07e20 100644 (file)
@@ -21,6 +21,7 @@ use C4::Context;
 use C4::Biblio;    # GetMarcFromKohaField
 use C4::Koha;      # getFacets
 use Lingua::Stem;
+use C4::Date;
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
 
@@ -832,13 +833,14 @@ sub searchResults {
     #find itemtype & itemtype image
     my %itemtypes;
     $bsth =
-      $dbh->prepare("SELECT itemtype,description,imageurl,summary FROM itemtypes");
+      $dbh->prepare("SELECT itemtype,description,imageurl,summary,notforloan FROM itemtypes");
     $bsth->execute();
     while ( my $bdata = $bsth->fetchrow_hashref ) {
         $itemtypes{ $bdata->{'itemtype'} }->{description} =
           $bdata->{'description'};
         $itemtypes{ $bdata->{'itemtype'} }->{imageurl} = $bdata->{'imageurl'};
         $itemtypes{ $bdata->{'itemtype'} }->{summary} = $bdata->{'summary'};
+        $itemtypes{ $bdata->{'itemtype'} }->{notforloan} = $bdata->{'notforloan'};
     }
 
     #search item field code
@@ -948,41 +950,58 @@ sub searchResults {
         my $itemlost_count    = 0;
         my $norequests        = 1;
 
+        #
+        # check the loan status of the item : 
+        # it is not stored in the MARC record, for pref (zebra reindexing)
+        # reason. Thus, we have to get the status from a specific SQL query
+        #
+        my $sth_issue = $dbh->prepare("
+            SELECT date_due,returndate 
+            FROM issues 
+            WHERE itemnumber=? AND returndate IS NULL");
+
         foreach my $field (@fields) {
             my $item;
             foreach my $code ( keys %subfieldstosearch ) {
                 $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
             }
+            $sth_issue->execute($item->{itemnumber});
+            $item->{due_date} = format_date($sth_issue->fetchrow);
+            $item->{onloan} = 1 if $item->{due_date};
+            # at least one item can be reserved : suppose no
+            $norequests = 1;
             if ( $item->{wthdrawn} ) {
                 $wthdrawn_count++;
             }
-            elsif ( $item->{notforloan} == -1 ) {
-                $ordered_count++;
-                $norequests = 0;
-            }
             elsif ( $item->{itemlost} ) {
                 $itemlost_count++;
             }
-            elsif ( ( $item->{onloan} ) && ( $item->{onloan} != '0000-00-00' ) )
+            unless ( $item->{notforloan}) {
+                # OK, this one can be issued, so at least one can be reserved
+                $norequests = 0;
+            }
+            if ( ( $item->{onloan} ) && ( $item->{onloan} != '0000-00-00' ) )
             {
+                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{onloancount} = 1;
+                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{due_date} = $item->{due_date};
                 $onloan_count++;
-                $norequests = 0;
             }
-            else {
-                $norequests = 0;
-                if ( $item->{'homebranch'} ) {
-                    $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{count}++;
-                }
+            if ( $item->{'homebranch'} ) {
+                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{count}++;
+            }
 
-                # Last resort
-                elsif ( $item->{'holdingbranch'} ) {
-                    $items->{ $item->{'holdingbranch'} }->{count}++;
-                }
-                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{itemcallnumber} =                $item->{itemcallnumber};
-                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{location} =                $item->{location};
-                $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{branchcode} =               $item->{homebranch};
+            # Last resort
+            elsif ( $item->{'holdingbranch'} ) {
+                $items->{ $item->{'holdingbranch'} }->{count}++;
             }
+            $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{itemcallnumber} =                $item->{itemcallnumber};
+            $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{location} =                $item->{location};
+            $items->{ $item->{'homebranch'}.'--'.$item->{'itemcallnumber'} }->{branchcode} =               $item->{homebranch};
         }    # notforloan, item level and biblioitem level
+
+        # last check for norequest : if itemtype is notforloan, it can't be reserved either, whatever the items
+        $norequests = 1 if $itemtypes{$oldbiblio->{itemtype}}->{notforloan};
+
         for my $key ( sort keys %$items ) {
             my $this_item = {
                 branchname     => $branches{$items->{$key}->{branchcode}},
@@ -990,6 +1009,8 @@ sub searchResults {
                 count          => $items->{$key}->{count}==1 ?"":$items->{$key}->{count},
                 itemcallnumber => $items->{$key}->{itemcallnumber},
                 location => $items->{$key}->{location},
+                onloancount         => $items->{$key}->{onloancount},
+                due_date         => $items->{$key}->{due_date},
             };
             push @items_loop, $this_item;
         }
@@ -1000,61 +1021,6 @@ sub searchResults {
         $oldbiblio->{itemlostcount} = $itemlost_count;
         $oldbiblio->{orderedcount}  = $ordered_count;
         $oldbiblio->{isbn}          =~ s/-//g; # deleting - in isbn to enable amazon content 
-        
-# FIXME
-#  Ugh ... this is ugly, I'll re-write it better above then delete it
-#     my $norequests = 1;
-#     my $noitems    = 1;
-#     if (@items) {
-#         $noitems = 0;
-#         foreach my $itm (@items) {
-#             $norequests = 0 unless $itm->{'itemnotforloan'};
-#         }
-#     }
-#     $oldbiblio->{'noitems'} = $noitems;
-#     $oldbiblio->{'norequests'} = $norequests;
-#     $oldbiblio->{'even'} = $even = not $even;
-#     $oldbiblio->{'itemcount'} = $counts{'total'};
-#     my $totalitemcounts = 0;
-#     foreach my $key (keys %counts){
-#         if ($key ne 'total'){
-#             $totalitemcounts+= $counts{$key};
-#             $oldbiblio->{'locationhash'}->{$key}=$counts{$key};
-#         }
-#     }
-#     my ($locationtext, $locationtextonly, $notavailabletext) = ('','','');
-#     foreach (sort keys %{$oldbiblio->{'locationhash'}}) {
-#         if ($_ eq 'notavailable') {
-#             $notavailabletext="Not available";
-#             my $c=$oldbiblio->{'locationhash'}->{$_};
-#             $oldbiblio->{'not-available-p'}=$c;
-#         } else {
-#             $locationtext.="$_";
-#             my $c=$oldbiblio->{'locationhash'}->{$_};
-#             if ($_ eq 'Item Lost') {
-#                 $oldbiblio->{'lost-p'} = $c;
-#             } elsif ($_ eq 'Withdrawn') {
-#                 $oldbiblio->{'withdrawn-p'} = $c;
-#             } elsif ($_ eq 'On Loan') {
-#                 $oldbiblio->{'on-loan-p'} = $c;
-#             } else {
-#                 $locationtextonly.= $_;
-#                 $locationtextonly.= " ($c)<br/> " if $totalitemcounts > 1;
-#             }
-#             if ($totalitemcounts>1) {
-#                 $locationtext.=" ($c)<br/> ";
-#             }
-#         }
-#     }
-#     if ($notavailabletext) {
-#         $locationtext.= $notavailabletext;
-#     } else {
-#         $locationtext=~s/, $//;
-#     }
-#     $oldbiblio->{'location'} = $locationtext;
-#     $oldbiblio->{'location-only'} = $locationtextonly;
-#     $oldbiblio->{'use-location-flags-p'} = 1;
-
         push( @newresults, $oldbiblio );
     }
     return @newresults;
index d03a5b2..0e785f4 100644 (file)
@@ -8,5 +8,6 @@
        <li><a id="deletebiblio" href="javascript:confirm_deletion(<!-- TMPL_VAR NAME="count" -->)">Delete</a></li>
        <li><a id="addtoshelf" href="#" onclick="window.open('/cgi-bin/koha/virtualshelves/addbybiblionumber.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->','Add_to_virtualshelf','width=500,height=400,toolbar=false,scrollbars=yes'); return false;">Add to shelf</a></li>
        <li><a id="printbiblio" href="/cgi-bin/koha/catalogue/detailprint.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Print</a></li>
-       <!-- TMPL_IF NAME="norequests" --><!-- TMPL_ELSE --><li><a id="placehold" href="/cgi-bin/koha/reserve/request.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Place Hold</a></li><!-- /TMPL_IF -->
+        <!-- TMPL_UNLESS name="bi_notforloan" -->
+       <!-- TMPL_UNLESS NAME="norequests" --><li><a id="placehold" href="/cgi-bin/koha/reserve/request.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">Place Hold</a></li><!-- /TMPL_UNLESS --><!-- TMPL_UNLESS -->
 </ul></div>
index c568a75..9324069 100644 (file)
@@ -69,14 +69,16 @@ function confirm_deletion(count) {
 
 function yuiToolbar(){
         YAHOO.toolbar.init = function () {
-                       var oAddbiblio = new YAHOO.widget.Button("addbiblio");
-                       var oEditbiblio = new YAHOO.widget.Button("editbiblio");
-                       var oEdititems = new YAHOO.widget.Button("edititems");
-                       var oDuplicatebiblio = new YAHOO.widget.Button("duplicatebiblio");
-            var oDeletebiblio = new YAHOO.widget.Button("deletebiblio");
-                       var oAddtoshelf = new YAHOO.widget.Button("addtoshelf");
-                       var oPrintbiblio = new YAHOO.widget.Button("printbiblio");
-                       var oPlacehold = new YAHOO.widget.Button("placehold");           
+                    var oAddbiblio = new YAHOO.widget.Button("addbiblio");
+                    var oEditbiblio = new YAHOO.widget.Button("editbiblio");
+                    var oEdititems = new YAHOO.widget.Button("edititems");
+                    var oDuplicatebiblio = new YAHOO.widget.Button("duplicatebiblio");
+                    var oDeletebiblio = new YAHOO.widget.Button("deletebiblio");
+                    var oAddtoshelf = new YAHOO.widget.Button("addtoshelf");
+                    var oPrintbiblio = new YAHOO.widget.Button("printbiblio");
+                    <!-- TMPL_UNLESS name="bi_notforloan" -->
+                        var oPlacehold = new YAHOO.widget.Button("placehold");          
+                    <!-- /TMPL_UNLESS -->
     } ();
 }
        
@@ -236,16 +238,21 @@ function yuiToolbar(){
                     <td><!-- TMPL_IF name="datedue" -->
                             On issue to <a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"><!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></a>
                         <!-- TMPL_ELSE -->
-                            <!-- TMPL_IF name="notforloan" -->
-                                <!-- TMPL_VAR name="notforloan" -->
+                            <!-- TMPL_IF name="bi_notforloan" -->
+                                Not For loan (itemtype)
                             <!-- TMPL_ELSE -->
-                                <!-- TMPL_IF name="itemlost"-->
-                                    Item lost
+                                <!-- TMPL_IF name="notforloan" -->
+                                    <!-- TMPL_VAR name="notforloan" -->
                                 <!-- TMPL_ELSE -->
-                                <!-- TMPL_IF NAME="wthdrawn" -->Item Cancelled<!-- TMPL_ELSE -->Available<!-- /TMPL_IF -->
+                                    <!-- TMPL_IF name="itemlost"-->
+                                        Item lost
+                                    <!-- TMPL_ELSE -->
+                                    <!-- TMPL_IF NAME="wthdrawn" -->Item Cancelled<!-- TMPL_ELSE -->Available<!-- /TMPL_IF -->
+                                    <!-- /TMPL_IF -->
                                 <!-- /TMPL_IF -->
                             <!-- /TMPL_IF -->
-                        <!-- /TMPL_IF --></td>
+                        <!-- /TMPL_IF -->
+                        </td>
                     <td><!-- TMPL_VAR NAME="datedue" --></td>
                     <td><!-- TMPL_VAR NAME="datelastseen" --></td>
                     <td><a href="/cgi-bin/koha/catalogue/moredetail.pl?type=<!-- TMPL_VAR NAME="type" -->&amp;item=<!-- TMPL_VAR NAME="itemnumber" -->&amp;biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;bi=<!-- TMPL_VAR NAME="biblioitemnumber" -->"><!-- TMPL_VAR NAME="barcode" --></a></td>
index e31277d..8497f72 100644 (file)
@@ -7,11 +7,13 @@
 <div id="action">
 
 <!-- TMPL_UNLESS NAME="norequests" -->
-       <!-- TMPL_IF NAME="RequestOnOpac" -->
-               <a href="/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
-               Place Reserve
-               </a>
-       <!-- /TMPL_IF -->
+    <!-- TMPL_UNLESS name="bi_notforloan" -->
+        <!-- TMPL_IF NAME="RequestOnOpac" -->
+            <a href="/cgi-bin/koha/opac-reserve.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
+            Place Reserve
+            </a>
+        <!-- /TMPL_IF -->
+    <!-- /TMPL_UNLESS -->
 <!-- /TMPL_UNLESS -->
         <a href="/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->">
             MARC View
             <td><!-- TMPL_VAR NAME="description" --></td>
             <td><!-- TMPL_VAR NAME="branchname" --> <!-- TMPL_VAR name="location" --> <!-- TMPL_IF NAME="itemcallnumber" --> <!-- TMPL_VAR NAME="itemcallnumber" --><!-- /TMPL_IF --></td>
             <td>
-                <!-- TMPL_IF name="datedue" -->
-                On issue
-                <!-- TMPL_ELSE -->
-                <!-- TMPL_IF name="notforloan" -->
-                <!-- TMPL_VAR name="notforloan" -->
-                <!-- TMPL_ELSE -->
-                <!-- TMPL_IF name="itemlost"-->
-                Item lost
+                <!-- TMPL_IF name="bi_notforloan" -->
+                    Not for loan
                 <!-- TMPL_ELSE -->
-                <!-- TMPL_IF NAME="wthdrawn" -->Item Cancelled<!-- TMPL_ELSE -->Available<!-- /TMPL_IF -->
-                <!-- /TMPL_IF -->
-                <!-- /TMPL_IF -->
+                    <!-- TMPL_IF name="datedue" -->
+                    On issue
+                    <!-- TMPL_ELSE -->
+                        <!-- TMPL_IF name="notforloan" -->
+                            <!-- TMPL_VAR name="notforloan" -->
+                        <!-- TMPL_ELSE -->
+                            <!-- TMPL_IF name="itemlost"-->
+                                Item lost
+                            <!-- TMPL_ELSE -->
+                                <!-- TMPL_IF NAME="wthdrawn" -->
+                                    Item Cancelled
+                                <!-- TMPL_ELSE -->
+                                    Available
+                                <!-- /TMPL_IF -->
+                            <!-- /TMPL_IF -->
+                        <!-- /TMPL_IF -->
+                    <!-- /TMPL_IF -->
                 <!-- /TMPL_IF -->
             </td>
             <td><!-- TMPL_VAR NAME="datedue" --></td>
index 1e9f93e..9748ced 100644 (file)
@@ -315,15 +315,15 @@ Error :
                                 <!-- /TMPL_IF -->
                                 </i>
                                 <br />
+                                <span class="unavailable">
+                                    <!-- TMPL_IF NAME="onloancount" --> On loan (due date <!-- TMPL_VAR name="due_date" -->)<br /> <!-- /TMPL_IF -->
+                                    <!-- TMPL_IF NAME="wthdrawncount" --> Withdrawn (<!-- TMPL_VAR NAME="wthdrawncount" -->),<br /> <!-- /TMPL_IF -->
+                                    <!-- TMPL_IF NAME="itemlostcount" --> Lost (<!-- TMPL_VAR NAME="itemlostcount" -->)<br /><!-- /TMPL_IF -->
+                                    <!-- TMPL_IF NAME="orderedcount" --> On order (<!-- TMPL_VAR NAME="orderedcount" -->)<!-- /TMPL_IF -->
+                                </span>
                             <!-- /TMPL_LOOP -->
                         </span>
                         <!-- /TMPL_IF -->
-                        <span class="unavailable">
-                            <!-- TMPL_IF NAME="onloancount" --> On loan (<!-- TMPL_VAR NAME="onloancount" -->),<br /> <!-- /TMPL_IF -->
-                            <!-- TMPL_IF NAME="wthdrawncount" --> Withdrawn (<!-- TMPL_VAR NAME="wthdrawncount" -->),<br /> <!-- /TMPL_IF -->
-                            <!-- TMPL_IF NAME="itemlostcount" --> Lost (<!-- TMPL_VAR NAME="itemlostcount" -->)<br /><!-- /TMPL_IF -->
-                            <!-- TMPL_IF NAME="orderedcount" --> On order (<!-- TMPL_VAR NAME="orderedcount" -->)<!-- /TMPL_IF -->
-                        </span>
                     </td>
                     <!-- TMPL_IF NAME="RequestOnOpac" -->
                     <td>