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
33 my $biblionumber=$cgi->param('biblionumber');
34 my $itemnumber=$cgi->param('itemnumber');
35 my $biblioitemnumber=$cgi->param('biblioitemnumber');
36 my $itemlost=$cgi->param('itemlost');
37 my $itemnotes=$cgi->param('itemnotes');
38 my $wthdrawn=$cgi->param('wthdrawn');
39 my $damaged=$cgi->param('damaged');
41 my $confirm=$cgi->param('confirm');
42 my $dbh = C4::Context->dbh;
44 # get the rest of this item's information
45 my $item_data_hashref = GetItem($itemnumber, undef);
47 # make sure item statuses are set to 0 if empty or NULL
48 for ($damaged,$itemlost,$wthdrawn) {
49 if (!$_ or $_ eq "") {
54 # modify MARC item if input differs from items table.
55 my $item_changes = {};
56 if (defined $itemnotes) { # i.e., itemnotes parameter passed from form
57 if ((not defined $item_data_hashref->{'itemnotes'}) or $itemnotes ne $item_data_hashref->{'itemnotes'}) {
58 $item_changes->{'itemnotes'} = $itemnotes;
60 } elsif ($itemlost ne $item_data_hashref->{'itemlost'}) {
61 $item_changes->{'itemlost'} = $itemlost;
62 } elsif ($wthdrawn ne $item_data_hashref->{'wthdrawn'}) {
63 $item_changes->{'wthdrawn'} = $wthdrawn;
64 } elsif ($damaged ne $item_data_hashref->{'damaged'}) {
65 $item_changes->{'damaged'} = $damaged;
67 #nothings changed, so do nothing.
68 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");
72 ModItem($item_changes, $biblionumber, $itemnumber);
74 # check issues iff itemlost.
75 # http://wiki.koha.org/doku.php?id=en:development:kohastatuses
76 # lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
77 # FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
78 # a charge has been added
79 # FIXME : if no replacement price, borrower just doesn't get charged?
81 my $sth=$dbh->prepare("SELECT * FROM issues WHERE (itemnumber=? AND returndate IS NULL)");
82 $sth->execute($itemnumber);
83 my $issues=$sth->fetchrow_hashref();
85 # if a borrower lost the item, add a replacement cost to the their record
86 if ( ($issues->{borrowernumber}) && ($itemlost==1) ){
88 # first make sure the borrower hasn't already been charged for this item
89 my $sth1=$dbh->prepare("SELECT * from accountlines
90 WHERE borrowernumber=? AND itemnumber=?");
91 $sth1->execute($issues->{'borrowernumber'},$itemnumber);
92 my $existing_charge_hashref=$sth1->fetchrow_hashref();
95 unless ($existing_charge_hashref) {
96 # This item is on issue ... add replacement cost to the borrower's record and mark it returned
97 my $accountno = getnextacctno('',$issues->{'borrowernumber'},$dbh);
98 my $sth2=$dbh->prepare("INSERT INTO accountlines
99 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
101 (?,?,now(),?,?,'L',?,?)");
102 $sth2->execute($issues->{'borrowernumber'},$accountno,$item_data_hashref->{'replacementprice'},
103 "Lost Item $item_data_hashref->{'title'} $item_data_hashref->{'barcode'}",
104 $item_data_hashref->{'replacementprice'},$itemnumber);
112 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");