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
32 my $biblionumber=$cgi->param('biblionumber');
33 my $itemnumber=$cgi->param('itemnumber');
34 my $biblioitemnumber=$cgi->param('biblioitemnumber');
35 my $itemlost=$cgi->param('itemlost');
36 my $itemnotes=$cgi->param('itemnotes');
37 my $wthdrawn=$cgi->param('wthdrawn');
38 my $damaged=$cgi->param('damaged');
40 my $confirm=$cgi->param('confirm');
41 my $dbh = C4::Context->dbh;
42 # get the rest of this item's information
43 my $item_data_hashref = GetItem($itemnumber, undef);
45 # modify MARC item if input differs from items table.
46 if ( $itemnotes ne $item_data_hashref->{'itemnotes'}) {
47 ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemnotes', $itemnotes);
48 $newitemdata->{'itemnotes'} = $itemnotes;
49 } elsif ($itemlost ne $item_data_hashref->{'itemlost'}) {
50 ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemlost', $itemlost);
51 $newitemdata->{'itemlost'} = $itemlost;
52 } elsif ($wthdrawn ne $item_data_hashref->{'wthdrawn'}) {
53 ModItemInMarconefield($biblionumber, $itemnumber, 'items.wthdrawn', $wthdrawn);
54 $newitemdata->{'wthdrawn'} = $wthdrawn;
55 } elsif ($damaged ne $item_data_hashref->{'damaged'}) {
56 ModItemInMarconefield($biblionumber, $itemnumber, 'items.damaged', $damaged);
57 $newitemdata->{'damaged'} = $damaged;
59 #nothings changed, so do nothing.
60 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");
63 # FIXME: eventually we'll use Biblio.pm, but it's currently too buggy (is this current ??)
64 #ModItem( $dbh,'',$biblionumber,$itemnumber,'',$item_hashref );
65 $newitemdata->{'itemnumber'} = $itemnumber;
66 # &C4::Biblio::_koha_modify_item($dbh,$newitemdata);
68 my $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=?,itemnotes=? WHERE itemnumber=?");
69 $sth->execute($wthdrawn,$itemlost,$damaged,$itemnotes,$itemnumber);
70 &ModZebra($biblionumber,"specialUpdate","biblioserver");
72 # check issues iff itemlost.
73 # FIXME : is there documentation or enforcement that itemlost value must be '1'? if no replacement price, then borrower just doesn't get charged?
75 my $sth=$dbh->prepare("SELECT * FROM issues WHERE (itemnumber=? AND returndate IS NULL)");
76 $sth->execute($itemnumber);
77 my $issues=$sth->fetchrow_hashref();
79 # if a borrower lost the item, add a replacement cost to the their record
80 if ( ($issues->{borrowernumber}) && ($itemlost==1) ){
82 # first make sure the borrower hasn't already been charged for this item
83 my $sth1=$dbh->prepare("SELECT * from accountlines
84 WHERE borrowernumber=? AND itemnumber=?");
85 $sth1->execute($issues->{'borrowernumber'},$itemnumber);
86 my $existing_charge_hashref=$sth1->fetchrow_hashref();
89 unless ($existing_charge_hashref) {
90 # This item is on issue ... add replacement cost to the borrower's record and mark it returned
91 my $accountno = getnextacctno('',$issues->{'borrowernumber'},$dbh);
92 my $sth2=$dbh->prepare("INSERT INTO accountlines
93 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
95 (?,?,now(),?,?,'L',?,?)");
96 $sth2->execute($issues->{'borrowernumber'},$accountno,$item_data_hashref->{'replacementprice'},
97 "Lost Item $item_data_hashref->{'title'} $item_data_hashref->{'barcode'}",
98 $item_data_hashref->{'replacementprice'},$itemnumber);
106 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");