From 6d578747a9810faba30bbe5b2e26bf42ff9aa1af Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 15 Oct 2002 13:39:17 +0000 Subject: [PATCH] removing Acquisition.pm deleting unused code in biblio.pm, rewriting POD and answering most FIXME comments --- C4/Acquisitions.pm | 1972 -------------------------------------------- C4/Biblio.pm | 1308 ++++++----------------------- 2 files changed, 240 insertions(+), 3040 deletions(-) delete mode 100644 C4/Acquisitions.pm diff --git a/C4/Acquisitions.pm b/C4/Acquisitions.pm deleted file mode 100644 index 529297a635..0000000000 --- a/C4/Acquisitions.pm +++ /dev/null @@ -1,1972 +0,0 @@ -package C4::Acquisitions; #assumes C4/Acquisitions.pm - - -# Copyright 2000-2002 Katipo Communications -# -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA - -# *** -# NOTE: This module is deprecated in Koha 1.3.x, and will shortly be -# deleted. -# *** - -use strict; -require Exporter; -use C4::Context; - #use C4::Biblio; -use vars qw($VERSION @ISA @EXPORT); - -# set the version for version checking -$VERSION = 0.01; - -=head1 NAME - -C4::Acquisitions - Koha module dealing with acquisitions and orders - -=head1 SYNOPSIS - - use C4::Acquisitions; - -=head1 DESCRIPTION - -B This module is deprecated in Koha 1.3.x. - -The functions in this module deal with acquisitions, managing book -orders, converting money to different currencies, and so forth. - -=head1 FUNCTIONS - -=over 2 - -=cut - -@ISA = qw(Exporter); -@EXPORT = qw(&getorders &bookseller &breakdown &basket &newbasket &bookfunds -&ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder -&newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder -&bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem -&getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems -&findall &needsmod &delitem &deletebiblioitem &delbiblio &delorder &branches -&getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder -&updatecost &checkitems &modnote &getitemtypes &getbiblio -&getbiblioitembybiblionumber -&getbiblioitem &getitemsbybiblioitem &isbnsearch -&websitesearch &addwebsite &updatewebsite &deletewebsite); - -=item getorders - - ($count, $orders) = &getorders($booksellerid); - -Finds pending orders from the bookseller with the given ID. Ignores -completed and cancelled orders. - -C<$count> is the number of elements in C<@{$orders}>. - -C<$orders> is a reference-to-array; each element is a -reference-to-hash with the following fields: - -=over 4 - -=item C - -Gives the number of orders in with this basket number. - -=item C - -=item C - -=item C - -These give the value of the corresponding field in the aqorders table -of the Koha database. - -=back - -Results are ordered from most to least recent. - -=cut -#' -# FIXME - This exact function already exists in C4::Catalogue -sub getorders { - my ($supplierid)=@_; - my $dbh = C4::Context->dbh; - my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where - booksellerid='$supplierid' and (quantity > quantityreceived or - quantityreceived is NULL) - and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')"; - $query.=" group by basketno order by entrydate desc"; - #print $query; - my $sth=$dbh->prepare($query); - $sth->execute; - my @results; - my $i=0; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return ($i,\@results); -} - -# Only used internally -# FIXME - This is the same as &C4::Biblio::itemcount, but not -# the same as &C4::Search::itemcount -sub itemcount{ - my ($biblio)=@_; - my $dbh = C4::Context->dbh; - my $query="Select count(*) from items where biblionumber=$biblio"; -# print $query; - my $sth=$dbh->prepare($query); - $sth->execute; - my $data=$sth->fetchrow_hashref; - $sth->finish; - return($data->{'count(*)'}); -} - -=item getorder - - ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber); - -Looks up the order with the given biblionumber and biblioitemnumber. - -Returns a two-element array. C<$ordernumber> is the order number. -C<$order> is a reference-to-hash describing the order; its keys are -fields from the biblio, biblioitems, aqorders, and aqorderbreakdown -tables of the Koha database. - -=cut -#' -# FIXME - There are functions &getorder and &getorders. Isn't this -# somewhat likely to cause confusion? -# FIXME - Almost the exact same function is already in C4::Catalogue -sub getorder{ - my ($bi,$bib)=@_; - my $dbh = C4::Context->dbh; - my $query="Select ordernumber - from aqorders - where biblionumber=? and biblioitemnumber=?"; - my $sth=$dbh->prepare($query); - $sth->execute($bib,$bi); - my $ordnum=$sth->fetchrow_hashref; - $sth->finish; - my $order=getsingleorder($ordnum->{'ordernumber'}); -# print $query; - return ($order,$ordnum->{'ordernumber'}); -} - -=item getsingleorder - - $order = &getsingleorder($ordernumber); - -Looks up an order by order number. - -Returns a reference-to-hash describing the order. The keys of -C<$order> are fields from the biblio, biblioitems, aqorders, and -aqorderbreakdown tables of the Koha database. - -=cut -#' -# FIXME - This is practically the same function as -# &C4::Catalogue::getsingleorder and &C4::Biblio::getsingleorder. -sub getsingleorder { - my ($ordnum)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown - where aqorders.ordernumber=? - and biblio.biblionumber=aqorders.biblionumber and - biblioitems.biblioitemnumber=aqorders.biblioitemnumber and - aqorders.ordernumber=aqorderbreakdown.ordernumber"; - my $sth=$dbh->prepare($query); - $sth->execute($ordnum); - my $data=$sth->fetchrow_hashref; - $sth->finish; - return($data); -} - -=item invoice - - ($count, @results) = &invoice($booksellerinvoicenumber); - -Looks up orders by invoice number. - -Returns an array. C<$count> is the number of elements in C<@results>. -C<@results> is an array of references-to-hash; the keys of each -elements are fields from the aqorders, biblio, and biblioitems tables -of the Koha database. - -=cut -#' -# FIXME - This exact function is already in C4::Catalogue -sub invoice { - my ($invoice)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from aqorders,biblio,biblioitems where - booksellerinvoicenumber='$invoice' - and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber= - aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber"; - my $i=0; - my @results; - my $sth=$dbh->prepare($query); - $sth->execute; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -=item getallorders - - ($count, @results) = &getallorders($booksellerid); - -Looks up all of the pending orders from the supplier with the given -bookseller ID. Ignores cancelled orders. - -C<$count> is the number of elements in C<@results>. C<@results> is an -array of references-to-hash. The keys of each element are fields from -the aqorders, biblio, and biblioitems tables of the Koha database. - -C<@results> is sorted alphabetically by book title. - -=cut -#' -# FIXME - Almost (but not quite) the same function appears in C4::Catalogue -# That one only lists incomplete orders. -sub getallorders { - #gets all orders from a certain supplier, orders them alphabetically - my ($supid)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid' - and (cancelledby is NULL or cancelledby = '') - and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber= - aqorders.biblioitemnumber - group by aqorders.biblioitemnumber - order by - biblio.title"; - my $i=0; - my @results; - my $sth=$dbh->prepare($query); - $sth->execute; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -# FIXME - There's a getrecorders in C4::Catalogue -# FIXME - Never used (neither is the other one, actually) -sub getrecorders { - #gets all orders from a certain supplier, orders them alphabetically - my ($supid)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid' - and (cancelledby is NULL or cancelledby = '') - and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber= - aqorders.biblioitemnumber and - aqorders.quantityreceived>0 - and aqorders.datereceived >=now() - group by aqorders.biblioitemnumber - order by - biblio.title"; - my $i=0; - my @results; - my $sth=$dbh->prepare($query); - $sth->execute; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -=item ordersearch - - ($count, @results) = &ordersearch($search, $biblionumber, $complete); - -Searches for orders. - -C<$search> may take one of several forms: if it is an ISBN, -C<&ordersearch> returns orders with that ISBN. If C<$search> is an -order number, C<&ordersearch> returns orders with that order number -and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered -to be a space-separated list of search terms; in this case, all of the -terms must appear in the title (matching the beginning of title -words). - -If C<$complete> is C, the results will include only completed -orders. In any case, C<&ordersearch> ignores cancelled orders. - -C<&ordersearch> returns an array. C<$count> is the number of elements -in C<@results>. C<@results> is an array of references-to-hash with the -following keys: - -=over 4 - -=item C - -=item C - -=item C - -=item C - -=back - -=cut -#' -# FIXME - The same function (modulo whitespace) appears in C4::Catalogue -sub ordersearch { - my ($search,$biblio,$catview)=@_; - my $dbh = C4::Context->dbh; - my $query="Select *,biblio.title from aqorders,biblioitems,biblio - where aqorders.biblioitemnumber = biblioitems.biblioitemnumber - and biblio.biblionumber=aqorders.biblionumber - and ((datecancellationprinted is NULL) - or (datecancellationprinted = '0000-00-00')) - and (("; - my @data=split(' ',$search); - my $count=@data; - for (my $i=0;$i<$count;$i++){ - $query.= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and "; - } - $query=~ s/ and $//; - $query.=" ) or biblioitems.isbn='$search' - or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) "; - if ($catview ne 'yes'){ - $query.=" and (quantityreceived < quantity or quantityreceived is NULL)"; - } - $query.=" group by aqorders.ordernumber"; - my $sth=$dbh->prepare($query); -# print $query; - $sth->execute; - my $i=0; - my @results; - while (my $data=$sth->fetchrow_hashref){ - my $sth2=$dbh->prepare("Select * from biblio where - biblionumber='$data->{'biblionumber'}'"); - $sth2->execute; - my $data2=$sth2->fetchrow_hashref; - $sth2->finish; - $data->{'author'}=$data2->{'author'}; - $data->{'seriestitle'}=$data2->{'seriestitle'}; - $sth2=$dbh->prepare("Select * from aqorderbreakdown where - ordernumber=$data->{'ordernumber'}"); - $sth2->execute; - $data2=$sth2->fetchrow_hashref; - $sth2->finish; - $data->{'branchcode'}=$data2->{'branchcode'}; - $data->{'bookfundid'}=$data2->{'bookfundid'}; - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -=item bookseller - - ($count, @results) = &bookseller($searchstring); - -Looks up a book seller. C<$searchstring> may be either a book seller -ID, or a string to look for in the book seller's name. - -C<$count> is the number of elements in C<@results>. C<@results> is an -array of references-to-hash, whose keys are the fields of of the -aqbooksellers table in the Koha database. - -=cut -#' -# FIXME - This function appears in C4::Catalogue -sub bookseller { - my ($searchstring)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from aqbooksellers where name like '%$searchstring%' or - id = '$searchstring'"; - my $sth=$dbh->prepare($query); - $sth->execute; - my @results; - my $i=0; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -=item breakdown - - ($count, $results) = &breakdown($ordernumber); - -Looks up an order by order ID, and returns its breakdown. - -C<$count> is the number of elements in C<$results>. C<$results> is a -reference-to-array; its elements are references-to-hash, whose keys -are the fields of the aqorderbreakdown table in the Koha database. - -=cut -#' -# FIXME - This function appears in C4::Catalogue. -sub breakdown { - my ($id)=@_; - my $dbh = C4::Context->dbh; - my $query="Select * from aqorderbreakdown where ordernumber='$id'"; - my $sth=$dbh->prepare($query); - $sth->execute; - my @results; - my $i=0; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,\@results); -} - -=item basket - - ($count, @orders) = &basket($basketnumber, $booksellerID); - -Looks up the pending (non-cancelled) orders with the given basket -number. If C<$booksellerID> is non-empty, only orders from that seller -are returned. - -C<&basket> returns a two-element array. C<@orders> is an array of -references-to-hash, whose keys are the fields from the aqorders, -biblio, and biblioitems tables in the Koha database. C<$count> is the -number of elements in C<@orders>. - -=cut -#' -# FIXME - Almost the same function (with less error-checking) appears in -# C4::Catalogue.pm -sub basket { - my ($basketno,$supplier)=@_; - my $dbh = C4::Context->dbh; - my $query="Select *,biblio.title from aqorders,biblio,biblioitems - where basketno='$basketno' - and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber - =aqorders.biblioitemnumber - and (datecancellationprinted is NULL or datecancellationprinted = - '0000-00-00')"; - if (defined $supplier && $supplier ne ''){ - $query.=" and aqorders.booksellerid='$supplier'"; - } - $query.=" group by aqorders.ordernumber"; - my $sth=$dbh->prepare($query); - $sth->execute; - my @results; -# print $query; - my $i=0; - while (my $data=$sth->fetchrow_hashref){ - $results[$i]=$data; - $i++; - } - $sth->finish; - return($i,@results); -} - -=item newbasket - - $basket = &newbasket(); - -Finds the next unused basket number in the aqorders table of the Koha -database, and returns it. - -=cut -#' -# FIXME - There's a race condition here: -# A calls &newbasket -# B calls &newbasket (gets the same number as A) -# A updates the basket -# B updates the basket, and clobbers A's result. -# A better approach might be to create a dummy order (with, say, -# requisitionedby == "Dummy-$$" or notes == "dummy