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);
347 while (my $data=$sth->fetchrow_hashref){
356 sub bookfundbreakdown {
359 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
360 from aqorders,aqorderbreakdown where bookfundid='$id' and
361 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
362 '2001-07-01' and budgetdate <'2002-07-01') or
363 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
364 and (datecancellationprinted is NULL or
365 datecancellationprinted='0000-00-00')";
366 my $sth=$dbh->prepare($query);
370 while (my $data=$sth->fetchrow_hashref){
371 if ($data->{'subscription'} == 1){
372 $spent+=$data->{'quantity'}*$data->{'unitprice'};
374 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
375 $comtd+=($data->{'ecost'})*$leftover;
376 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
381 return($spent,$comtd);
387 my $dbh = &C4Connect;
388 my $query = "Select max(biblionumber) from biblio";
389 my $sth = $dbh->prepare($query);
391 my $data = $sth->fetchrow_arrayref;
392 my $bibnum = $$data[0] + 1;
395 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
396 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
397 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
398 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
399 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
400 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
401 if ($biblio->{'seriestitle'}) { $series = 1 };
404 $query = "insert into biblio set
405 biblionumber = $bibnum,
406 title = $biblio->{'title'},
407 author = $biblio->{'author'},
408 copyrightdate = $biblio->{'copyright'},
410 seriestitle = $biblio->{'seriestitle'},
411 notes = $biblio->{'notes'},
412 abstract = $biblio->{'abstract'}";
414 $sth = $dbh->prepare($query);
424 my ($bibnum, $title, $author, $copyright, $seriestitle, $serial, $unititle, $notes)=@_;
426 my $query = "Update biblio set
429 copyrightdate = '$copyright',
430 seriestitle = '$seriestitle',
432 unititle = '$unititle',
434 where biblionumber = $bibnum";
435 my $sth = $dbh->prepare($query);
445 my ($bibnum,$subtitle)=@_;
447 my $query="update bibliosubtitle set subtitle='$subtitle' where biblionumber=$bibnum";
448 my $sth=$dbh->prepare($query);
455 my ($bibnum, $author) = @_;
457 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
458 my $sth = $dbh->prepare($query);
464 $query = "Insert into additionalauthors set
466 biblionumber = '$bibnum'";
467 $sth = $dbh->prepare($query);
479 my ($bibnum,$force,@subject)=@_;
483 for (my $i=0;$i<$count;$i++){
484 $subject[$i]=~ s/^ //g;
485 $subject[$i]=~ s/ $//g;
486 my $query="select * from catalogueentry where entrytype='s' and
487 catalogueentry='$subject[$i]'";
488 my $sth=$dbh->prepare($query);
490 if (my $data=$sth->fetchrow_hashref){
493 if ($force eq $subject[$i]){
494 #subject not in aut, chosen to force anway
495 #so insert into cataloguentry so its in auth file
496 $query="Insert into catalogueentry (entrytype,catalogueentry)
497 values ('s','$subject[$i]')";
498 my $sth2=$dbh->prepare($query);
503 $error="$subject[$i]\n does not exist in the subject authority file";
504 $query= "Select * from catalogueentry where
505 entrytype='s' and (catalogueentry like '$subject[$i] %' or
506 catalogueentry like '% $subject[$i] %' or catalogueentry like
508 my $sth2=$dbh->prepare($query);
511 while (my $data=$sth2->fetchrow_hashref){
512 $error=$error."<br>$data->{'catalogueentry'}";
515 # $error=$error."<br>$query";
521 my $query="Delete from bibliosubject where biblionumber=$bibnum";
523 my $sth=$dbh->prepare($query);
527 for (my $i=0;$i<$count;$i++){
528 $sth=$dbh->prepare("Insert into bibliosubject values ('$subject[$i]',$bibnum)");
529 # print $subject[$i];
539 my ($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place)=@_;
541 my $query="update biblioitems set itemtype='$itemtype',
542 isbn='$isbn',publishercode='$publishercode',publicationyear='$publicationdate',
543 classification='$classification',dewey='$dewey',subclass='$subclass',illus='$illus',
544 pages='$pages',volumeddesc='$volumeddesc',notes='$notes',size='$size',place='$place'
546 biblioitemnumber=$bibitemnum";
547 my $sth=$dbh->prepare($query);
555 my ($bibitemnum,$note)=@_;
557 my $query="update biblioitems set notes='$note' where
558 biblioitemnumber='$bibitemnum'";
559 my $sth=$dbh->prepare($query);
566 my ($biblioitem) = @_;
568 my $query = "Select max(biblioitemnumber) from biblioitems";
569 my $sth = $dbh->prepare($query);
573 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
574 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
575 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
576 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
577 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
578 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
579 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
580 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
581 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
582 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
583 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
584 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
585 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
586 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
587 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
588 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
589 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
592 $data = $sth->fetchrow_arrayref;
593 $bibitemnum = $$data[0] + 1;
597 $query = "insert into biblioitems set
598 biblioitemnumber = $bibitemnum,
599 biblionumber = $biblioitem->{'biblionumber'},
600 volume = $biblioitem->{'volume'},
601 number = $biblioitem->{'number'},
602 classification = $biblioitem->{'classification'},
603 itemtype = $biblioitem->{'itemtype'},
604 url = $biblioitem->{'url'},
605 isbn = $biblioitem->{'isbn'},
606 issn = $biblioitem->{'issn'},
607 dewey = $biblioitem->{'dewey'},
608 subclass = $biblioitem->{'subclass'},
609 publicationyear = $biblioitem->{'publicationyear'},
610 publishercode = $biblioitem->{'publishercode'},
611 volumedate = $biblioitem->{'volumedate'},
612 volumeddesc = $biblioitem->{'volumeddesc'},
613 illus = $biblioitem->{'illus'},
614 pages = $biblioitem->{'pages'},
615 notes = $biblioitem->{'notes'},
616 size = $biblioitem->{'size'},
617 place = $biblioitem->{'place'}";
619 $sth = $dbh->prepare($query);
630 my $query="insert into bibliosubject (biblionumber) values
632 my $sth=$dbh->prepare($query);
640 my ($bibnum, $subtitle) = @_;
642 $subtitle = $dbh->quote($subtitle);
643 my $query = "insert into bibliosubtitle set
644 biblionumber = $bibnum,
645 subtitle = $subtitle";
646 my $sth = $dbh->prepare($query);
655 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
656 if ($budget eq 'now'){
659 $budget="'2001-07-01'";
667 my $query="insert into aqorders (biblionumber,title,basketno,
668 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
669 biblioitemnumber,rrp,ecost,gst,budgetdate,unitprice,subscription,booksellerinvoicenumber)
672 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
673 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst',$budget,'$cost',
675 my $sth=$dbh->prepare($query);
679 $query="select * from aqorders where
680 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
681 $sth=$dbh->prepare($query);
683 my $data=$sth->fetchrow_hashref;
685 $ordnum=$data->{'ordernumber'};
686 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
687 ($ordnum,'$bookfund')";
688 $sth=$dbh->prepare($query);
696 my ($bibnum,$ordnum)=@_;
698 my $query="update aqorders set datecancellationprinted=now()
699 where biblionumber='$bibnum' and
700 ordernumber='$ordnum'";
701 my $sth=$dbh->prepare($query);
705 my $count=itemcount($bibnum);
713 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
715 my $query="update aqorders set title='$title',
716 quantity='$quantity',listprice='$listprice',basketno='$basketno',
717 rrp='$rrp',ecost='$ecost',unitprice='$cost',
718 booksellerinvoicenumber='$invoice'
720 ordernumber=$ordnum and biblionumber=$bibnum";
721 my $sth=$dbh->prepare($query);
725 $query="update aqorderbreakdown set bookfundid=$bookfund where
726 ordernumber=$ordnum";
727 $sth=$dbh->prepare($query);
736 my $query="Select max(ordernumber) from aqorders";
737 my $sth=$dbh->prepare($query);
739 my $data=$sth->fetchrow_arrayref;
740 my $ordnum=$$data[0];
748 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
750 my $query="update aqorders set quantityreceived='$quantrec',
751 datereceived=now(),booksellerinvoicenumber='$invoiceno',
752 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
754 where biblionumber=$biblio and ordernumber=$ordnum
757 my $sth=$dbh->prepare($query);
760 $query="update aqorderbreakdown set bookfundid=$bookfund where
761 ordernumber=$ordnum";
762 $sth=$dbh->prepare($query);
769 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
771 my $query="update aqorders set
772 unitprice='$cost', rrp='$rrp'
773 where biblionumber=$biblio and ordernumber=$ordnum
776 my $sth=$dbh->prepare($query);
779 $query="update aqorderbreakdown set bookfundid=$bookfund where
780 ordernumber=$ordnum";
781 $sth=$dbh->prepare($query);
789 my ($currency,$price)=@_;
791 my $query="Select rate from currency where currency='$currency'";
792 my $sth=$dbh->prepare($query);
794 my $data=$sth->fetchrow_hashref;
797 my $cur=$data->{'rate'};
801 my $price=$price / $cur;
807 my $query="Select * from currency";
808 my $sth=$dbh->prepare($query);
812 while (my $data=$sth->fetchrow_hashref){
818 return($i,\@results);
824 my $query="Select * from currency where currency='$cur'";
825 my $sth=$dbh->prepare($query);
828 my $data=$sth->fetchrow_hashref;
834 sub updatecurrencies {
835 my ($currency,$rate)=@_;
837 my $query="update currency set rate=$rate where currency='$currency'";
838 my $sth=$dbh->prepare($query);
847 my $query="Update aqbooksellers set
848 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
849 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
850 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
851 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
852 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
853 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
854 '$data->{'contnotes'}', active=$data->{'active'},
855 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
856 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
857 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
858 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
859 nocalc='$data->{'nocalc'}'
860 where id='$data->{'id'}'";
861 my $sth=$dbh->prepare($query);
871 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
873 my $data2=$sth->fetchrow_hashref;
875 $data2->{'max(id)'}++;
876 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
879 $data->{'id'}=$data2->{'max(id)'};
882 return($data->{'id'});
887 my ($item, @barcodes) = @_;
889 my $query = "Select max(itemnumber) from items";
890 my $sth = $dbh->prepare($query);
896 $data = $sth->fetchrow_hashref;
897 $itemnumber = $data->{'max(itemnumber)'} + 1;
900 $item->{'booksellerid'} = $dbh->quote($item->{'bookselletid'});
901 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
902 $item->{'price'} = $dbh->quote($item->{'price'});
903 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
904 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
906 foreach my $barcode (@barcodes) {
907 $barcode = uc($barcode);
908 $query = "Insert into items set
909 itemnumber = $itemnumber,
910 biblionumber = $item->{'biblionumber'},
911 biblioitemnumber = $item->{'biblioitemnumber'},
913 booksellerid = $item->{'booksellerid'},
914 dateaccessioned = NOW(),
915 homebranch = $item->{'branch'},
916 holdingbranch = $item->{'branch'},
917 price = $item->{'price'},
918 replacementprice = $item->{'replacementprice'},
919 replacementpricedate = NOW(),
920 notforloan = $item->{'loan'},
921 itemnotes = $item->{'itemnotes'}";
923 $sth = $dbh->prepare($query);
926 $error .= $sth->errstr;
937 my ($count,@barcodes)=@_;
940 for (my $i=0;$i<$count;$i++){
941 $barcodes[$i]=uc $barcodes[$i];
942 my $query="Select * from items where barcode='$barcodes[$i]'";
943 my $sth=$dbh->prepare($query);
945 if (my $data=$sth->fetchrow_hashref){
946 $error.=" Duplicate Barcode: $barcodes[$i]";
955 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
957 my $query="update items set biblioitemnumber=$bibitemnum,
958 barcode='$barcode',itemnotes='$notes'
959 where itemnumber=$itemnum";
961 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
964 $query="update items set biblioitemnumber=$bibitemnum,
965 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
966 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
968 if ($replacement ne ''){
969 $query=~ s/ where/,replacementprice='$replacement' where/;
972 my $sth=$dbh->prepare($query);
979 my($price,$rrp,$itemnum)=@_;
981 my $query="update items set price='$price',replacementprice='$rrp'
982 where itemnumber=$itemnum";
983 my $sth=$dbh->prepare($query);
991 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
992 my $sth=$dbh->prepare($query);
994 my $data=$sth->fetchrow_hashref;
997 return($data->{'count(*)'});
1001 my ($biblionumber)=@_;
1003 my $query="Select * from biblioitems,items,itemtypes where
1004 biblioitems.biblionumber=$biblionumber
1005 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1006 itemtypes.itemtype=biblioitems.itemtype
1007 order by items.biblioitemnumber";
1008 my $sth=$dbh->prepare($query);
1012 while (my $data=$sth->fetchrow_hashref){
1022 my ($bibitemnum,$itemtype)=@_;
1024 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1025 and itemtype='$itemtype'";
1026 my $sth=$dbh->prepare($query);
1029 if (my $data=$sth->fetchrow_hashref){
1040 my $query="select * from items where itemnumber=$itemnum";
1041 my $sth=$dbh->prepare($query);
1043 my @data=$sth->fetchrow_array;
1045 $query="Insert into deleteditems values (";
1046 foreach my $temp (@data){
1047 $query=$query."'$temp',";
1051 $sth=$dbh->prepare($query);
1054 $query = "Delete from items where itemnumber=$itemnum";
1055 $sth=$dbh->prepare($query);
1064 my $query="select * from biblioitems where biblioitemnumber=$itemnum";
1065 my $sth=$dbh->prepare($query);
1067 if (my @data=$sth->fetchrow_array){
1069 $query="Insert into deletedbiblioitems values (";
1070 foreach my $temp (@data){
1071 $temp=~ s/\'/\\\'/g;
1072 $query=$query."'$temp',";
1076 $sth=$dbh->prepare($query);
1079 $query = "Delete from biblioitems where biblioitemnumber=$itemnum";
1080 $sth=$dbh->prepare($query);
1091 my $query="select * from biblio where biblionumber=$biblio";
1092 my $sth=$dbh->prepare($query);
1094 if (my @data=$sth->fetchrow_array){
1096 $query="Insert into deletedbiblio values (";
1097 foreach my $temp (@data){
1098 $temp=~ s/\'/\\\'/g;
1099 $query=$query."'$temp',";
1103 $sth=$dbh->prepare($query);
1106 $query = "Delete from biblio where biblionumber=$biblio";
1107 $sth=$dbh->prepare($query);
1117 my $dbh = C4Connect;
1118 my $query = "select * from itemtypes";
1119 my $sth = $dbh->prepare($query);
1120 # || die "Cannot prepare $query" . $dbh->errstr;
1125 # || die "Cannot execute $query\n" . $sth->errstr;
1126 while (my $data = $sth->fetchrow_hashref) {
1127 @results[$count] = $data;
1133 return($count, @results);
1134 } # sub getitemtypes
1138 my ($biblionumber) = @_;
1139 my $dbh = C4Connect;
1140 my $query = "Select * from biblio where biblionumber = $biblionumber";
1141 my $sth = $dbh->prepare($query);
1142 # || die "Cannot prepare $query\n" . $dbh->errstr;
1147 # || die "Cannot execute $query\n" . $sth->errstr;
1148 while (my $data = $sth->fetchrow_hashref) {
1149 $results[$count] = $data;
1155 return($count, @results);
1160 my ($biblioitemnum) = @_;
1161 my $dbh = C4Connect;
1162 my $query = "Select * from biblioitems where
1163 biblioitemnumber = $biblioitemnum";
1164 my $sth = $dbh->prepare($query);
1170 while (my $data = $sth->fetchrow_hashref) {
1171 $results[$count] = $data;
1177 return($count, @results);
1178 } # sub getbiblioitem
1181 sub getitemsbybiblioitem {
1182 my ($biblioitemnum) = @_;
1183 my $dbh = C4Connect;
1184 my $query = "Select * from items, biblio where
1185 biblio.biblionumber = items.biblionumber and biblioitemnumber
1187 my $sth = $dbh->prepare($query);
1188 # || die "Cannot prepare $query\n" . $dbh->errstr;
1193 # || die "Cannot execute $query\n" . $sth->errstr;
1194 while (my $data = $sth->fetchrow_hashref) {
1195 $results[$count] = $data;
1201 return($count, @results);
1202 } # sub getitemsbybiblioitem
1207 my $dbh = C4Connect;
1213 $isbn = $dbh->quote($isbn);
1214 $query = "Select * from biblioitems where isbn = $isbn";
1215 $sth = $dbh->prepare($query);
1218 while (my $data = $sth->fetchrow_hashref) {
1219 $results[$count] = $data;
1225 return($count, @results);
1230 my ($keywordlist) = @_;
1231 my $dbh = C4Connect;
1232 my $query = "Select * from biblio where";
1236 my @keywords = split(/ +/, $keywordlist);
1237 my $keyword = shift(@keywords);
1239 $keyword =~ s/%/\\%/g;
1240 $keyword =~ s/_/\\_/;
1241 $keyword = "%" . $keyword . "%";
1242 $keyword = $dbh->quote($keyword);
1243 $query .= " (author like $keyword) or
1244 (title like $keyword) or (unititle like $keyword) or
1245 (notes like $keyword) or (seriestitle like $keyword) or
1246 (abstract like $keyword)";
1248 foreach $keyword (@keywords) {
1249 $keyword =~ s/%/\\%/;
1250 $keyword =~ s/_/\\_/;
1251 $keyword = "%" . $keyword . "%";
1252 $keyword = $dbh->quote($keyword);
1253 $query .= " or (author like $keyword) or
1254 (title like $keyword) or (unititle like $keyword) or
1255 (notes like $keyword) or (seriestitle like $keyword) or
1256 (abstract like $keyword)";
1259 $sth = $dbh->prepare($query);
1262 while (my $data = $sth->fetchrow_hashref) {
1263 $results[$count] = $data;
1269 return($count, @results);
1270 } # sub keywordsearch
1274 my ($keywordlist) = @_;
1275 my $dbh = C4Connect;
1276 my $query = "Select distinct biblio.* from biblio, biblioitems where
1277 biblio.biblionumber = biblioitems.biblionumber and (";
1281 my @keywords = split(/ +/, $keywordlist);
1282 my $keyword = shift(@keywords);
1284 $keyword =~ s/%/\\%/g;
1285 $keyword =~ s/_/\\_/;
1286 $keyword = "%" . $keyword . "%";
1287 $keyword = $dbh->quote($keyword);
1288 $query .= " (url like $keyword)";
1290 foreach $keyword (@keywords) {
1291 $keyword =~ s/%/\\%/;
1292 $keyword =~ s/_/\\_/;
1293 $keyword = "%" . $keyword . "%";
1294 $keyword = $dbh->quote($keyword);
1295 $query .= " or (url like $keyword)";
1299 $sth = $dbh->prepare($query);
1302 while (my $data = $sth->fetchrow_hashref) {
1303 $results[$count] = $data;
1309 return($count, @results);
1310 } # sub websitesearch
1313 END { } # module clean-up code here (global destructor)