Permalink
Browse files

[fixes #14149993] make a transfer at checkin: lost, notlost, &c. Othe…

…r fixes:

- fix undef Perl warning in mapping in fines.pl
- fix overdue from datedue calculation, was using object instead of ISO date
  from issues
- finally finished work on refund owed for backdate checkin resulting
  in downward adjustment of fine
- converted Yes|No option to Continue prompt: Remove from patron's Lost Items
- retested and fixed some lost prompts +notissued/issued, +hold/nohold, &c.
  • Loading branch information...
1 parent 9f98f96 commit 09804e69cc989413f6bb3e1bd84b34210f7d7bf7 @hgq hgq committed Jul 18, 2011
Showing with 91 additions and 72 deletions.
  1. +40 −21 C4/Circulation.pm
  2. +8 −6 C4/Items.pm
  3. +2 −2 circ/returns.pl
  4. +39 −41 koha-tmpl/intranet-tmpl/prog/en/modules/circ/returns.tmpl
  5. +2 −2 misc/cronjobs/fines.pl
View
@@ -1545,7 +1545,7 @@ sub AddReturn {
$$issue{returndate} = $returndate;
$datedue = C4::Dates->new($$issue{date_due},'iso');
my $rd = $returndate; $rd =~ s/\D//g;
- my $dd = $datedue ; $dd =~ s/\D//g;
+ my $dd = $$issue{date_due}; $dd =~ s/\D//g;
if ($$issue{overdue} && ($rd <= $dd)) {
$$issue{overdue} = 0;
$dropbox = 1;
@@ -1844,8 +1844,6 @@ C<$flags> : hashref containing flags indicating checkin options. Can be one of:
Returns nothing.
-*** NOTE *** TODO: handle refund owed for payment+backdate checkin
-
=cut
sub _chargeToAccount
@@ -1961,14 +1959,14 @@ sub _FixAccountOverdues {
}
elsif (!$$issue{overdue}) { # wow: backdate checkin where it's no longer overdue
my $msg = 'adjusted to no longer overdue';
+ $msg .= ", returned $checkindate" if $$flags{atreturn};
$dbh->do("UPDATE accountlines
SET description = CONCAT(description, ', $msg'),
amountoutstanding = 0,
accounttype = 'F'
WHERE borrowernumber = $$issue{borrowernumber}
AND accountno = $$row{accountno}
");
- $msg .= ", returned $checkindate" if $$flags{atreturn};
_rcrFine($issue,$row,0);
_logFine($$issue{borrowernumber},$msg,1);
return;
@@ -2001,6 +1999,12 @@ sub _FixAccountOverdues {
## lower both the amount and the amountoutstanding by diff cmp to new amount
my $diff = $$row{amount} - $amount;
my $newout = $$row{amountoutstanding} - $diff;
+ my $tryRCR = 0;
+ my $amountoutstanding = $newout;
+ if ($amountoutstanding <0) {
+ $tryRCR = 1;
+ $amountoutstanding = 0;
+ }
if ($$row{description} =~ /max overdue/i) {
$$row{description} =~ s/\, max overdue//i;
}
@@ -2014,12 +2018,19 @@ sub _FixAccountOverdues {
WHERE borrowernumber = ?
AND accountno = ?",undef,
$amount,
- $newout,
+ $amountoutstanding,
$desc,
$$issue{borrowernumber},
$$row{accountno}
);
- _rcrFine($issue,$row,$newout);
+ ##general case _rcrFine($issue,$row,$newout) doesn't apply
+ RCR: {
+ last RCR unless $tryRCR;
+ my $paid = $$row{amount}-$$row{amountoutstanding};
+ my $owed = -1*($paid-$amount) if ($paid > $amount);
+ last RCR unless $owed;
+ _rcrFine($issue,$row,$owed,1);
+ }
}
else { # new amount is greater than previous
C4::Overdues::UpdateFine(
@@ -2205,7 +2216,7 @@ sub _getnextaccountno
# RCR refund owed (not yet issued) for prior payment on overdue charges
sub _rcrFine
{
- my($iss,$acc,$newoutstanding) = @_;
+ my($iss,$acc,$newoutstanding,$amountIsOwed) = @_;
return if $$acc{description} !~ /paid at no\.\d+/;
## the paid amount is amount-amountoutstanding
@@ -2215,9 +2226,12 @@ sub _rcrFine
## amountoutstanding $4.00 $2.00
## new overdue $3.50 $4.00
## refund owed $0 $1.00 if paid>newamountoutstanding
- my $paid = $$acc{amount} - $$acc{amountoutstanding};
- my $owed = -1*($paid - $newoutstanding);
- return unless ($paid > $newoutstanding);
+ my $paid = my $owed = 0;
+ if (!$amountIsOwed) {
+ $paid = $$acc{amount} - $$acc{amountoutstanding};
+ $owed = -1*($paid - $newoutstanding);
+ return unless ($paid > $newoutstanding);
+ }
my $dbh = C4::Context->dbh;
## already have an RCR accountline
@@ -2232,22 +2246,27 @@ sub _rcrFine
if (my $dat = $sth->fetchrow_hashref()) {
##... doing this would never happen, since you can't checkin
## item twice for same due date
- if ($$dat{amount} != $owed) {
- ## update previous RCR amount owed to patron
+ my $setamount = 0;
+ if ($amountIsOwed) {
+ $setamount = $$dat{amount}+$newoutstanding;
+ }
+ elsif ($$dat{amount} != $owed) {
+ $setamount = $$dat{amount}+$owed;
+ }
+ if ($setamount) {
$dbh->do("UPDATE accountlines
- SET amount = ?
- WHERE accountno = ?
- AND borrowernumber = ?",undef,
- $owed, $$dat{accountno}, $$iss{borrowernumber}
- );
- return;
+ SET amount = ?, amountoutstanding = ?
+ WHERE accountno = ?
+ AND borrowernumber = ?",undef,
+ $setamount,$setamount,$$dat{accountno},$$iss{borrowernumber});
} # else the refund amount is unchanged
return;
}
## else typical case: insert new RCR for refund owed
## avoid circular dependency by doing this here instead of in Accounts.pm
- my($nextnum) = _getnextaccountno($$iss{borrowernumber});
+ my($nextnum) = _getnextaccountno($$iss{borrowernumber});
+ my $setamount = $amountIsOwed? $newoutstanding : $owed;
$dbh->do("INSERT INTO accountlines (
date,
accountno,
@@ -2262,8 +2281,8 @@ sub _rcrFine
$$iss{borrowernumber},
$$iss{itemnumber},
"Refund owed at no.$$acc{accountno} for payment on overdue charges",
- $owed,
- $owed
+ $setamount,
+ $setamount
);
return;
}
View
@@ -639,27 +639,29 @@ to another.
=cut
sub ModItemTransfer {
- my ( $itemnumber, $frombranch, $tobranch ) = @_;
+ my ( $itemnumber, $frombranch, $tobranch, $currbranch ) = @_;
my $dbh = C4::Context->dbh;
if(!$frombranch && !$tobranch) {
$dbh->do('DELETE FROM branchtransfers WHERE itemnumber=?',undef,$itemnumber);
return;
}
+ my $datearrived = ($currbranch ~~ $tobranch)? 'NOW()' : 'NULL';
my $sth = $dbh->prepare('SELECT 1 FROM branchtransfers WHERE itemnumber = ?');
$sth->execute($itemnumber);
if ($sth->fetchrow_array) {
- $sth = $dbh->prepare('UPDATE branchtransfers
+ $sth = $dbh->prepare("UPDATE branchtransfers
SET frombranch = ?,
tobranch = ?,
- datesent = NOW()
- WHERE itemnumber = ?');
+ datesent = NOW(),
+ datearrived = $datearrived
+ WHERE itemnumber = ?");
$sth->execute($frombranch,$tobranch,$itemnumber);
}
else {
$sth = $dbh->prepare(
- "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch)
- VALUES (?, ?, NOW(), ?)");
+ "INSERT INTO branchtransfers (itemnumber, frombranch, datesent, tobranch, datearrived)
+ VALUES (?, ?, NOW(),?,$datearrived)");
$sth->execute($itemnumber, $frombranch, $tobranch);
}
ModItem({ holdingbranch => $tobranch }, undef, $itemnumber);
View
@@ -235,7 +235,7 @@ =head1 returns.pl
# An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
my $transferitem = $query->param('transferitem');
my $tobranch = $query->param('tobranch');
- C4::Items::ModItemTransfer($transferitem, $userenv_branch, $tobranch);
+ C4::Items::ModItemTransfer($transferitem, $userenv_branch, $tobranch, $userenv_branch);
}
elsif ($query->param('cancelTransfer')) {
C4::Items::ModItemTransfer($query->param('itemnumber'));
@@ -521,7 +521,7 @@ =head1 returns.pl
# $err{reserve} = 1;
foreach(keys %{$$messages{$code}}) { $template->param("res_$_"=>$$messages{$code}{$_}) }
$template->param(
- currBranch => C4::Context->userenv->{branch},
+ currBranch => $userenv_branch,
pickbranchname => $$branches{$$messages{$code}{branchcode}}{branchname},
);
}
Oops, something went wrong.

0 comments on commit 09804e6

Please sign in to comment.