3 #script to add a new item and to mark orders as received
4 #written 1/3/00 by chris@katipo.co.nz
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
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
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.
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
23 # this script makes the items, addorder.pl has already made the biblio and biblioitem records: MASON
31 use C4::Circulation::Circ2;
33 use C4::Interface::CGI::Output;
40 my $dbh = C4::Context->dbh;
42 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44 template_name => "acqui/finishreceive.tmpl",
48 flagsrequired => { editcatalogue => 1 },
53 my $user = $input->remote_user;
54 my $biblionumber = $input->param('biblio');
55 my $biblioitemnumber = $input->param('biblioitemnum');
56 my $ordnum = $input->param('ordnum');
57 my $cost = $input->param('cost');
58 my $invoiceno = $input->param('invoice');
59 my $replacement = $input->param('rrp');
60 my $gst = $input->param('gst');
61 my $freight = $input->param('freight');
62 my $freightperitem = $input->param('freightperitem');
63 my $supplierid = $input->param('supplierid');
64 my $title = $input->param('title');
65 my $author = $input->param('author');
66 my $copyrightdate = $input->param('copyrightdate');
67 my $itemtype = $input->param('format');
68 my $isbn = $input->param('ISBN');
69 my $seriestitle = $input->param('series');
70 my $branch = $input->param('branch');
71 my $holdingbranch = $branch;
72 my $barcode = $input->param('barcode');
73 my $bookfund = $input->param('bookfund');
74 my $quantity = $input->param('quantity');
75 my $quantrec = $input->param('quantityrec');
76 my $ecost = $input->param('ecost');
77 my $unitprice = $input->param('unitprice');
78 my $notes = $input->param('notes');
79 my $booksellers = $input->param('booksellers');
80 my $foo = $input->param('foo');
81 my $volinf = $input->param('volinf');
82 my $catview = $input->param('catview'); # for editing from moredetail.tmpl
83 my $barcodeexists = $input->param('barcodeexists'); # if barcode exists
84 my $newitemfailed = $input->param('newitemfailed'); # if create new item failed
86 $input->param('createbibitem'); # user wants to create a new bibitem
88 #get additional info on bib and bibitem from dbase for additional needed fields before modbiblio.
89 ( my $bibliocount, my @biblios ) = &getbiblio($biblionumber);
90 ( my $biblioitemcount, my @biblioitems ) =
91 &getbiblioitembybiblionumber($biblionumber);
92 ( my $itemscount, my @items ) = &getitemsbybiblioitem($biblioitemnumber);
95 biblionumber => $biblionumber,
98 abstract => $biblios[0]->{'abstract'},
99 copyrightdate => $copyrightdate,
100 seriestitle => $seriestitle,
101 serial => $biblios[0]->{'serial'},
102 unititle => $biblios[0]->{'unititle'},
103 notes => $biblios[0]->{'notes'}
106 my $biblioitemhash = {
107 illus => $biblioitems[0]->{'illus'},
108 number => $biblioitems[0]->{'number'},
109 itemtype => $itemtype,
110 place => $biblioitems[0]->{'place'},
111 biblioitemnumber => $biblioitemnumber,
112 issn => $biblioitems[0]->{'issn'},
113 size => $biblioitems[0]->{'size'},
114 marc => $biblioitems[0]->{'marc'},
115 timestamp => $biblioitems[0]->{'timestamp'},
116 biblionumber => $biblionumber,
117 url => $biblioitems[0]->{'url'},
118 dewey => $biblioitems[0]->{'dewey'},
120 publishercode => $biblioitems[0]->{'publishercode'},
121 lccn => $biblioitems[0]->{'iccn'},
122 volume => $biblioitems[0]->{'volume'},
123 subclass => $biblioitems[0]->{'subclass'},
124 notes => $biblioitems[0]->{'notes'},
125 classification => $biblioitems[0]->{'classification'},
126 volumeddesc => $volinf,
127 publicationyear => $biblioitems[0]->{'publicationyear'},
128 volumedate => $biblioitems[0]->{'volumedate'},
129 pages => $biblioitems[0]->{'pages'}
133 biblionumber => $biblionumber,
134 itemnum => $items[0]->{'itemnumber'},
136 notes => $items[0]->{'notes'},
137 itemcallnumber => $items[0]->{'itemcallnumber'},
138 notforloan => $items[0]->{'notforloan'},
139 location => $items[0]->{'location'},
140 bibitemnum => $biblioitemnumber,
141 homebranch => $items[0]->{'homebranch'},
142 lost => $items[0]->{'itemlost'},
143 withdrawn => $items[0]->{'withdrawn'},
144 holdingbranch => $items[0]->{'holdingbranch'},
145 replacement => $replacement
148 # check if barcode exists, if so redirect back to acquire.pl and give message
149 my $error = &checkitems( 1, $barcode );
150 #warn "barcode check for $barcode result = $error";
152 print $input->redirect(
153 "/cgi-bin/koha/acqui/acquire.pl?recieve=$ordnum&biblio=$biblionumber&invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&barcodeexists=$barcode"
156 # or if barcode is blank
159 if ( $createbibitem eq "YES" ) {
160 &modbiblio($bibliohash);
161 $biblioitemnumber = &newbiblioitem($biblioitemhash);
163 #lets do a lookup on aqorders, with ordnum, then insert biblioitem fiels with new biblioitem number
166 "UPDATE aqorders SET biblioitemnumber = ? where ordernumber = ?
167 and biblionumber = ?";
168 my $sth = $dbh->prepare($query);
169 my $error = $sth->execute( $biblioitemnumber, $ordnum, $biblionumber );
171 $sth->fetchrow_hashref;
175 &modbiblio($bibliohash);
176 &modbibitem($biblioitemhash);
181 print $input->redirect(
182 "/cgi-bin/koha/moredetail.pl?type=$itemtype&bib=$biblionumber&bi=$biblioitemnumber"
186 if ( $quantity != 0 ) {
187 # save the quantity recieved.
188 receiveorder( $biblionumber, $ordnum, $quantrec, $user, $cost,
189 $invoiceno, $freightperitem, $bookfund, $replacement );
191 # create items if the user has entered barcodes
192 my @barcodes = split( /\,| |\|/, $barcode ); #WTF?
194 my ($error) = newitems(
196 biblioitemnumber => $biblioitemnumber,
197 biblionumber => $biblionumber,
198 replacementprice => $replacement,
200 booksellerid => $supplierid,
201 homebranch => $branch,
208 { #if newitems failes then display error, and send them back to acquire.pl????
210 print $input->redirect(
211 "/cgi-bin/koha/acqui/acquire.pl?recieve=$ordnum&biblio=$biblionumber&invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&newitemfailed=1"
215 elsif ( $itemtype ne 'P' && $itemtype ne 'PP' ) { # chris's new if bit
217 my $item = getiteminformation( \%env, 0, $barcode );
218 my ( $resfound, $resrec ) = CheckReserves( 0, $barcode );
220 if ($resfound) { # reserves is found
222 getpatroninformation( \%env, $resrec->{'borrowernumber'}, 0 );
224 borrowernumber => $borrower->{'borrowernumber'},
225 cardnumber => $borrower->{'cardnumber'},
226 firstname => $borrower->{'firstname'},
227 surname => $borrower->{'surname'},
228 invoice => $invoiceno,
234 biblionumber => $biblionumber,
238 output_html_with_http_headers $input, $cookie,
241 else { #no reserves found
243 s/\&/\%26/g; # swapping pesky & with url friendly hex codes.
244 print $input->redirect(
245 "/cgi-bin/koha/acqui/receive.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&quantity=$quantity"
250 print $input->redirect(
251 "/cgi-bin/koha/loadmodules.pl?module=acquisitions")
257 # print $input->header;
258 delorder( $biblionumber, $ordnum );
259 print $input->redirect("/acquisitions/");