From 2480e024363b26723323ee25a18f12e0797bbca7 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Thu, 17 Dec 2009 09:24:22 +0100 Subject: [PATCH] (bug #3950) rebuild pendingreserves and fix reserves and transfert case This patch rebuild pending reserves, export code to API and simplify SQL query(that was _very_ ugly!). It fixes too circulation case, when a document is transfered because of user hold, it's still shown in pending reserves, now it don't. --- C4/Reserves.pm | 96 +++++++++- circ/pendingreserves.pl | 171 +----------------- .../prog/en/modules/circ/pendingreserves.tmpl | 58 ++---- 3 files changed, 116 insertions(+), 209 deletions(-) diff --git a/C4/Reserves.pm b/C4/Reserves.pm index b7b22ef523..e008500845 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -24,6 +24,7 @@ use strict; # use warnings; # FIXME: someday use C4::Context; use C4::Biblio; +use C4::Dates qw/format_date format_date_in_iso/; use C4::Members; use C4::Items; use C4::Search; @@ -56,6 +57,7 @@ C4::Reserves - Koha functions for dealing with reservation. =0 : then the reserve is being dealed - found : NULL : means the patron requested the 1st available, and we haven't choosen the item W(aiting) : the reserve has an itemnumber affected, and is on the way + T(ransfet) : the reserve has an itemnumber affected, and is beeing transfered to pickup branch F(inished) : the reserve has been completed, and is done - itemnumber : empty : the reserve is still unaffected to an item filled: the reserve is attached to an item @@ -90,6 +92,7 @@ BEGIN { @EXPORT = qw( &AddReserve + &GetPendingReserves &GetReservesFromItemnumber &GetReservesFromBiblionumber &GetReservesFromBorrowernumber @@ -216,6 +219,94 @@ sub AddReserve { return; # FIXME: why not have a useful return value? } + + +=item GetPendingReserves + +=cut + +sub GetPendingReserves { + my ($startdate, $enddate) = @_; + + my $sqldatewhere; + my @query_params; + my $indepbranch = C4::Context->preference('IndependantBranches') ? C4::Context->userenv->{'branch'} : undef; + my $dbh = C4::Context->dbh; + + my $query = "SELECT * + FROM reserves + WHERE + reserves.found IS NULL "; + + if (!defined($startdate) or $startdate eq "") { + $startdate = format_date($startdate); + } + if (!defined($enddate) or $enddate eq "") { + $enddate = format_date($enddate); + } + + if ($startdate) { + $sqldatewhere .= " AND reservedate >= ?"; + push @query_params, format_date_in_iso($startdate); + } + if ($enddate) { + $sqldatewhere .= " AND reservedate <= ?"; + push @query_params, format_date_in_iso($enddate); + } + $query .= $sqldatewhere; + + if ($indepbranch){ + $query .= " AND branchcode = ? "; + push @query_params, $indepbranch; + } + + + my $sth = $dbh->prepare($query); + $sth->execute(@query_params); + + my %reserves; + + while ( my $reserve = $sth->fetchrow_hashref ) { + my $line; + unless( $line = $reserves{$reserve->{biblionumber}} ){ + $line = {}; + my $biblio = GetBiblioData($reserve->{biblionumber}); + my @items = GetItemsInfo($reserve->{biblionumber}); + + $line->{title} = $biblio->{title}; + + foreach my $item (@items){ + next if ($indepbranch && $indepbranch ne $item->{holdingbranch}); + $line->{count}++; + $line->{holdingbranches}->{$item->{holdingbranch}} = 1; + $line->{callnumbers}->{$item->{itemcallnumber}} = 1; + $line->{locations}->{$item->{location}} = 1; + $line->{itemtypes}->{$item->{itemtype}} = 1; + } + } + $line->{reservecount}++; + $reserves{$reserve->{biblionumber}} = $line if($line->{count}); + } + + my @reserves; + foreach my $rkey (keys %reserves){ + my $line = $reserves{$rkey}; + $line->{biblionumber} = $rkey; + + foreach my $datatype (qw/holdingbranches callnumbers locations itemtypes/){ + my @newdatas = (); + foreach my $data (keys %{$line->{$datatype}}){ + @newdatas = { 'value' => $data} + } + $line->{$datatype} = \@newdatas; + } + + push @reserves, $line; + } + + return \@reserves; +} + =item GetReservesFromBiblionumber ($count, $title_reserves) = &GetReserves($biblionumber); @@ -999,8 +1090,9 @@ sub ModReserveAffect { if ($transferToDo) { $query = " UPDATE reserves - SET priority = 0, - itemnumber = ? + SET priority = 0, + itemnumber = ?, + found = 'T' WHERE borrowernumber = ? AND biblionumber = ? "; diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 7fc02a132b..f3edd3604b 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -75,6 +75,7 @@ $startdate =~ s/^\s+//; $startdate =~ s/\s+$//; $enddate =~ s/^\s+//; $enddate =~ s/\s+$//; + # Check if null, should string match, if so set start and end date to yesterday if (!defined($startdate) or $startdate eq "") { $startdate = format_date($pastdate); @@ -83,179 +84,13 @@ if (!defined($enddate) or $enddate eq "") { $enddate = format_date($todaysdate); } - -my $dbh = C4::Context->dbh; -my ($sqlorderby, $sqldatewhere) = ("",""); -$debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate); -my @query_params = (); -if ($startdate) { - $sqldatewhere .= " AND reservedate >= ?"; - push @query_params, format_date_in_iso($startdate); -} -if ($enddate) { - $sqldatewhere .= " AND reservedate <= ?"; - push @query_params, format_date_in_iso($enddate); -} - -if ($order eq "biblio") { - $sqlorderby = " ORDER BY biblio.title "; -} elsif ($order eq "itype") { - $sqlorderby = " ORDER BY l_itype, location, l_itemcallnumber "; -} elsif ($order eq "location") { - $sqlorderby = " ORDER BY location, l_itemcallnumber, holdingbranch "; -} elsif ($order eq "date") { - $sqlorderby = " ORDER BY l_reservedate, location, l_itemcallnumber "; -} elsif ($order eq "library") { - $sqlorderby = " ORDER BY holdingbranch, l_itemcallnumber, location "; -} elsif ($order eq "call") { - $sqlorderby = " ORDER BY l_itemcallnumber, holdingbranch, location "; -} else { - $sqlorderby = " ORDER BY biblio.title "; -} -my $strsth = -"SELECT min(reservedate) as l_reservedate, - reserves.borrowernumber as borrowernumber, - GROUP_CONCAT(DISTINCT items.holdingbranch - ORDER BY items.itemnumber SEPARATOR '
') l_holdingbranch, - reserves.biblionumber, - reserves.branchcode, - GROUP_CONCAT(DISTINCT reserves.branchcode - ORDER BY items.itemnumber SEPARATOR ', ') l_branch, - items.holdingbranch as branch, - items.itemcallnumber, - GROUP_CONCAT(DISTINCT items.itype - ORDER BY items.itemnumber SEPARATOR '
') l_itype, - GROUP_CONCAT(DISTINCT items.location - ORDER BY items.itemnumber SEPARATOR '
') l_location, - GROUP_CONCAT(DISTINCT items.itemcallnumber - ORDER BY items.itemnumber SEPARATOR '
') l_itemcallnumber, - items.itemnumber, - notes, - notificationdate, - reminderdate, - max(priority) as priority, - reserves.found, - biblio.title, - biblio.author, - count(DISTINCT items.itemnumber) as icount, - count(DISTINCT reserves.borrowernumber) as rcount - FROM reserves - LEFT JOIN items ON items.biblionumber=reserves.biblionumber - LEFT JOIN biblio ON reserves.biblionumber=biblio.biblionumber - LEFT JOIN branchtransfers ON items.itemnumber=branchtransfers.itemnumber - WHERE -reserves.found IS NULL - $sqldatewhere -AND items.itemnumber NOT IN (SELECT itemnumber FROM branchtransfers where datearrived IS NULL) -AND items.itemnumber NOT IN (SELECT itemnumber FROM issues) -AND reserves.priority <> 0 -AND notforloan = 0 AND damaged = 0 AND itemlost = 0 AND wthdrawn = 0 -"; -# GROUP BY reserves.biblionumber allows only items that are not checked out, else multiples occur when -# multiple patrons have a hold on an item - - -if (C4::Context->preference('IndependantBranches')){ - $strsth .= " AND items.holdingbranch=? "; - push @query_params, C4::Context->userenv->{'branch'}; -} -$strsth .= " GROUP BY reserves.biblionumber " . $sqlorderby; - -my $sth = $dbh->prepare($strsth); -$sth->execute(@query_params); - -my @reservedata; -my $previous; -my $this; -while ( my $data = $sth->fetchrow_hashref ) { - $this=$data->{biblionumber}.":".$data->{borrowernumber}; - my @itemlist; - push( - @reservedata, - { - reservedate => format_date( $data->{l_reservedate} ), - priority => $data->{priority}, - name => $data->{l_patron}, - title => $data->{title}, - author => $data->{author}, - borrowernumber => $data->{borrowernumber}, - itemnum => $data->{itemnumber}, - phone => $data->{phone}, - email => $data->{email}, - biblionumber => $data->{biblionumber}, - statusw => ( $data->{found} eq "W" ), - statusf => ( $data->{found} eq "F" ), - holdingbranch => $data->{l_holdingbranch}, - branch => $data->{l_branch}, - itemcallnumber => $data->{l_itemcallnumber}, - notes => $data->{notes}, - notificationdate => $data->{notificationdate}, - reminderdate => $data->{reminderdate}, - count => $data->{icount}, - rcount => $data->{rcount}, - pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount}, - itype => $data->{l_itype}, - location => $data->{l_location} - } - ); - $previous=$this; -} - -$sth->finish; - -# *** I doubt any of this is needed now with the above fixes *** -d.u. - -#$strsth=~ s/AND reserves.itemnumber is NULL/AND reserves.itemnumber is NOT NULL/; -#$strsth=~ s/LEFT JOIN items ON items.biblionumber=reserves.biblionumber/LEFT JOIN items ON items.biblionumber=reserves.itemnumber/; -#$sth = $dbh->prepare($strsth); -#if (C4::Context->preference('IndependantBranches')){ -# $sth->execute(C4::Context->userenv->{'branch'}); -#} -#else { -# $sth->execute(); -#} -#while ( my $data = $sth->fetchrow_hashref ) { -# $this=$data->{biblionumber}.":".$data->{borrowernumber}; -# my @itemlist; -# push( -# @reservedata, -# { -# reservedate => format_date( $data->{l_reservedate} ), -# priority => $data->{priority}, -# name => $data->{l_patron}, -# title => $data->{title}, -# author => $data->{author}, -# borrowernumber => $data->{borrowernumber}, -# itemnum => $data->{itemnumber}, -# phone => $data->{phone}, -# email => $data->{email}, -# biblionumber => $data->{biblionumber}, -# statusw => ( $data->{found} eq "W" ), -# statusf => ( $data->{found} eq "F" ), -# holdingbranch => $data->{l_holdingbranch}, -# branch => $data->{l_branch}, -# itemcallnumber => $data->{l_itemcallnumber}, -# notes => $data->{notes}, -# notificationdate => $data->{notificationdate}, -# reminderdate => $data->{reminderdate}, -# count => $data->{icount}, -# rcount => $data->{rcount}, -# pullcount => $data->{icount} <= $data->{rcount} ? $data->{icount} : $data->{rcount}, -# itype => $data->{l_itype}, -# location => $data->{l_location}, -# thisitemonly => 1, -# -# } -# ); -# $previous=$this; -#} -#$sth->finish; +my $reservedata = C4::Reserves::GetPendingReserves(); $template->param( todaysdate => format_date($todaysdate), from => $startdate, to => $enddate, - reserveloop => \@reservedata, + reserveloop => $reservedata, "BiblioDefaultView".C4::Context->preference("BiblioDefaultView") => 1, DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), dateformat => C4::Context->preference("dateformat"), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl index 0876ae78f0..8d0d29543f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tmpl @@ -23,7 +23,7 @@ $.tablesorter.addParser({ $("#holdst").tablesorter({ dateFormat: 'uk', sortList: [[3,0]], - headers: { 0:{sorter:false},1:{sorter:false},3: { sorter: 'articles' },7:{sorter:false}} + headers: { 0:{sorter:false},1:{sorter:false},2: { sorter: 'articles' },6:{sorter:false}} }); }); //]]> @@ -49,9 +49,6 @@ $.tablesorter.addParser({ - @@ -77,52 +74,35 @@ $.tablesorter.addParser({ Available Locations &to=">Sort - - - - - - - + + - - - - - - - - - + + + +
- Pull This Many Items - Items Available Earliest Hold Date - &to=">Sort -

-

- - "> +

+

+ + "> + + + + + "> - - "> + "> - - "> - - - -

-
-   - "

-

-

in

-

Waiting

Fullfilled

+ +





-- 2.39.5