From dcbecbc8de2649ed94e41cbdb5727732dc1e1537 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Wed, 21 May 2014 08:05:53 -0400
Subject: [PATCH] [SIGNED OFF] Bug 12302 - OPAC course details not displaying
 item status correctly for itemtypes that are not for loan

If an item is not for loan based on it's itemtype,
opac-detail.pl will show the item as "Not for loan"
but opac-course-details.pl will show the item as "Available".

Test Plan:
1) Enable course reserves
2) Create a course, add an item to it
3) Edit that item's itemtype, set it to not for loan
4) View the item from opac-detail.pl, note the status is "Not for loan"
5) View the item from opac-course-details.pl, note the status is "Available"
6) Apply this patch
7) Reload opac-course-details.pl, not the status is now "Not for loan"

Signed-off-by: Frederic Demians <f.demians@tamil.fr>

This is a revised version of the patch, introducing a invalid display on item
table (see obsolete bug 13155). It works, and correct the bug described by
Kyle. A 2nd sign-off may be necessrary.

Signed-off-by: Nick Clemens <nick@quecheelibrary.org>
---
 C4/Biblio.pm |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index ec4c71e..b3c8c12 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -893,10 +893,12 @@ sub GetBiblioFromItemNumber {
     my $sth;
     if ($itemnumber) {
         $sth = $dbh->prepare(
-            "SELECT * FROM items 
+            "SELECT items.*, biblio.*, biblioitems.*, itemtypes.notforloan as notforloan_per_itemtype FROM items
             LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber
             LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber
-             WHERE items.itemnumber = ?"
+            LEFT JOIN itemtypes ON itemtypes.itemtype = " .
+            (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype') .
+            " WHERE items.itemnumber = ?"
         );
         $sth->execute($itemnumber);
     } else {
-- 
1.7.10.4