3 # $Id: updateitem.pl,v 1.9.2.1.2.4 2006/10/05 18:36:50 kados Exp $
4 # Copyright 2006 LibLime
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
20 use strict; use warnings;
31 my $biblionumber=$cgi->param('biblionumber');
32 my $itemnumber=$cgi->param('itemnumber');
33 my $biblioitemnumber=$cgi->param('biblioitemnumber');
34 my $itemlost=$cgi->param('itemlost');
35 my $wthdrawn=$cgi->param('wthdrawn');
36 my $damaged=$cgi->param('damaged');
38 my $confirm=$cgi->param('confirm');
39 my $dbh = C4::Context->dbh;
40 # get the rest of this item's information
41 my $item_data_hashref = GetItem($itemnumber, undef);
44 if ((not defined($item_data_hashref->{'itemlost'})) or ($itemlost ne $item_data_hashref->{'itemlost'})) {
45 ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemlost', $itemlost);
47 if ((not defined($item_data_hashref->{'wthdrawn'})) or ($wthdrawn ne $item_data_hashref->{'wthdrawn'})) {
48 ModItemInMarconefield($biblionumber, $itemnumber, 'items.wthdrawn', $wthdrawn);
50 if ((not defined($item_data_hashref->{'damaged'})) or ($damaged ne $item_data_hashref->{'damaged'})) {
51 ModItemInMarconefield($biblionumber, $itemnumber, 'items.damaged', $damaged);
55 my ($status, $reserve) = CheckReserves($itemnumber, $item_data_hashref->{'barcode'});
58 warn "Reservation found on item $itemnumber";
62 my $sth=$dbh->prepare("SELECT * FROM issues WHERE (itemnumber=? AND returndate IS NULL)");
63 $sth->execute($itemnumber);
64 my $issues=$sth->fetchrow_hashref();
66 # if a borrower lost the item, add a replacement cost to the their record
67 if ( ($issues->{borrowernumber}) && ($itemlost==1) ){
69 # first make sure the borrower hasn't already been charged for this item
70 my $sth1=$dbh->prepare("SELECT * from accountlines
71 WHERE borrowernumber=? AND itemnumber=?");
72 $sth1->execute($issues->{'borrowernumber'},$itemnumber);
73 my $existing_charge_hashref=$sth1->fetchrow_hashref();
76 unless ($existing_charge_hashref) {
77 # This item is on issue ... add replacement cost to the borrower's record and mark it returned
78 my $accountno = getnextacctno('',$issues->{'borrowernumber'},$dbh);
79 my $sth2=$dbh->prepare("INSERT INTO accountlines
80 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
82 (?,?,now(),?,?,'L',?,?)");
83 $sth2->execute($issues->{'borrowernumber'},$accountno,$item_data_hashref->{'replacementprice'},
84 "Lost Item $item_data_hashref->{'title'} $item_data_hashref->{'barcode'}",
85 $item_data_hashref->{'replacementprice'},$itemnumber);
91 # FIXME: eventually we'll use Biblio.pm, but it's currently too buggy
92 #ModItem( $dbh,'',$biblionumber,$itemnumber,'',$item_hashref );
93 $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=? WHERE itemnumber=?");
94 $sth->execute($wthdrawn,$itemlost,$damaged,$itemnumber);
96 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");