X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FOverdues.pm;h=660e10b830b055a4202207b54e3141db20f29e59;hb=db946ffd58094ec6287f991493a8df7bd7298f71;hp=adba9793b763b5e39be58fdf36d5aab5354034e1;hpb=36d64bd18c5695d773c9d956796c605fd7ae25c9;p=koha_gimpoz diff --git a/C4/Overdues.pm b/C4/Overdues.pm index adba9793b7..660e10b830 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -2,6 +2,7 @@ package C4::Overdues; # Copyright 2000-2002 Katipo Communications +# copyright 2010 BibLibre # # This file is part of Koha. # @@ -78,7 +79,6 @@ BEGIN { # subs to move to Members.pm push @EXPORT, qw( &CheckBorrowerDebarred - &UpdateBorrowerDebarred ); # subs to move to Biblio.pm push @EXPORT, qw( @@ -164,8 +164,37 @@ Returns a count and a list of overdueitems for a given borrowernumber sub checkoverdues { my $borrowernumber = shift or return; + # don't select biblioitems.marc or biblioitems.marcxml... too slow on large systems my $sth = C4::Context->dbh->prepare( - "SELECT * FROM issues + "SELECT biblio.*, items.*, issues.*, + biblioitems.volume, + biblioitems.number, + biblioitems.itemtype, + biblioitems.isbn, + biblioitems.issn, + biblioitems.publicationyear, + biblioitems.publishercode, + biblioitems.volumedate, + biblioitems.volumedesc, + biblioitems.collectiontitle, + biblioitems.collectionissn, + biblioitems.collectionvolume, + biblioitems.editionstatement, + biblioitems.editionresponsibility, + biblioitems.illus, + biblioitems.pages, + biblioitems.notes, + biblioitems.size, + biblioitems.place, + biblioitems.lccn, + biblioitems.url, + biblioitems.cn_source, + biblioitems.cn_class, + biblioitems.cn_item, + biblioitems.cn_suffix, + biblioitems.cn_sort, + biblioitems.totalissues + FROM issues LEFT JOIN items ON issues.itemnumber = items.itemnumber LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber @@ -488,12 +517,12 @@ sub UpdateFine { if ( my $data = $sth->fetchrow_hashref ) { - # we're updating an existing fine. Only modify if we're adding to the charge. + # we're updating an existing fine. Only modify if amount changed # Note that in the current implementation, you cannot pay against an accruing fine # (i.e. , of accounttype 'FU'). Doing so will break accrual. if ( $data->{'amount'} != $amount ) { my $diff = $amount - $data->{'amount'}; - $diff = 0 if ( $data->{amount} > $amount); + #3341: diff could be positive or negative! my $out = $data->{'amountoutstanding'} + $diff; my $query = " UPDATE accountlines @@ -614,13 +643,16 @@ C<$borrowernumber> is the borrowernumber sub GetFine { my ( $itemnum, $borrowernumber ) = @_; my $dbh = C4::Context->dbh(); - my $query = "SELECT sum(amountoutstanding) FROM accountlines - where accounttype like 'F%' - AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?"; + my $query = q|SELECT sum(amountoutstanding) as fineamount FROM accountlines + where accounttype like 'F%' + AND amountoutstanding > 0 AND itemnumber = ? AND borrowernumber=?|; my $sth = $dbh->prepare($query); $sth->execute( $itemnum, $borrowernumber ); - my $data = $sth->fetchrow_hashref(); - return ( $data->{'sum(amountoutstanding)'} ); + my $fine = $sth->fetchrow_hashref(); + if ($fine->{fineamount}) { + return $fine->{fineamount}; + } + return 0; } @@ -956,9 +988,13 @@ returns a list of branch codes for branches with overdue rules defined. sub GetBranchcodesWithOverdueRules { my $dbh = C4::Context->dbh; - my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> ''"); + my $rqoverduebranches = $dbh->prepare("SELECT DISTINCT branchcode FROM overduerules WHERE delay1 IS NOT NULL AND branchcode <> '' ORDER BY branchcode"); $rqoverduebranches->execute; my @branches = map { shift @$_ } @{ $rqoverduebranches->fetchall_arrayref }; + if (!$branches[0]) { + my $availbranches = C4::Branch::GetBranches(); + @branches = keys %$availbranches; + } return @branches; } @@ -1043,35 +1079,14 @@ sub CheckBorrowerDebarred { SELECT debarred FROM borrowers WHERE borrowernumber=? + AND debarred > NOW() |; my $sth = $dbh->prepare($query); $sth->execute($borrowernumber); - my ($debarredstatus) = $sth->fetchrow; - return ( $debarredstatus eq '1' ? 1 : 0 ); + my $debarredstatus = $sth->fetchrow; + return $debarredstatus; } -=head2 UpdateBorrowerDebarred - - ($borrowerstatut) = &UpdateBorrowerDebarred($borrowernumber); - -update status of borrowers in borrowers table (field debarred) - -C<$borrowernumber> borrower number - -=cut - -sub UpdateBorrowerDebarred{ - my($borrowernumber) = @_; - my $dbh = C4::Context->dbh; - my $query=qq|UPDATE borrowers - SET debarred='1' - WHERE borrowernumber=? - |; - my $sth=$dbh->prepare($query); - $sth->execute($borrowernumber); - $sth->finish; - return 1; -} =head2 CheckExistantNotifyid