1 package C4::Acquisitions; #asummes C4/Acquisitions.pm
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw(&getorders &bookseller &breakdown &basket &newbasket &bookfunds
14 &ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder
15 &newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder
16 &bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem
17 &getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems
18 &findall &needsmod &delitem &delbibitem &delbiblio &delorder &branches
19 &getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder
20 &updatecost &checkitems &modnote &getitemtypes &getbiblio
21 &getbiblioitem &getitemsbybiblioitem &isbnsearch &keywordsearch
23 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
25 # your exported package globals go here,
26 # as well as any optionally exported functions
28 @EXPORT_OK = qw($Var1 %Hashit);
31 # non-exported package globals go here
32 use vars qw(@more $stuff);
34 # initalize package globals, first exported ones
41 # then the others (which are still accessible as $Some::Module::stuff)
45 # all file-scoped lexicals must be created before
46 # the functions below that use them.
48 # file-private lexicals go here
52 # here's a file-private function as a closure,
53 # callable as &$priv_func; it cannot be prototyped.
58 # make all your functions, whether exported or not;
63 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
64 booksellerid='$supplierid' and (quantity > quantityreceived or
65 quantityreceived is NULL)
66 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
67 $query.=" group by basketno order by entrydate desc";
69 my $sth=$dbh->prepare($query);
73 while (my $data=$sth->fetchrow_hashref){
79 return ($i,\@results);
85 my $query="Select count(*) from items where biblionumber=$biblio";
87 my $sth=$dbh->prepare($query);
89 my $data=$sth->fetchrow_hashref;
92 return($data->{'count(*)'});
98 my $query="Select ordernumber from aqorders where biblionumber=$bib and
99 biblioitemnumber='$bi'";
100 my $sth=$dbh->prepare($query);
102 my $ordnum=$sth->fetchrow_hashref;
104 my $order=getsingleorder($ordnum->{'ordernumber'});
107 return ($order,$ordnum->{'ordernumber'});
113 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
114 where aqorders.ordernumber='$ordnum'
115 and biblio.biblionumber=aqorders.biblionumber and
116 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
117 aqorders.ordernumber=aqorderbreakdown.ordernumber";
118 my $sth=$dbh->prepare($query);
120 my $data=$sth->fetchrow_hashref;
129 my $query="Select * from aqorders,biblio,biblioitems where
130 booksellerinvoicenumber='$invoice'
131 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
132 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
135 my $sth=$dbh->prepare($query);
137 while (my $data=$sth->fetchrow_hashref){
147 #gets all orders from a certain supplier, orders them alphabetically
150 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
151 and (cancelledby is NULL or cancelledby = '')
152 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
153 aqorders.biblioitemnumber
154 group by aqorders.biblioitemnumber
159 my $sth=$dbh->prepare($query);
161 while (my $data=$sth->fetchrow_hashref){
171 #gets all orders from a certain supplier, orders them alphabetically
174 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
175 and (cancelledby is NULL or cancelledby = '')
176 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
177 aqorders.biblioitemnumber and
178 aqorders.quantityreceived>0
179 and aqorders.datereceived >=now()
180 group by aqorders.biblioitemnumber
185 my $sth=$dbh->prepare($query);
187 while (my $data=$sth->fetchrow_hashref){
197 my ($search,$biblio,$catview) = @_;
199 my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
200 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
201 and biblio.biblionumber=aqorders.biblionumber
202 and ((datecancellationprinted is NULL)
203 or (datecancellationprinted = '0000-00-00')
205 my @data = split(' ',$search);
207 for (my $i = 0; $i < $count; $i++) {
208 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
211 $query.=" ) or biblioitems.isbn='$search'
212 or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
213 if ($catview ne 'yes'){
214 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
216 $query.=" group by aqorders.ordernumber";
217 my $sth=$dbh->prepare($query);
222 while (my $data=$sth->fetchrow_hashref){
223 my $sth2=$dbh->prepare("Select * from biblio where
224 biblionumber='$data->{'biblionumber'}'");
226 my $data2=$sth2->fetchrow_hashref;
228 $data->{'author'}=$data2->{'author'};
229 $data->{'seriestitle'}=$data2->{'seriestitle'};
230 $sth2=$dbh->prepare("Select * from aqorderbreakdown where
231 ordernumber=$data->{'ordernumber'}");
233 $data2=$sth2->fetchrow_hashref;
235 $data->{'branchcode'}=$data2->{'branchcode'};
236 $data->{'bookfundid'}=$data2->{'bookfundid'};
247 my ($searchstring)=@_;
249 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
250 id = '$searchstring'";
251 my $sth=$dbh->prepare($query);
255 while (my $data=$sth->fetchrow_hashref){
267 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
268 my $sth=$dbh->prepare($query);
272 while (my $data=$sth->fetchrow_hashref){
278 return($i,\@results);
282 my ($basketno,$supplier)=@_;
284 my $query="Select *,biblio.title from aqorders,biblio,biblioitems
285 where basketno='$basketno'
286 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
287 =aqorders.biblioitemnumber
288 and (datecancellationprinted is NULL or datecancellationprinted =
290 if ($supplier ne ''){
291 $query.=" and aqorders.booksellerid='$supplier'";
293 $query.=" group by aqorders.ordernumber";
294 my $sth=$dbh->prepare($query);
299 while (my $data=$sth->fetchrow_hashref){
310 my $query="Select max(basketno) from aqorders";
311 my $sth=$dbh->prepare($query);
313 my $data=$sth->fetchrow_arrayref;
314 my $basket=$$data[0];
323 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
325 and aqbudget.startdate='2001=07-01'
326 group by aqbookfund.bookfundid order by bookfundname";
327 my $sth=$dbh->prepare($query);
331 while (my $data=$sth->fetchrow_hashref){
342 my $query = "Select * from branches";
343 my $sth = $dbh->prepare($query);
348 while (my $data = $sth->fetchrow_hashref) {
349 $results[$i] = $data;
355 return($i, @results);
358 sub bookfundbreakdown {
361 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
362 from aqorders,aqorderbreakdown where bookfundid='$id' and
363 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
364 '2001-07-01' and budgetdate <'2002-07-01') or
365 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
366 and (datecancellationprinted is NULL or
367 datecancellationprinted='0000-00-00')";
368 my $sth=$dbh->prepare($query);
372 while (my $data=$sth->fetchrow_hashref){
373 if ($data->{'subscription'} == 1){
374 $spent+=$data->{'quantity'}*$data->{'unitprice'};
376 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
377 $comtd+=($data->{'ecost'})*$leftover;
378 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
383 return($spent,$comtd);
389 my $dbh = &C4Connect;
390 my $query = "Select max(biblionumber) from biblio";
391 my $sth = $dbh->prepare($query);
393 my $data = $sth->fetchrow_arrayref;
394 my $bibnum = $$data[0] + 1;
397 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
398 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
399 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
400 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
401 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
402 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
403 if ($biblio->{'seriestitle'}) { $series = 1 };
406 $query = "insert into biblio set
407 biblionumber = $bibnum,
408 title = $biblio->{'title'},
409 author = $biblio->{'author'},
410 copyrightdate = $biblio->{'copyright'},
412 seriestitle = $biblio->{'seriestitle'},
413 notes = $biblio->{'notes'},
414 abstract = $biblio->{'abstract'}";
416 $sth = $dbh->prepare($query);
431 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
432 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
433 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
434 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
435 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
436 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
437 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
438 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
440 $query = "Update biblio set
441 title = $biblio->{'title'},
442 author = $biblio->{'author'},
443 abstract = $biblio->{'abstract'},
444 copyrightdate = $biblio->{'copyrightdate'},
445 seriestitle = $biblio->{'seriestitle'},
446 serial = $biblio->{'serial'},
447 unititle = $biblio->{'unititle'},
448 notes = $biblio->{'notes'}
449 where biblionumber = $biblio->{'biblionumber'}";
450 $sth = $dbh->prepare($query);
456 return($biblio->{'biblionumber'});
461 my ($bibnum, $subtitle) = @_;
463 my $query = "update bibliosubtitle set
464 subtitle = '$subtitle'
465 where biblionumber = $bibnum";
466 my $sth = $dbh->prepare($query);
475 my ($bibnum, $author) = @_;
477 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
478 my $sth = $dbh->prepare($query);
484 $query = "Insert into additionalauthors set
486 biblionumber = '$bibnum'";
487 $sth = $dbh->prepare($query);
499 my ($bibnum, $force, @subject) = @_;
501 my $count = @subject;
503 for (my $i = 0; $i < $count; $i++) {
504 $subject[$i] =~ s/^ //g;
505 $subject[$i] =~ s/ $//g;
506 my $query = "select * from catalogueentry
507 where entrytype = 's'
508 and catalogueentry = '$subject[$i]'";
509 my $sth = $dbh->prepare($query);
512 if (my $data = $sth->fetchrow_hashref) {
514 if ($force eq $subject[$i]) {
516 # subject not in aut, chosen to force anway
517 # so insert into cataloguentry so its in auth file
518 $query = "Insert into catalogueentry
519 (entrytype,catalogueentry)
520 values ('s','$subject[$i]')";
521 my $sth2 = $dbh->prepare($query);
528 $error = "$subject[$i]\n does not exist in the subject authority file";
529 $query = "Select * from catalogueentry
530 where entrytype = 's'
531 and (catalogueentry like '$subject[$i] %'
532 or catalogueentry like '% $subject[$i] %'
533 or catalogueentry like '% $subject[$i]')";
534 my $sth2 = $dbh->prepare($query);
537 while (my $data = $sth2->fetchrow_hashref) {
538 $error = $error."<br>$data->{'catalogueentry'}";
547 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
548 my $sth = $dbh->prepare($query);
553 for (my $i = 0; $i < $count; $i++) {
554 $sth = $dbh->prepare("Insert into bibliosubject
555 values ('$subject[$i]', $bibnum)");
567 my ($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place)=@_;
569 my $query="update biblioitems set itemtype='$itemtype',
570 isbn='$isbn',publishercode='$publishercode',publicationyear='$publicationdate',
571 classification='$classification',dewey='$dewey',subclass='$subclass',illus='$illus',
572 pages='$pages',volumeddesc='$volumeddesc',notes='$notes',size='$size',place='$place'
574 biblioitemnumber=$bibitemnum";
575 my $sth=$dbh->prepare($query);
583 my ($bibitemnum,$note)=@_;
585 my $query="update biblioitems set notes='$note' where
586 biblioitemnumber='$bibitemnum'";
587 my $sth=$dbh->prepare($query);
594 my ($biblioitem) = @_;
596 my $query = "Select max(biblioitemnumber) from biblioitems";
597 my $sth = $dbh->prepare($query);
601 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
602 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
603 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
604 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
605 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
606 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
607 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
608 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
609 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
610 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
611 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
612 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
613 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
614 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
615 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
616 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
617 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
620 $data = $sth->fetchrow_arrayref;
621 $bibitemnum = $$data[0] + 1;
625 $query = "insert into biblioitems set
626 biblioitemnumber = $bibitemnum,
627 biblionumber = $biblioitem->{'biblionumber'},
628 volume = $biblioitem->{'volume'},
629 number = $biblioitem->{'number'},
630 classification = $biblioitem->{'classification'},
631 itemtype = $biblioitem->{'itemtype'},
632 url = $biblioitem->{'url'},
633 isbn = $biblioitem->{'isbn'},
634 issn = $biblioitem->{'issn'},
635 dewey = $biblioitem->{'dewey'},
636 subclass = $biblioitem->{'subclass'},
637 publicationyear = $biblioitem->{'publicationyear'},
638 publishercode = $biblioitem->{'publishercode'},
639 volumedate = $biblioitem->{'volumedate'},
640 volumeddesc = $biblioitem->{'volumeddesc'},
641 illus = $biblioitem->{'illus'},
642 pages = $biblioitem->{'pages'},
643 notes = $biblioitem->{'notes'},
644 size = $biblioitem->{'size'},
645 place = $biblioitem->{'place'}";
647 $sth = $dbh->prepare($query);
658 my $query="insert into bibliosubject (biblionumber) values
660 my $sth=$dbh->prepare($query);
668 my ($bibnum, $subtitle) = @_;
670 $subtitle = $dbh->quote($subtitle);
671 my $query = "insert into bibliosubtitle set
672 biblionumber = $bibnum,
673 subtitle = $subtitle";
674 my $sth = $dbh->prepare($query);
683 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
684 if ($budget eq 'now'){
687 $budget="'2001-07-01'";
695 my $query="insert into aqorders (biblionumber,title,basketno,
696 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
697 biblioitemnumber,rrp,ecost,gst,budgetdate,unitprice,subscription,booksellerinvoicenumber)
700 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
701 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst',$budget,'$cost',
703 my $sth=$dbh->prepare($query);
707 $query="select * from aqorders where
708 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
709 $sth=$dbh->prepare($query);
711 my $data=$sth->fetchrow_hashref;
713 $ordnum=$data->{'ordernumber'};
714 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
715 ($ordnum,'$bookfund')";
716 $sth=$dbh->prepare($query);
724 my ($bibnum,$ordnum)=@_;
726 my $query="update aqorders set datecancellationprinted=now()
727 where biblionumber='$bibnum' and
728 ordernumber='$ordnum'";
729 my $sth=$dbh->prepare($query);
733 my $count=itemcount($bibnum);
741 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
743 my $query="update aqorders set title='$title',
744 quantity='$quantity',listprice='$listprice',basketno='$basketno',
745 rrp='$rrp',ecost='$ecost',unitprice='$cost',
746 booksellerinvoicenumber='$invoice'
748 ordernumber=$ordnum and biblionumber=$bibnum";
749 my $sth=$dbh->prepare($query);
753 $query="update aqorderbreakdown set bookfundid=$bookfund where
754 ordernumber=$ordnum";
755 $sth=$dbh->prepare($query);
764 my $query="Select max(ordernumber) from aqorders";
765 my $sth=$dbh->prepare($query);
767 my $data=$sth->fetchrow_arrayref;
768 my $ordnum=$$data[0];
776 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
778 my $query="update aqorders set quantityreceived='$quantrec',
779 datereceived=now(),booksellerinvoicenumber='$invoiceno',
780 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
782 where biblionumber=$biblio and ordernumber=$ordnum
785 my $sth=$dbh->prepare($query);
788 $query="update aqorderbreakdown set bookfundid=$bookfund where
789 ordernumber=$ordnum";
790 $sth=$dbh->prepare($query);
797 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
799 my $query="update aqorders set
800 unitprice='$cost', rrp='$rrp'
801 where biblionumber=$biblio and ordernumber=$ordnum
804 my $sth=$dbh->prepare($query);
807 $query="update aqorderbreakdown set bookfundid=$bookfund where
808 ordernumber=$ordnum";
809 $sth=$dbh->prepare($query);
817 my ($currency,$price)=@_;
819 my $query="Select rate from currency where currency='$currency'";
820 my $sth=$dbh->prepare($query);
822 my $data=$sth->fetchrow_hashref;
825 my $cur=$data->{'rate'};
829 my $price=$price / $cur;
835 my $query="Select * from currency";
836 my $sth=$dbh->prepare($query);
840 while (my $data=$sth->fetchrow_hashref){
846 return($i,\@results);
852 my $query="Select * from currency where currency='$cur'";
853 my $sth=$dbh->prepare($query);
856 my $data=$sth->fetchrow_hashref;
862 sub updatecurrencies {
863 my ($currency,$rate)=@_;
865 my $query="update currency set rate=$rate where currency='$currency'";
866 my $sth=$dbh->prepare($query);
875 my $query="Update aqbooksellers set
876 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
877 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
878 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
879 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
880 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
881 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
882 '$data->{'contnotes'}', active=$data->{'active'},
883 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
884 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
885 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
886 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
887 nocalc='$data->{'nocalc'}'
888 where id='$data->{'id'}'";
889 my $sth=$dbh->prepare($query);
899 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
901 my $data2=$sth->fetchrow_hashref;
903 $data2->{'max(id)'}++;
904 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
907 $data->{'id'}=$data2->{'max(id)'};
910 return($data->{'id'});
915 my ($item, @barcodes) = @_;
917 my $query = "Select max(itemnumber) from items";
918 my $sth = $dbh->prepare($query);
924 $data = $sth->fetchrow_hashref;
925 $itemnumber = $data->{'max(itemnumber)'} + 1;
928 $item->{'booksellerid'} = $dbh->quote($item->{'bookselletid'});
929 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
930 $item->{'price'} = $dbh->quote($item->{'price'});
931 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
932 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
934 foreach my $barcode (@barcodes) {
935 $barcode = uc($barcode);
936 $query = "Insert into items set
937 itemnumber = $itemnumber,
938 biblionumber = $item->{'biblionumber'},
939 biblioitemnumber = $item->{'biblioitemnumber'},
941 booksellerid = $item->{'booksellerid'},
942 dateaccessioned = NOW(),
943 homebranch = $item->{'homebranch'},
944 holdingbranch = $item->{'homebranch'},
945 price = $item->{'price'},
946 replacementprice = $item->{'replacementprice'},
947 replacementpricedate = NOW(),
948 itemnotes = $item->{'itemnotes'}";
950 if ($item->{'loan'}) {
952 notforloan = $item->{'loan'}";
955 $sth = $dbh->prepare($query);
958 $error .= $sth->errstr;
969 my ($count,@barcodes)=@_;
972 for (my $i=0;$i<$count;$i++){
973 $barcodes[$i]=uc $barcodes[$i];
974 my $query="Select * from items where barcode='$barcodes[$i]'";
975 my $sth=$dbh->prepare($query);
977 if (my $data=$sth->fetchrow_hashref){
978 $error.=" Duplicate Barcode: $barcodes[$i]";
987 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
989 my $query="update items set biblioitemnumber=$bibitemnum,
990 barcode='$barcode',itemnotes='$notes'
991 where itemnumber=$itemnum";
993 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
996 $query="update items set biblioitemnumber=$bibitemnum,
997 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
998 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
1000 if ($replacement ne ''){
1001 $query=~ s/ where/,replacementprice='$replacement' where/;
1004 my $sth=$dbh->prepare($query);
1011 my($price,$rrp,$itemnum)=@_;
1013 my $query="update items set price='$price',replacementprice='$rrp'
1014 where itemnumber=$itemnum";
1015 my $sth=$dbh->prepare($query);
1021 my ($bibitemnum)=@_;
1023 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1024 my $sth=$dbh->prepare($query);
1026 my $data=$sth->fetchrow_hashref;
1029 return($data->{'count(*)'});
1033 my ($biblionumber)=@_;
1035 my $query="Select * from biblioitems,items,itemtypes where
1036 biblioitems.biblionumber=$biblionumber
1037 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1038 itemtypes.itemtype=biblioitems.itemtype
1039 order by items.biblioitemnumber";
1040 my $sth=$dbh->prepare($query);
1044 while (my $data=$sth->fetchrow_hashref){
1054 my ($bibitemnum,$itemtype)=@_;
1056 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1057 and itemtype='$itemtype'";
1058 my $sth=$dbh->prepare($query);
1061 if (my $data=$sth->fetchrow_hashref){
1072 my $query="select * from items where itemnumber=$itemnum";
1073 my $sth=$dbh->prepare($query);
1075 my @data=$sth->fetchrow_array;
1077 $query="Insert into deleteditems values (";
1078 foreach my $temp (@data){
1079 $query=$query."'$temp',";
1083 $sth=$dbh->prepare($query);
1086 $query = "Delete from items where itemnumber=$itemnum";
1087 $sth=$dbh->prepare($query);
1096 my $query="select * from biblioitems where biblioitemnumber=$itemnum";
1097 my $sth=$dbh->prepare($query);
1099 if (my @data=$sth->fetchrow_array){
1101 $query="Insert into deletedbiblioitems values (";
1102 foreach my $temp (@data){
1103 $temp=~ s/\'/\\\'/g;
1104 $query=$query."'$temp',";
1108 $sth=$dbh->prepare($query);
1111 $query = "Delete from biblioitems where biblioitemnumber=$itemnum";
1112 $sth=$dbh->prepare($query);
1123 my $query="select * from biblio where biblionumber=$biblio";
1124 my $sth=$dbh->prepare($query);
1126 if (my @data=$sth->fetchrow_array){
1128 $query="Insert into deletedbiblio values (";
1129 foreach my $temp (@data){
1130 $temp=~ s/\'/\\\'/g;
1131 $query=$query."'$temp',";
1135 $sth=$dbh->prepare($query);
1138 $query = "Delete from biblio where biblionumber=$biblio";
1139 $sth=$dbh->prepare($query);
1149 my $dbh = C4Connect;
1150 my $query = "select * from itemtypes";
1151 my $sth = $dbh->prepare($query);
1152 # || die "Cannot prepare $query" . $dbh->errstr;
1157 # || die "Cannot execute $query\n" . $sth->errstr;
1158 while (my $data = $sth->fetchrow_hashref) {
1159 @results[$count] = $data;
1165 return($count, @results);
1166 } # sub getitemtypes
1170 my ($biblionumber) = @_;
1171 my $dbh = C4Connect;
1172 my $query = "Select * from biblio where biblionumber = $biblionumber";
1173 my $sth = $dbh->prepare($query);
1174 # || die "Cannot prepare $query\n" . $dbh->errstr;
1179 # || die "Cannot execute $query\n" . $sth->errstr;
1180 while (my $data = $sth->fetchrow_hashref) {
1181 $results[$count] = $data;
1187 return($count, @results);
1192 my ($biblioitemnum) = @_;
1193 my $dbh = C4Connect;
1194 my $query = "Select * from biblioitems where
1195 biblioitemnumber = $biblioitemnum";
1196 my $sth = $dbh->prepare($query);
1202 while (my $data = $sth->fetchrow_hashref) {
1203 $results[$count] = $data;
1209 return($count, @results);
1210 } # sub getbiblioitem
1213 sub getitemsbybiblioitem {
1214 my ($biblioitemnum) = @_;
1215 my $dbh = C4Connect;
1216 my $query = "Select * from items, biblio where
1217 biblio.biblionumber = items.biblionumber and biblioitemnumber
1219 my $sth = $dbh->prepare($query);
1220 # || die "Cannot prepare $query\n" . $dbh->errstr;
1225 # || die "Cannot execute $query\n" . $sth->errstr;
1226 while (my $data = $sth->fetchrow_hashref) {
1227 $results[$count] = $data;
1233 return($count, @results);
1234 } # sub getitemsbybiblioitem
1239 my $dbh = C4Connect;
1245 $isbn = $dbh->quote($isbn);
1246 $query = "Select * from biblioitems where isbn = $isbn";
1247 $sth = $dbh->prepare($query);
1250 while (my $data = $sth->fetchrow_hashref) {
1251 $results[$count] = $data;
1257 return($count, @results);
1262 my ($keywordlist) = @_;
1263 my $dbh = C4Connect;
1264 my $query = "Select * from biblio where";
1268 my @keywords = split(/ +/, $keywordlist);
1269 my $keyword = shift(@keywords);
1271 $keyword =~ s/%/\\%/g;
1272 $keyword =~ s/_/\\_/;
1273 $keyword = "%" . $keyword . "%";
1274 $keyword = $dbh->quote($keyword);
1275 $query .= " (author like $keyword) or
1276 (title like $keyword) or (unititle like $keyword) or
1277 (notes like $keyword) or (seriestitle like $keyword) or
1278 (abstract like $keyword)";
1280 foreach $keyword (@keywords) {
1281 $keyword =~ s/%/\\%/;
1282 $keyword =~ s/_/\\_/;
1283 $keyword = "%" . $keyword . "%";
1284 $keyword = $dbh->quote($keyword);
1285 $query .= " or (author like $keyword) or
1286 (title like $keyword) or (unititle like $keyword) or
1287 (notes like $keyword) or (seriestitle like $keyword) or
1288 (abstract like $keyword)";
1291 $sth = $dbh->prepare($query);
1294 while (my $data = $sth->fetchrow_hashref) {
1295 $results[$count] = $data;
1301 return($count, @results);
1302 } # sub keywordsearch
1306 my ($keywordlist) = @_;
1307 my $dbh = C4Connect;
1308 my $query = "Select distinct biblio.* from biblio, biblioitems where
1309 biblio.biblionumber = biblioitems.biblionumber and (";
1313 my @keywords = split(/ +/, $keywordlist);
1314 my $keyword = shift(@keywords);
1316 $keyword =~ s/%/\\%/g;
1317 $keyword =~ s/_/\\_/;
1318 $keyword = "%" . $keyword . "%";
1319 $keyword = $dbh->quote($keyword);
1320 $query .= " (url like $keyword)";
1322 foreach $keyword (@keywords) {
1323 $keyword =~ s/%/\\%/;
1324 $keyword =~ s/_/\\_/;
1325 $keyword = "%" . $keyword . "%";
1326 $keyword = $dbh->quote($keyword);
1327 $query .= " or (url like $keyword)";
1331 $sth = $dbh->prepare($query);
1334 while (my $data = $sth->fetchrow_hashref) {
1335 $results[$count] = $data;
1341 return($count, @results);
1342 } # sub websitesearch
1345 END { } # module clean-up code here (global destructor)