Skip to content
Browse files

[fixes #15483899] longoverdue script needs to honor syspref MarkLostI…

…temsReturned
  • Loading branch information...
1 parent 614ebc6 commit 1da8fd63e68206ed2467e2e3e4995568dd8f7760 @hgq hgq committed Jul 15, 2011
Showing with 51 additions and 19 deletions.
  1. +10 −8 C4/Circulation.pm
  2. +3 −0 C4/Items.pm
  3. +5 −1 C4/LostItems.pm
  4. +4 −2 C4/Members.pm
  5. +7 −0 installer/data/mysql/updatedatabase.pl
  6. +22 −8 misc/cronjobs/longoverdue.pl
View
18 C4/Circulation.pm
@@ -1530,7 +1530,7 @@ sub AddReturn {
my $validTransfert = 0;
# get information on item
- my $itemnumber = GetItemnumberFromBarcode( $barcode );
+ my $itemnumber = C4::Items::GetItemnumberFromBarcode( $barcode );
unless ($itemnumber) {
return (0, { BadBarcode => $barcode }); # no barcode means no item or borrower. bail out.
}
@@ -1574,7 +1574,7 @@ sub AddReturn {
$doreturn = 0;
}
}
- my $item = GetItem($itemnumber) or die "GetItem($itemnumber) failed";
+ my $item = C4::Items::GetItem($itemnumber) or die "GetItem($itemnumber) failed";
# full item data, but no borrowernumber or checkout info (no issue)
# we know GetItem should work because GetItemnumberFromBarcode worked
my $hbr = $item->{C4::Context->preference("HomeOrHoldingBranch")} || '';
@@ -1615,8 +1615,8 @@ sub AddReturn {
# Set items.otherstatus back to NULL on check in regardless of whether the
# item was actually checked out.
- ModItem({ otherstatus => undef }, $item->{'biblionumber'}, $item->{'itemnumber'});
- ModItem({ onloan => undef }, $item->{'biblionumber'}, $item->{'itemnumber'});
+ C4::Items::ModItem({ otherstatus => undef }, $item->{'biblionumber'}, $item->{'itemnumber'});
+ C4::Items::ModItem({ onloan => undef }, $item->{'biblionumber'}, $item->{'itemnumber'});
# case of a return of document (deal with issues and holdingbranch)
if ($doreturn) {
@@ -1626,7 +1626,7 @@ sub AddReturn {
# define circControlBranch only if dropbox mode is set
# don't allow dropbox mode to create an invalid entry in issues (issuedate > today)
# FIXME: check issuedate > returndate, factoring in holidays
- $circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $item->{'issuedate'} eq C4::Dates->today('iso') );;
+ $circControlBranch = _GetCircControlBranch($item,$borrower) unless ( $issue->{'issuedate'} eq C4::Dates->today('iso') );;
}
if ($borrowernumber) {
@@ -1646,7 +1646,7 @@ sub AddReturn {
UpdateHoldingbranch($branch, $item->{'itemnumber'});
$item->{'holdingbranch'} = $branch; # update item data holdingbranch too
}
- ModDateLastSeen( $item->{'itemnumber'} );
+ C4::Items::ModDateLastSeen( $item->{'itemnumber'} );
# check if we have a transfer for this document
my ($datesent,$frombranch,$tobranch) = GetTransfers( $item->{'itemnumber'} );
@@ -1924,7 +1924,7 @@ sub _FixAccountOverdues {
## fines.pl cron isn't running?
if(!$row && $$issue{overdue}) { ## is overdue, not yet charged
my($amount,$type,$daycounttotal,$daycount,$ismax) = C4::Overdues::CalcFine(
- GetItem($$issue{itemnumber}),
+ C4::Items::GetItem($$issue{itemnumber}),
$$flags{borcatcode},
$$flags{branch},
undef,undef,
@@ -2096,7 +2096,9 @@ sub _FixAccountNowFound
);
}
elsif ($tolost) {
- $by .= sprintf('staff (-%s)',C4::Context->userenv->{id});
+ my $userid = 'cron';
+ if (my $userenv = C4::Context->userenv) { $userid = $userenv->{id} }
+ $by .= sprintf('staff (-%s)',$userid);
}
elsif ( ($co ~~ 'renewal') ||
($issuebor && ($issuebor == $$lost{borrowernumber}))
View
3 C4/Items.pm
@@ -2215,6 +2215,9 @@ sub _koha_modify_item {
my $error;
my $query = "UPDATE items SET ";
my @bind;
+ $$item{notforloan} //= 0;
+ $$item{suppress} //= 0;
+ $$item{wthdrawn} //= 0;
if (($$item{notforloan} != 0)
|| ($$item{suppress} != 0)
|| ($$item{wthdrawn} != 0) ) {
View
6 C4/LostItems.pm
@@ -105,9 +105,13 @@ sub CreateLostItem {
my $date_lost = C4::Dates->new()->output('iso');
# Get the item and biblio data
- my $sth = $dbh->prepare("SELECT * FROM items LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber WHERE itemnumber=?");
+ my $sth = $dbh->prepare("
+ SELECT items.*,biblioitems.itemtype FROM items,biblioitems
+ WHERE items.itemnumber=?
+ AND items.biblioitemnumber=biblioitems.biblioitemnumber");
$sth->execute($itemnumber);
my $item = $sth->fetchrow_hashref;
+ $$item{itype} //= $$item{itemtype};
## dupecheck: an item-borrower pair can only be lost once per borrower
$sth = $dbh->prepare('SELECT id FROM lost_items
View
6 C4/Members.pm
@@ -539,8 +539,10 @@ sub patronflags {
foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
@$itemsoverdue )
{
- $flaginfo{'itemlisttext'} .=
- "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n"; # newline is display layer
+ my $dd = $$_{date_due} // '';
+ my $bc = $$_{barcode} // '';
+ my $ti = $$_{title} // '';
+ $flaginfo{'itemlisttext'} .= "$dd $bc $ti \n"; # newline is display layer
}
$flags{'ODUES'} = \%flaginfo;
}
View
7 installer/data/mysql/updatedatabase.pl
@@ -4681,6 +4681,13 @@
print "Upgrade to $DBversion done ( Modified systempreferences.reservesNeedConfirmationOnCheckout )\n";
}
+$DBversion = '4.08.00.001';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ SetVersion ($DBversion);
+ $dbh->do('ALTER TABLE lost_items change itemtype itemtype varchar(10) NULL');
+ print "Upgrade to $DBversion done ( Allow lost_items.itemtype to be nullable )\n";
+}
+
printf "Database schema now up to date at version %s as of %s.\n", $DBversion, scalar localtime;
=item DropAllForeignKeys($table)
View
30 misc/cronjobs/longoverdue.pl
@@ -38,6 +38,7 @@ BEGIN
use C4::Items;
use C4::LostItems;
use C4::Accounts;
+use C4::Circulation;
use Getopt::Long;
my $lost; # key=lost value, value=num days.
@@ -63,7 +64,9 @@ BEGIN
where n is num days overdue, and lv is the lost value. See warning below.
--charge | -c This specifies what lost value triggers Koha to charge the account for the
- lost item. Replacement costs are not charged if this is not specified.
+ lost item. Replacement costs are not charged if this is not specified. Normally,
+ the 'Lost+Charge' authorized value of the LOST category has a value of 1, so set this
+ to 1.
--verbose | v verbose.
@@ -118,13 +121,13 @@ ($)
# FIXME - This sql should be inside the API.
sub longoverdue_sth {
my $query = "
- SELECT items.itemnumber, borrowernumber, date_due
+ SELECT issues.*,items.barcode,items.holdingbranch
FROM issues, items
WHERE items.itemnumber = issues.itemnumber
- AND DATE_SUB(CURDATE(), INTERVAL ? DAY) > date_due
- AND DATE_SUB(CURDATE(), INTERVAL ? DAY) <= date_due
- AND itemlost <> ?
- ORDER BY date_due
+ AND DATE_SUB(CURDATE(), INTERVAL ? DAY) > issues.date_due
+ AND DATE_SUB(CURDATE(), INTERVAL ? DAY) <= issues.date_due
+ AND items.itemlost <> ?
+ ORDER BY issues.date_due
";
return C4::Context->dbh->prepare($query);
}
@@ -155,9 +158,20 @@ sub longoverdue_sth {
while (my $row=$sth_items->fetchrow_hashref) {
printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
if($confirm) {
- ModItemLost($row->{'biblionumber'}, $row->{'itemnumber'}, $lostvalue);
- C4::Accounts::chargelostitem($row->{'itemnumber'}) if( $charge && $charge eq $lostvalue);
C4::LostItems::CreateLostItem($row->{'itemnumber'}, $row->{'borrowernumber'});
+ C4::Accounts::chargelostitem($row->{'itemnumber'}) if( $charge && $charge eq $lostvalue);
+ ## honor syspref
+ if (C4::Context->preference('MarkLostItemsReturned')) {
+ C4::Circulation::AddReturn(
+ $$row{barcode},
+ $$row{holdingbranch}, # assume returned to where last checked out
+ 0, # exemptfine
+ 0, # dropbox
+ undef, # returndate: will default to today
+ 1, # tolost
+ );
+ }
+ ModItemLost($row->{'biblionumber'}, $row->{'itemnumber'}, $lostvalue);
}
$count++;
}

0 comments on commit 1da8fd6

Please sign in to comment.
Something went wrong with that request. Please try again.