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
49 use C4::Circulation::Circ2;
51 use C4::Interface::CGI::Output;
58 my $dbh = C4::Context->dbh;
60 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
62 template_name => "acqui/finishreceive.tmpl",
66 flagsrequired => { editcatalogue => 1 },
71 my $user = $input->remote_user;
72 my $biblionumber = $input->param('biblio');
73 my $biblioitemnumber = $input->param('biblioitemnum');
74 my $ordnum = $input->param('ordnum');
75 my $cost = $input->param('cost');
76 my $invoiceno = $input->param('invoice');
77 my $replacement = $input->param('rrp');
78 my $gst = $input->param('gst');
79 my $freight = $input->param('freight');
80 my $freightperitem = $input->param('freightperitem');
81 my $supplierid = $input->param('supplierid');
82 my $title = $input->param('title');
83 my $author = $input->param('author');
84 my $copyrightdate = $input->param('copyrightdate');
85 my $itemtype = $input->param('format');
86 my $isbn = $input->param('ISBN');
87 my $seriestitle = $input->param('series');
88 my $branch = $input->param('branch');
89 my $holdingbranch = $branch;
90 my $barcode = $input->param('barcode');
91 my $bookfund = $input->param('bookfund');
92 my $quantity = $input->param('quantity');
93 my $quantrec = $input->param('quantityrec');
94 my $ecost = $input->param('ecost');
95 my $unitprice = $input->param('unitprice');
96 my $notes = $input->param('notes');
97 my $booksellers = $input->param('booksellers');
98 my $foo = $input->param('foo');
99 my $volinf = $input->param('volinf');
100 my $catview = $input->param('catview'); # for editing from moredetail.tmpl
101 my $barcodeexists = $input->param('barcodeexists'); # if barcode exists
102 my $newitemfailed = $input->param('newitemfailed'); # if create new item failed
104 $input->param('createbibitem'); # user wants to create a new bibitem
106 #get additional info on bib and bibitem from dbase for additional needed fields before modbiblio.
107 ( my $bibliocount, my @biblios ) = &getbiblio($biblionumber);
108 my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
109 my $biblioitemcount = scalar @biblioitems;
111 ( my $itemscount, my @items ) = &getitemsbybiblioitem($biblioitemnumber);
114 biblionumber => $biblionumber,
117 abstract => $biblios[0]->{'abstract'},
118 copyrightdate => $copyrightdate,
119 seriestitle => $seriestitle,
120 serial => $biblios[0]->{'serial'},
121 unititle => $biblios[0]->{'unititle'},
122 notes => $biblios[0]->{'notes'}
125 my $biblioitemhash = {
126 illus => $biblioitems[0]->{'illus'},
127 number => $biblioitems[0]->{'number'},
128 itemtype => $itemtype,
129 place => $biblioitems[0]->{'place'},
130 biblioitemnumber => $biblioitemnumber,
131 issn => $biblioitems[0]->{'issn'},
132 size => $biblioitems[0]->{'size'},
133 marc => $biblioitems[0]->{'marc'},
134 timestamp => $biblioitems[0]->{'timestamp'},
135 biblionumber => $biblionumber,
136 url => $biblioitems[0]->{'url'},
137 dewey => $biblioitems[0]->{'dewey'},
139 publishercode => $biblioitems[0]->{'publishercode'},
140 lccn => $biblioitems[0]->{'iccn'},
141 volume => $biblioitems[0]->{'volume'},
142 subclass => $biblioitems[0]->{'subclass'},
143 notes => $biblioitems[0]->{'notes'},
144 classification => $biblioitems[0]->{'classification'},
145 volumeddesc => $volinf,
146 publicationyear => $biblioitems[0]->{'publicationyear'},
147 volumedate => $biblioitems[0]->{'volumedate'},
148 pages => $biblioitems[0]->{'pages'}
152 biblionumber => $biblionumber,
153 itemnum => $items[0]->{'itemnumber'},
155 notes => $items[0]->{'notes'},
156 itemcallnumber => $items[0]->{'itemcallnumber'},
157 notforloan => $items[0]->{'notforloan'},
158 location => $items[0]->{'location'},
159 bibitemnum => $biblioitemnumber,
160 homebranch => $items[0]->{'homebranch'},
161 lost => $items[0]->{'itemlost'},
162 withdrawn => $items[0]->{'withdrawn'},
163 holdingbranch => $items[0]->{'holdingbranch'},
164 replacement => $replacement
167 # check if barcode exists, if so redirect back to orderreceive.pl and give message
168 my $error = &checkitems( 1, $barcode );
169 #warn "barcode check for $barcode result = $error";
171 print $input->redirect(
172 "/cgi-bin/koha/acqui/orderreceive.pl?recieve=$ordnum&biblio=$biblionumber&invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&barcodeexists=$barcode"
175 # or if barcode is blank
178 if ( $createbibitem eq "YES" ) {
179 &modbiblio($bibliohash);
180 $biblioitemnumber = &newbiblioitem($biblioitemhash);
182 #lets do a lookup on aqorders, with ordnum, then insert biblioitem fiels with new biblioitem number
185 "UPDATE aqorders SET biblioitemnumber = ? where ordernumber = ?
186 and biblionumber = ?";
187 my $sth = $dbh->prepare($query);
188 my $error = $sth->execute( $biblioitemnumber, $ordnum, $biblionumber );
190 $sth->fetchrow_hashref;
194 &modbiblio($bibliohash);
195 &modbibitem($biblioitemhash);
200 print $input->redirect(
201 "/cgi-bin/koha/moredetail.pl?type=$itemtype&bib=$biblionumber&bi=$biblioitemnumber"
205 if ( $quantity != 0 ) {
206 # save the quantity recieved.
207 receiveorder( $biblionumber, $ordnum, $quantrec, $user, $cost,
208 $invoiceno, $freightperitem, $bookfund, $replacement );
210 # create items if the user has entered barcodes
211 my @barcodes = split( /\,| |\|/, $barcode ); #WTF?
213 my ($error) = newitems(
215 biblioitemnumber => $biblioitemnumber,
216 biblionumber => $biblionumber,
217 replacementprice => $replacement,
219 booksellerid => $supplierid,
220 homebranch => $branch,
227 { #if newitems failes then display error, and send them back to orderreceive.pl????
229 print $input->redirect(
230 "/cgi-bin/koha/acqui/orderreceive.pl?recieve=$ordnum&biblio=$biblionumber&invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&newitemfailed=1"
234 elsif ( $itemtype ne 'P' && $itemtype ne 'PP' ) { # chris's new if bit
236 my $item = getiteminformation( \%env, 0, $barcode );
237 my ( $resfound, $resrec ) = CheckReserves( 0, $barcode );
239 if ($resfound) { # reserves is found
241 getpatroninformation( \%env, $resrec->{'borrowernumber'}, 0 );
243 borrowernumber => $borrower->{'borrowernumber'},
244 cardnumber => $borrower->{'cardnumber'},
245 firstname => $borrower->{'firstname'},
246 surname => $borrower->{'surname'},
247 invoice => $invoiceno,
253 biblionumber => $biblionumber,
257 output_html_with_http_headers $input, $cookie,
260 else { #no reserves found
262 s/\&/\%26/g; # swapping pesky & with url friendly hex codes.
263 print $input->redirect(
264 "/cgi-bin/koha/acqui/receive.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&quantity=$quantity"
269 print $input->redirect(
270 "/cgi-bin/koha/loadmodules.pl?module=acquisitions")
276 # print $input->header;
277 DelOrder( $biblionumber, $ordnum );
278 print $input->redirect("/acquisitions/");