|
Lines 2-7
package C4::Items;
Link Here
|
| 2 |
|
2 |
|
| 3 |
# Copyright 2007 LibLime, Inc. |
3 |
# Copyright 2007 LibLime, Inc. |
| 4 |
# |
4 |
# |
|
|
5 |
# Parts copyright Catalyst IT 2010 |
| 6 |
# |
| 5 |
# This file is part of Koha. |
7 |
# This file is part of Koha. |
| 6 |
# |
8 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it under the |
9 |
# Koha is free software; you can redistribute it and/or modify it under the |
|
Lines 1168-1297
If this is set, it is set to C<One Order>.
Link Here
|
| 1168 |
sub GetItemsInfo { |
1170 |
sub GetItemsInfo { |
| 1169 |
my ( $biblionumber, $type ) = @_; |
1171 |
my ( $biblionumber, $type ) = @_; |
| 1170 |
my $dbh = C4::Context->dbh; |
1172 |
my $dbh = C4::Context->dbh; |
|
|
1173 |
|
| 1174 |
# get notforloan complete status if applicable |
| 1175 |
my $sthnflstatus = $dbh->prepare( |
| 1176 |
"SELECT authorised_value |
| 1177 |
FROM marc_subfield_structure |
| 1178 |
WHERE kohafield='items.notforloan' |
| 1179 |
" |
| 1180 |
); |
| 1181 |
$sthnflstatus->execute; |
| 1182 |
my ($authorised_value_nfl) = $sthnflstatus->fetchrow; |
| 1183 |
|
| 1184 |
# my stack procedures |
| 1185 |
my $stackstatus = $dbh->prepare( |
| 1186 |
'SELECT authorised_value |
| 1187 |
FROM marc_subfield_structure |
| 1188 |
WHERE kohafield="items.stack" |
| 1189 |
' |
| 1190 |
); |
| 1191 |
$stackstatus->execute; |
| 1192 |
my ($authorised_value_stack) = $stackstatus->fetchrow; |
| 1193 |
|
| 1194 |
my $user_branch; |
| 1195 |
if (C4::Context->preference("IndependantBranches")){ |
| 1196 |
my $userenv = C4::Context->userenv; |
| 1197 |
$user_branch = $userenv->{branch} if $userenv && ( $userenv->{flags} % 2 != 1 ); |
| 1198 |
} |
| 1199 |
|
| 1171 |
# note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance. |
1200 |
# note biblioitems.* must be avoided to prevent large marc and marcxml fields from killing performance. |
| 1172 |
my $query = " |
1201 |
my $fields = <<EOS; |
| 1173 |
SELECT items.*, |
1202 |
items.*, |
| 1174 |
biblio.*, |
1203 |
biblio.*, |
| 1175 |
biblioitems.volume, |
1204 |
issues.*, |
| 1176 |
biblioitems.number, |
1205 |
biblioitems.volume, |
| 1177 |
biblioitems.itemtype, |
1206 |
biblioitems.number, |
| 1178 |
biblioitems.isbn, |
1207 |
biblioitems.itemtype, |
| 1179 |
biblioitems.issn, |
1208 |
biblioitems.isbn, |
| 1180 |
biblioitems.publicationyear, |
1209 |
biblioitems.issn, |
| 1181 |
biblioitems.publishercode, |
1210 |
biblioitems.publicationyear, |
| 1182 |
biblioitems.volumedate, |
1211 |
biblioitems.publishercode, |
| 1183 |
biblioitems.volumedesc, |
1212 |
biblioitems.volumedate, |
| 1184 |
biblioitems.lccn, |
1213 |
biblioitems.volumedesc, |
| 1185 |
biblioitems.url, |
1214 |
biblioitems.lccn, |
| 1186 |
items.notforloan as itemnotforloan, |
1215 |
biblioitems.url, |
| 1187 |
itemtypes.description, |
1216 |
items.notforloan as itemnotforloan, |
| 1188 |
itemtypes.notforloan as notforloan_per_itemtype, |
1217 |
itemtypes.description, |
| 1189 |
branchurl |
1218 |
itemtypes.notforloan as notforloan_per_itemtype, |
| 1190 |
FROM items |
1219 |
homebranch.branchurl, |
| 1191 |
LEFT JOIN branches ON items.homebranch = branches.branchcode |
1220 |
COALESCE(holdingbranch.branchname, homebranch.branchname) AS branchname, |
| 1192 |
LEFT JOIN biblio ON biblio.biblionumber = items.biblionumber |
1221 |
serial.serialseq, |
| 1193 |
LEFT JOIN biblioitems ON biblioitems.biblioitemnumber = items.biblioitemnumber |
1222 |
serial.publisheddate |
| 1194 |
LEFT JOIN itemtypes ON itemtypes.itemtype = " |
1223 |
EOS |
| 1195 |
. (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'); |
1224 |
my $itemtypes_join_field = C4::Context->preference('item-level_itypes') ? 'items.itype' |
| 1196 |
$query .= " WHERE items.biblionumber = ? ORDER BY branches.branchname,items.dateaccessioned desc" ; |
1225 |
: 'biblioitems.itemtype'; |
|
|
1226 |
my $from = <<EOS; |
| 1227 |
items |
| 1228 |
LEFT JOIN biblio USING(biblionumber) |
| 1229 |
LEFT JOIN biblioitems USING(biblioitemnumber) |
| 1230 |
LEFT OUTER JOIN (SELECT itemnumber, serialseq, publisheddate |
| 1231 |
FROM serialitems LEFT JOIN serial USING(serialid)) serial |
| 1232 |
USING(itemnumber) |
| 1233 |
LEFT OUTER JOIN (SELECT itemnumber, borrowernumber, cardnumber, surname, firstname, date_due, |
| 1234 |
borrowers.branchcode AS borrower_branchcode |
| 1235 |
FROM issues LEFT JOIN borrowers USING(borrowernumber)) issues |
| 1236 |
USING(itemnumber) |
| 1237 |
LEFT JOIN itemtypes ON itemtypes.itemtype = $itemtypes_join_field |
| 1238 |
LEFT JOIN branches homebranch ON items.homebranch = homebranch.branchcode |
| 1239 |
LEFT OUTER JOIN branches holdingbranch ON items.holdingbranch = holdingbranch.branchcode |
| 1240 |
EOS |
| 1241 |
if ($authorised_value_nfl) { |
| 1242 |
$from .= <<EOS; |
| 1243 |
LEFT OUTER JOIN authorised_values authorised_values_nfl |
| 1244 |
ON authorised_values_nfl.category = '$authorised_value_nfl' |
| 1245 |
AND authorised_values_nfl.authorised_value = items.notforloan |
| 1246 |
EOS |
| 1247 |
$fields .= ", authorised_values_nfl.lib AS notforloanvalue"; |
| 1248 |
} |
| 1249 |
|
| 1250 |
if ($authorised_value_stack) { |
| 1251 |
$from .= <<EOS; |
| 1252 |
LEFT OUTER JOIN authorised_values authorised_values_stack |
| 1253 |
ON authorised_values_nfl.category = '$authorised_value_stack' |
| 1254 |
AND authorised_values_nfl.authorised_value = items.stack |
| 1255 |
EOS |
| 1256 |
$fields .= ", authorised_values_stack.lib AS stack"; |
| 1257 |
} |
| 1258 |
|
| 1259 |
my $query = "SELECT $fields FROM $from WHERE items.biblionumber = ? |
| 1260 |
ORDER BY homebranch.branchname,items.dateaccessioned desc" ; |
| 1197 |
my $sth = $dbh->prepare($query); |
1261 |
my $sth = $dbh->prepare($query); |
| 1198 |
$sth->execute($biblionumber); |
1262 |
$sth->execute($biblionumber); |
| 1199 |
my $i = 0; |
1263 |
|
| 1200 |
my @results; |
1264 |
my @results; |
| 1201 |
my $serial; |
1265 |
my $serial; |
| 1202 |
|
|
|
| 1203 |
my $isth = $dbh->prepare( |
| 1204 |
"SELECT issues.*,borrowers.cardnumber,borrowers.surname,borrowers.firstname,borrowers.branchcode as bcode |
| 1205 |
FROM issues LEFT JOIN borrowers ON issues.borrowernumber=borrowers.borrowernumber |
| 1206 |
WHERE itemnumber = ?" |
| 1207 |
); |
| 1208 |
my $ssth = $dbh->prepare("SELECT serialseq,publisheddate from serialitems left join serial on serialitems.serialid=serial.serialid where serialitems.itemnumber=? "); |
| 1209 |
while ( my $data = $sth->fetchrow_hashref ) { |
1266 |
while ( my $data = $sth->fetchrow_hashref ) { |
| 1210 |
my $datedue = ''; |
1267 |
my $datedue = $data->{'date_due'}; |
| 1211 |
my $count_reserves; |
1268 |
my $count_reserves; |
| 1212 |
$isth->execute( $data->{'itemnumber'} ); |
1269 |
|
| 1213 |
if ( my $idata = $isth->fetchrow_hashref ) { |
1270 |
$data->{'NOTSAMEBRANCH'} = $data->{'borrower_branchcode'} ne $user_branch |
| 1214 |
$data->{borrowernumber} = $idata->{borrowernumber}; |
1271 |
if $data->{'borrower_branchcode'} && $user_branch; |
| 1215 |
$data->{cardnumber} = $idata->{cardnumber}; |
1272 |
|
| 1216 |
$data->{surname} = $idata->{surname}; |
1273 |
$serial = 1 if $data->{'serial'}; |
| 1217 |
$data->{firstname} = $idata->{firstname}; |
1274 |
|
| 1218 |
$datedue = $idata->{'date_due'}; |
1275 |
unless ( $datedue ) { |
| 1219 |
if (C4::Context->preference("IndependantBranches")){ |
|
|
| 1220 |
my $userenv = C4::Context->userenv; |
| 1221 |
if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) { |
| 1222 |
$data->{'NOTSAMEBRANCH'} = 1 if ($idata->{'bcode'} ne $userenv->{branch}); |
| 1223 |
} |
| 1224 |
} |
| 1225 |
} |
| 1226 |
if ( $data->{'serial'}) { |
| 1227 |
$ssth->execute($data->{'itemnumber'}) ; |
| 1228 |
($data->{'serialseq'} , $data->{'publisheddate'}) = $ssth->fetchrow_array(); |
| 1229 |
$serial = 1; |
| 1230 |
} |
| 1231 |
if ( $datedue eq '' ) { |
| 1232 |
my ( $restype, $reserves ) = |
1276 |
my ( $restype, $reserves ) = |
| 1233 |
C4::Reserves::CheckReserves( $data->{'itemnumber'} ); |
1277 |
C4::Reserves::MostImportantReserve( $data->{'biblioitemnumber'}, $data->{'biblionumber'}, $data->{'itemnumber'} ); |
| 1234 |
# Previous conditional check with if ($restype) is not needed because a true |
1278 |
# Previous conditional check with if ($restype) is not needed because a true |
| 1235 |
# result for one item will result in subsequent items defaulting to this true |
1279 |
# result for one item will result in subsequent items defaulting to this true |
| 1236 |
# value. |
1280 |
# value. |
| 1237 |
$count_reserves = $restype; |
1281 |
$count_reserves = $restype; |
| 1238 |
} |
1282 |
} |
| 1239 |
#get branch information..... |
|
|
| 1240 |
my $bsth = $dbh->prepare( |
| 1241 |
"SELECT * FROM branches WHERE branchcode = ? |
| 1242 |
" |
| 1243 |
); |
| 1244 |
$bsth->execute( $data->{'holdingbranch'} ); |
| 1245 |
if ( my $bdata = $bsth->fetchrow_hashref ) { |
| 1246 |
$data->{'branchname'} = $bdata->{'branchname'}; |
| 1247 |
} |
| 1248 |
$data->{'datedue'} = $datedue; |
1283 |
$data->{'datedue'} = $datedue; |
| 1249 |
$data->{'count_reserves'} = $count_reserves; |
1284 |
$data->{'count_reserves'} = $count_reserves; |
| 1250 |
|
1285 |
|
| 1251 |
# get notforloan complete status if applicable |
|
|
| 1252 |
my $sthnflstatus = $dbh->prepare( |
| 1253 |
'SELECT authorised_value |
| 1254 |
FROM marc_subfield_structure |
| 1255 |
WHERE kohafield="items.notforloan" |
| 1256 |
' |
| 1257 |
); |
| 1258 |
|
| 1259 |
$sthnflstatus->execute; |
| 1260 |
my ($authorised_valuecode) = $sthnflstatus->fetchrow; |
| 1261 |
if ($authorised_valuecode) { |
| 1262 |
$sthnflstatus = $dbh->prepare( |
| 1263 |
"SELECT lib FROM authorised_values |
| 1264 |
WHERE category=? |
| 1265 |
AND authorised_value=?" |
| 1266 |
); |
| 1267 |
$sthnflstatus->execute( $authorised_valuecode, |
| 1268 |
$data->{itemnotforloan} ); |
| 1269 |
my ($lib) = $sthnflstatus->fetchrow; |
| 1270 |
$data->{notforloanvalue} = $lib; |
| 1271 |
} |
| 1272 |
|
| 1273 |
# my stack procedures |
| 1274 |
my $stackstatus = $dbh->prepare( |
| 1275 |
'SELECT authorised_value |
| 1276 |
FROM marc_subfield_structure |
| 1277 |
WHERE kohafield="items.stack" |
| 1278 |
' |
| 1279 |
); |
| 1280 |
$stackstatus->execute; |
| 1281 |
|
| 1282 |
($authorised_valuecode) = $stackstatus->fetchrow; |
| 1283 |
if ($authorised_valuecode) { |
| 1284 |
$stackstatus = $dbh->prepare( |
| 1285 |
"SELECT lib |
| 1286 |
FROM authorised_values |
| 1287 |
WHERE category=? |
| 1288 |
AND authorised_value=? |
| 1289 |
" |
| 1290 |
); |
| 1291 |
$stackstatus->execute( $authorised_valuecode, $data->{stack} ); |
| 1292 |
my ($lib) = $stackstatus->fetchrow; |
| 1293 |
$data->{stack} = $lib; |
| 1294 |
} |
| 1295 |
# Find the last 3 people who borrowed this item. |
1286 |
# Find the last 3 people who borrowed this item. |
| 1296 |
my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers |
1287 |
my $sth2 = $dbh->prepare("SELECT * FROM old_issues,borrowers |
| 1297 |
WHERE itemnumber = ? |
1288 |
WHERE itemnumber = ? |
|
Lines 1307-1314
sub GetItemsInfo {
Link Here
|
| 1307 |
$ii++; |
1298 |
$ii++; |
| 1308 |
} |
1299 |
} |
| 1309 |
|
1300 |
|
| 1310 |
$results[$i] = $data; |
1301 |
push @results, $data; |
| 1311 |
$i++; |
|
|
| 1312 |
} |
1302 |
} |
| 1313 |
if($serial) { |
1303 |
if($serial) { |
| 1314 |
return( sort { ($b->{'publisheddate'} || $b->{'enumchron'}) cmp ($a->{'publisheddate'} || $a->{'enumchron'}) } @results ); |
1304 |
return( sort { ($b->{'publisheddate'} || $b->{'enumchron'}) cmp ($a->{'publisheddate'} || $a->{'enumchron'}) } @results ); |