A basic search script catalogue-search.pl demonstrates the use of koha_attr table...
[koha.git] / catalogue / moredetail.pl
1 #!/usr/bin/perl
2 # NOTE: Use standard 8-space tabs for this file (indents are 4 spaces)
3
4 # $Id$
5
6 # Copyright 2000-2003 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 require Exporter;
25 use C4::Koha;
26 use CGI;
27 use C4::Search;
28 use C4::Acquisition;
29 use C4::Output; # contains gettemplate
30 use C4::Auth;
31 use C4::Interface::CGI::Output;
32 use C4::Date;
33 use C4::Context;
34 use C4::Biblio;
35 use C4::Accounts2;
36 use C4::Circulation::Circ2;
37 use MARC::Record;
38 my $dbh=C4::Context->dbh;
39 my $query=new CGI;
40
41
42 my ($template, $loggedinuser, $cookie) = get_template_and_user({
43         template_name   => ( 'catalogue/moredetail.tmpl'),
44         query           => $query,
45         type            => "intranet",
46         authnotrequired => 0,
47         flagsrequired   => {catalogue => 1},
48     });
49
50 # get variables
51 my $op=$query->param('op');
52 my $lost=$query->param('lost');
53 my $withdrawn=$query->param('withdrawn');
54 my $override=$query->param('override');
55 my $itemnumber=$query->param('itemnumber');
56 my $barcode=$query->param('barcode');
57
58 my $title=$query->param('title');
59 my $biblionumber=$query->param('biblionumber');
60 my ($record,)=MARCgetbiblio($dbh,$biblionumber);
61 my $data=MARCmarc2koha($dbh,$record,"biblios");
62 my $dewey = $data->{'dewey'};
63 # FIXME Dewey is a string, not a number, & we should use a function
64 $dewey =~ s/0+$//;
65 if ($dewey eq "000.") { $dewey = "";};
66 if ($dewey < 10){$dewey='00'.$dewey;}
67 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
68 if ($dewey <= 0){
69       $dewey='';
70 }
71 $dewey=~ s/\.$//;
72 $data->{'dewey'}=$dewey;
73
74 my @results;
75
76 my @items;
77 if ($op eq "update"){
78 my $env;
79 ##Do Lost or Withdraw here
80 my $flag=0;
81   my ($resbor,$resrec)=C4::Reserves2::CheckReserves($env,$dbh,$itemnumber);
82 if ($override ne "yes"){
83   if ($resbor){
84 #    print $query->header;
85     $template->param(error => "This item   has a reserve on it");
86  $template->param(biblionumber =>$biblionumber);
87  $template->param(itemnumber =>$itemnumber);
88  $template->param(lost =>$lost);
89  $template->param(withdrawn =>$withdrawn);
90     $flag=1;
91   }
92   my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
93   $sth->execute($itemnumber);
94  
95   if (my $data=$sth->fetchrow_hashref) {
96    $template->param(biblionumber =>$biblionumber);
97  $template->param(itemnumber =>$itemnumber);
98  $template->param(error => "This item   is On Loan to a member");
99  $template->param(lost =>$lost);
100  $template->param(withdrawn =>$withdrawn);
101     $flag=2;
102   }
103 }
104 if ($flag != 0 && $override ne "yes"){
105
106   }else {
107    ##UPDATE here
108 my $sth=$dbh->prepare("update items set itemlost=? ,wthdrawn=? where itemnumber=?");
109 $sth->execute($lost,$withdrawn,$itemnumber);
110 $sth->finish;
111 MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'wthdrawn',$withdrawn,1);
112 MARCmoditemonefield($dbh,$biblionumber,$itemnumber,'itemlost',$lost);
113
114      if ($lost ==1 && $flag ==2){
115     my $sth=$dbh->prepare("Select * from issues where (itemnumber=?) and (returndate is null)");
116     $sth->execute($itemnumber);
117     my $data=$sth->fetchrow_hashref;
118     if ($data->{'borrowernumber'} ne '') {
119       #item on issue add replacement cost to borrowers record
120       my $accountno=getnextacctno($env,$data->{'borrowernumber'},$dbh);
121       my $item=getiteminformation($env, $itemnumber);
122       my $sth2=$dbh->prepare("Insert into accountlines
123       (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
124       values
125       (?,?,now(),?,?,'L',?,?)");
126       $sth2->execute($data->{'borrowernumber'},$accountno,$item->{'replacementprice'},
127       "Lost Item $item->{'title'} $item->{'barcode'}",
128       $item->{'replacementprice'},$itemnumber);
129       $sth2->finish;
130     }
131     }
132         if ($flag==1){
133         foreach my $res ($resrec){
134         C4::Reserves2::CancelReseve(undef,$res->{itemnumber},$res->{borrowernumber});
135         }
136         }
137     
138   }
139 }
140 my @itemrecords=MARCgetallitems($dbh,$biblionumber);
141 foreach my $itemrecord (@itemrecords){
142
143 my $items = MARCmarc2koha($dbh,$itemrecord,"holdings");
144 $items->{itemtype}=$data->{itemtype};
145 $items->{biblionumber}=$biblionumber;
146 $items=itemissues($dbh,$items,$biblionumber);
147 push @items,$items;
148 }
149 my $count=@items;
150 $data->{'count'}=$count;
151 my ($order,$ordernum)=GetOrder($biblionumber,$barcode);
152
153 my $env;
154 $env->{itemcount}=1;
155
156 $results[0]=$data;
157
158 foreach my $item (@items){
159     $item->{'replacementprice'}=sprintf("%.2f", $item->{'replacementprice'});
160     $item->{'datelastborrowed'}= format_date($item->{'datelastborrowed'});
161     $item->{'dateaccessioned'} = format_date($item->{'dateaccessioned'});
162     $item->{'datelastseen'} = format_date($item->{'datelastseen'});
163     $item->{'ordernumber'} = $ordernum;
164     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
165
166     if ($item->{'date_due'} gt '0000-00-00'){
167         $item->{'date_due'} = format_date($item->{'date_due'});         
168 $item->{'issue'}= 1;
169                 $item->{'borrowernumber'} = $item->{'borrowernumber'};
170                 $item->{'cardnumber'} = $item->{'card'};
171                         
172     } else {
173         $item->{'issue'}= 0;
174     }
175 }
176
177 $template->param(BIBITEM_DATA => \@results);
178 $template->param(ITEM_DATA => \@items);
179 $template->param(loggedinuser => $loggedinuser);
180
181 output_html_with_http_headers $query, $cookie, $template->output;
182
183
184 # Local Variables:
185 # tab-width: 8
186 # End: