Members.pm - checkuniquemember minor refactor and perldoc correction.
[koha.git] / catalogue / updateitem.pl
blobcdd8d464f869b7492352f52f15a439bc81bfbd0d
1 #!/usr/bin/perl
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
11 # version.
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;
21 use CGI;
22 use C4::Context;
23 use C4::Biblio;
24 use C4::Output;
25 use C4::Circulation;
26 use C4::Accounts;
27 use C4::Reserves;
29 my $cgi= new CGI;
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 $itemnotes=$cgi->param('itemnotes');
36 my $wthdrawn=$cgi->param('wthdrawn');
37 my $damaged=$cgi->param('damaged');
39 my $confirm=$cgi->param('confirm');
40 my $dbh = C4::Context->dbh;
41 # get the rest of this item's information
42 my $item_data_hashref = GetItem($itemnumber, undef);
43 my $newitemdata;
44 # modify MARC item if input differs from items table.
45 if ( $itemnotes ne $item_data_hashref->{'itemnotes'}) {
46 ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemnotes', $itemnotes);
47 $newitemdata->{'itemnotes'} = $itemnotes;
48 } elsif ($itemlost ne $item_data_hashref->{'itemlost'}) {
49 ModItemInMarconefield($biblionumber, $itemnumber, 'items.itemlost', $itemlost);
50 $newitemdata->{'itemlost'} = $itemlost;
51 } elsif ($wthdrawn ne $item_data_hashref->{'wthdrawn'}) {
52 ModItemInMarconefield($biblionumber, $itemnumber, 'items.wthdrawn', $wthdrawn);
53 $newitemdata->{'wthdrawn'} = $wthdrawn;
54 } elsif ($damaged ne $item_data_hashref->{'damaged'}) {
55 ModItemInMarconefield($biblionumber, $itemnumber, 'items.damaged', $damaged);
56 $newitemdata->{'damaged'} = $damaged;
57 } else {
58 #nothings changed, so do nothing.
59 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");
62 # FIXME: eventually we'll use Biblio.pm, but it's currently too buggy (is this current ??)
63 #ModItem( $dbh,'',$biblionumber,$itemnumber,'',$item_hashref );
64 $newitemdata->{'itemnumber'} = $itemnumber;
65 # &C4::Biblio::_koha_modify_item($dbh,$newitemdata);
67 my $sth = $dbh->prepare("UPDATE items SET wthdrawn=?,itemlost=?,damaged=?,itemnotes=? WHERE itemnumber=?");
68 $sth->execute($wthdrawn,$itemlost,$damaged,$itemnotes,$itemnumber);
69 &ModZebra($biblionumber,"specialUpdate","biblioserver");
71 # check issues iff itemlost.
72 # FIXME : is there documentation or enforcement that itemlost value must be '1'? if no replacement price, then borrower just doesn't get charged?
73 if ($itemlost==1) {
74 my $sth=$dbh->prepare("SELECT * FROM issues WHERE (itemnumber=? AND returndate IS NULL)");
75 $sth->execute($itemnumber);
76 my $issues=$sth->fetchrow_hashref();
78 # if a borrower lost the item, add a replacement cost to the their record
79 if ( ($issues->{borrowernumber}) && ($itemlost==1) ){
81 # first make sure the borrower hasn't already been charged for this item
82 my $sth1=$dbh->prepare("SELECT * from accountlines
83 WHERE borrowernumber=? AND itemnumber=?");
84 $sth1->execute($issues->{'borrowernumber'},$itemnumber);
85 my $existing_charge_hashref=$sth1->fetchrow_hashref();
87 # OK, they haven't
88 unless ($existing_charge_hashref) {
89 # This item is on issue ... add replacement cost to the borrower's record and mark it returned
90 my $accountno = getnextacctno('',$issues->{'borrowernumber'},$dbh);
91 my $sth2=$dbh->prepare("INSERT INTO accountlines
92 (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
93 VALUES
94 (?,?,now(),?,?,'L',?,?)");
95 $sth2->execute($issues->{'borrowernumber'},$accountno,$item_data_hashref->{'replacementprice'},
96 "Lost Item $item_data_hashref->{'title'} $item_data_hashref->{'barcode'}",
97 $item_data_hashref->{'replacementprice'},$itemnumber);
98 $sth2->finish;
99 # FIXME: Log this ?
102 $sth->finish;
105 print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber");