[Koha-cvs] CVS: koha/C4 Reserves2.pm,1.6,1.7

Finlay Thompson finlayt at users.sourceforge.net
Thu Jun 6 04:47:56 CEST 2002


Update of /cvsroot/koha/koha/C4
In directory usw-pr-cvs1:/tmp/cvs-serv14624/C4

Modified Files:
	Reserves2.pm 
Log Message:

improved all the code so that priorities are reset properly.


Index: Reserves2.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Reserves2.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** Reserves2.pm	29 May 2002 04:39:12 -0000	1.6
--- Reserves2.pm	6 Jun 2002 02:47:53 -0000	1.7
***************
*** 16,20 ****
      
  @ISA = qw(Exporter);
! @EXPORT = qw(&FindReserves &CheckReserves &CancelReserve &ReserveWaiting &CreateReserve &updatereserves &getreservetitle &Findgroupreserve);
  %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
  		  
--- 16,20 ----
      
  @ISA = qw(Exporter);
! @EXPORT = qw(&FindReserves &CheckReserves &CheckWaiting &CancelReserve &FillReserve &ReserveWaiting &CreateReserve &updatereserves &getreservetitle &Findgroupreserve);
  %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
  		  
***************
*** 55,60 ****
    my ($bib,$bor) = @_;
    my $dbh = C4Connect;
!   my $query = "Select *,reserves.branchcode,biblio.title as btitle
!                       from reserves,borrowers,biblio ";
    if ($bib ne ''){
        $bib = $dbh->quote($bib);
--- 55,60 ----
    my ($bib,$bor) = @_;
    my $dbh = C4Connect;
!   my $query = "SELECT *,reserves.branchcode,biblio.title AS btitle
!                       FROM reserves,borrowers,biblio ";
    if ($bib ne ''){
        $bib = $dbh->quote($bib);
***************
*** 101,115 ****
      my $qitem=$dbh->quote($item);
  # get the biblionumber...
!     my $sth=$dbh->prepare("select biblionumber from items where itemnumber=$qitem");
      $sth->execute;
!     my ($biblio) = $sth->fetchrow_array;
      $sth->finish;
      $dbh->disconnect;
  # get the reserves...
!     my ($count, $reserves) = FindReserves($biblio);
      my $priority = 10000000; 
      my $highest;
      if ($count) {
! 	foreach my $res (@$reserves) {
  	    if ($res->{'itemnumber'} == $item) {
  		return ("Waiting", $res);
--- 101,115 ----
      my $qitem=$dbh->quote($item);
  # get the biblionumber...
!     my $sth=$dbh->prepare("select biblionumber, biblioitemnumber from items where itemnumber=$qitem");
      $sth->execute;
!     my ($biblio, $bibitem) = $sth->fetchrow_array;
      $sth->finish;
      $dbh->disconnect;
  # get the reserves...
!     my ($count, @reserves) = Findgroupreserve($bibitem, $biblio);
      my $priority = 10000000; 
      my $highest;
      if ($count) {
! 	foreach my $res (@reserves) {
  	    if ($res->{'itemnumber'} == $item) {
  		return ("Waiting", $res);
***************
*** 131,134 ****
--- 131,135 ----
      my ($biblio, $item, $borr) = @_;
      my $dbh=C4Connect;
+     warn "In CancelReserve";
      if (($item and $borr) and (not $biblio)) {
  # removing a waiting reserve record....
***************
*** 147,158 ****
      if (($biblio and $borr) and (not $item)) {
  # removing a reserve record....
! 	$biblio = $dbh->quote($biblio);
  	$borr = $dbh->quote($borr);
  # fix up the priorities on the other records....
! 	my $query = "select priority from reserves 
!                                     where biblionumber   = $biblio 
!                                       and borrowernumber = $borr
!                                       and cancellationdate is NULL 
!                                       and (found <> 'F' or found is NULL)";
  	my $sth=$dbh->prepare($query);
  	$sth->execute;
--- 148,159 ----
      if (($biblio and $borr) and (not $item)) {
  # removing a reserve record....
! 	my $q_biblio = $dbh->quote($biblio);
  	$borr = $dbh->quote($borr);
  # fix up the priorities on the other records....
! 	my $query = "SELECT priority FROM reserves 
!                                     WHERE biblionumber   = $q_biblio 
!                                       AND borrowernumber = $borr
!                                       AND cancellationdate is NULL 
!                                       AND (found <> 'F' or found is NULL)";
  	my $sth=$dbh->prepare($query);
  	$sth->execute;
***************
*** 163,167 ****
                                           found            = Null, 
                                           priority         = 0 
!                                    where biblionumber     = $biblio 
                                       and borrowernumber   = $borr
                                       and cancellationdate is NULL 
--- 164,168 ----
                                           found            = Null, 
                                           priority         = 0 
!                                    where biblionumber     = $q_biblio 
                                       and borrowernumber   = $borr
                                       and cancellationdate is NULL 
***************
*** 171,188 ****
  	$sth->finish;
  # now fix the priority on the others....
! 	my ($count, $reserves) = FindReserves($biblio);
! 	foreach my $rec (@$reserves) {
! 	    if ($rec->{'priority'} > $priority) {
! 		my $newpr = $rec->{'priority'};
! 		$newpr = $dbh->quote($newpr - 1);
!                 my $query = "update reserves set priority = $newpr 
!                                    where biblionumber     = $rec->{'biblionumber'} 
!                                      and borrowernumber   = $rec->{'borrowernumber'}
!                                      and cancellationdate is NULL 
!                                      and (found <> 'F' or found is NULL)";
! 		my $sth = $dbh->prepare($query);
! 		$sth->execute;
! 		$sth->finish;
! 	    }
  	} 
      }
--- 172,220 ----
  	$sth->finish;
  # now fix the priority on the others....
! 	fixpriority($priority, $biblio);
!     }
!     $dbh->disconnect;
! }
! 
! 
! sub FillReserve {
!     my ($res) = @_;
!     my $dbh=C4Connect;
! # removing a waiting reserve record....
!     my $biblio = $res->{'biblionumber'}; my $qbiblio = $dbh->quote($biblio);
!     my $borr = $res->{'borrowernumber'}; $borr = $dbh->quote($borr);
!     my $resdate = $res->{'reservedate'}; $resdate = $dbh->quote($resdate);
! # update the database...
!     my $query = "UPDATE reserves SET found            = 'F', 
!                                      priority         = 0 
!                                WHERE biblionumber     = $qbiblio
!                                  AND reservedate      = $resdate
!                                  AND borrowernumber   = $borr";
!     my $sth = $dbh->prepare($query);
!     $sth->execute;
!     $sth->finish;
!     $dbh->disconnect;
! # now fix the priority on the others....
!     fixpriority($res->{'priority'}, $biblio);
! }
! 
! sub fixpriority {
!     my ($priority, $biblio) =  @_;
!     my $dbh = C4Connect;
!     my ($count, $reserves) = FindReserves($biblio);
!     foreach my $rec (@$reserves) {
! 	if ($rec->{'priority'} > $priority) {
! 	    my $newpr = $rec->{'priority'};      $newpr = $dbh->quote($newpr - 1);
! 	    my $nbib = $rec->{'biblionumber'};   $nbib = $dbh->quote($nbib);
! 	    my $nbor = $rec->{'borrowernumber'}; $nbor = $dbh->quote($nbor);
! 	    my $nresd = $rec->{'reservedate'};   $nresd = $dbh->quote($nresd);
!             my $query = "UPDATE reserves SET priority = $newpr 
!                                WHERE biblionumber     = $nbib 
!                                  AND borrowernumber   = $nbor
!                                  AND reservedate      = $nresd";
! 	    warn $query;
! 	    my $sth = $dbh->prepare($query);
! 	    $sth->execute;
! 	    $sth->finish;
  	} 
      }
***************
*** 190,193 ****
--- 222,227 ----
  }
  
+ 
+ 
  sub ReserveWaiting {
      my ($item, $borr) = @_;
***************
*** 210,243 ****
      $sth->finish;
      my $biblio = $data->{'biblionumber'};
!     $biblio = $dbh->quote($biblio);
  # update reserves record....
!     $query = "update reserves set priority = 0, found = 'W', itemnumber = $item 
!                             where borrowernumber = $borr and biblionumber = $biblio";
      $sth = $dbh->prepare($query);
      $sth->execute;
      $sth->finish;
  # now fix up the remaining priorities....
!     $query = "select priority, borrowernumber from reserves where biblionumber = $biblio
!                                               and cancellationdate is NULL
!                                               and found is NULL
!                                               and priority <> 0 and priority is not NULL";
!     $sth = $dbh->prepare($query);
!     $sth->execute;
      my $branchcode = $data->{'branchcode'};
!     my $priority = $data->{'priority'};
!     while (my $data = $sth->fetchrow_hashref) {
! 	if ($data->{'priority'} > $priority) {
!             my $uquery = "update reserves set priority       = priority - 1 
!                                         where biblionumber   = $biblio 
!                                           and borrowernumber = $borr
!                                           and cancellation  is NULL";
! 	    my $usth->$dbh->prepare($query);
! 	    $usth->execute;
! 	    $usth->finish;
! 	}
      }
      $sth->finish;
!     $dbh->disconnect;
!     return $branchcode;
  }
  
--- 244,279 ----
      $sth->finish;
      my $biblio = $data->{'biblionumber'};
!     my $q_biblio = $dbh->quote($biblio);
  # update reserves record....
!     $query = "UPDATE reserves SET priority = 0, found = 'W', itemnumber = $item 
!                             WHERE borrowernumber = $borr AND biblionumber = $q_biblio";
      $sth = $dbh->prepare($query);
      $sth->execute;
      $sth->finish;
+     $dbh->disconnect;
  # now fix up the remaining priorities....
!     fixpriority($data->{'priority'}, $biblio);
      my $branchcode = $data->{'branchcode'};
!     return $branchcode;
! }
! 
! sub CheckWaiting {
!     my ($borr)=@_;
!     my $dbh = C4Connect;
!     $borr = $dbh->quote($borr);
!     my @itemswaiting;
!     my $query = "SELECT * FROM reserves
!                          WHERE borrowernumber = $borr
!                            AND reserves.found = 'W' 
!                            AND cancellationdate is NULL";
!     my $sth = $dbh->prepare($query);
!     $sth->execute();
!     my $cnt=0;
!     if (my $data=$sth->fetchrow_hashref) {
! 	@itemswaiting[$cnt] =$data;
! 	$cnt ++;
      }
      $sth->finish;
!     return ($cnt,\@itemswaiting);
  }
  
***************
*** 246,261 ****
    my $dbh=C4Connect;
    $bibitem=$dbh->quote($bibitem);
!   my $query="Select * from reserves 
!   left join reserveconstraints on
!   reserves.biblionumber=reserveconstraints.biblionumber
!   where
!   reserves.biblionumber=$biblio and
!   ((reserveconstraints.biblioitemnumber=$bibitem 
!   and reserves.borrowernumber=reserveconstraints.borrowernumber
!   and reserves.reservedate=reserveconstraints.reservedate)
!   or reserves.constrainttype='a')
!   and reserves.cancellationdate is NULL
!   and (reserves.found <> 'F' or reserves.found is NULL)";
! #  print $query;
    my $sth=$dbh->prepare($query);
    $sth->execute;
--- 282,305 ----
    my $dbh=C4Connect;
    $bibitem=$dbh->quote($bibitem);
!   my $query = "SELECT reserves.biblionumber               AS biblionumber, 
!                       reserves.borrowernumber             AS borrowernumber, 
!                       reserves.reservedate                AS reservedate, 
!                       reserves.branchcode                 AS branchcode, 
!                       reserves.cancellationdate           AS cancellationdate, 
!                       reserves.found                      AS found, 
!                       reserves.reservenotes               AS reservenotes, 
!                       reserves.priority                   AS priority, 
!                       reserves.timestamp                  AS timestamp, 
!                       reserveconstraints.biblioitemnumber AS biblioitemnumber, 
!                       reserves.itemnumber                 AS itemnumber 
!                  FROM reserves LEFT JOIN reserveconstraints
!                    ON reserves.biblionumber = reserveconstraints.biblionumber
!                 WHERE reserves.biblionumber = $biblio
!                   AND ( ( reserveconstraints.biblioitemnumber = $bibitem 
!                       AND reserves.borrowernumber = reserveconstraints.borrowernumber
!                       AND reserves.reservedate    =reserveconstraints.reservedate )
!                    OR reserves.constrainttype='a' )
!                   AND reserves.cancellationdate is NULL
!                   AND (reserves.found <> 'F' or reserves.found is NULL)";
    my $sth=$dbh->prepare($query);
    $sth->execute;





More information about the Koha-cvs mailing list