From 7e2815885536a94cd93e7c328708eb68579ea231 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Fri, 7 Mar 2008 01:09:45 -0600 Subject: [PATCH] acqui/addorder.pl - use reliable GetBookSellerFromId instead of relying on name search. Signed-off-by: Joshua Ferraro --- C4/Bookseller.pm | 21 ++++++------ acqui/addorder.pl | 38 ++++++++++------------ acqui/neworderempty.pl | 72 +++++++++++++++++------------------------- 3 files changed, 56 insertions(+), 75 deletions(-) diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index c549d820b1..d3e63c7cc5 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -62,7 +62,10 @@ aqbooksellers table in the Koha database. =cut -sub GetBookSeller { +# FIXME: This function is badly named. It should be something like +# SearchBookSellersByName. It is NOT a singular return value. + +sub GetBookSeller($) { my ($searchstring) = @_; my $dbh = C4::Context->dbh; my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?"; @@ -74,7 +77,7 @@ sub GetBookSeller { my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); while ( my $data = $sth->fetchrow_hashref ) { $sth2->execute($data->{id}); - ($data->{basketcount}) = $sth2->fetchrow(); + $data->{basketcount} = $sth2->fetchrow(); push( @results, $data ); } $sth->finish; @@ -82,23 +85,19 @@ sub GetBookSeller { } -sub GetBookSellerFromId { - my ($id) = @_; +sub GetBookSellerFromId($) { + my ($id) = shift or return undef; my $dbh = C4::Context->dbh(); my $query = "SELECT * FROM aqbooksellers WHERE id = ?"; my $sth =$dbh->prepare($query); $sth->execute( $id ); if (my $data = $sth->fetchrow_hashref()){ - my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); + my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); $sth2->execute($id); $data->{basketcount}=$sth2->fetchrow(); - $sth->finish; - $sth2->finish; - return ($data); - } - else { - return 0; + return ($data); } + return 0; } #-----------------------------------------------------------------# diff --git a/acqui/addorder.pl b/acqui/addorder.pl index 1bd80a17cd..7c4bdcd54c 100755 --- a/acqui/addorder.pl +++ b/acqui/addorder.pl @@ -114,15 +114,14 @@ if it is an order from an existing suggestion : the id of this suggestion. use strict; use CGI; -use C4::Auth; -use C4::Acquisition; -use C4::Suggestions; -use C4::Biblio; +use C4::Auth; # get_template_and_user +use C4::Acquisition; # NewOrder DelOrder ModOrder +use C4::Suggestions; # ModStatus +use C4::Biblio; # AddBiblio TransformKohaToMarc use C4::Output; - - -#use Date::Manip; +# FIXME: This needs to do actual error checking and possibly return user to the same form, +# not just blindly call C4 functions and print a redirect. my $input = new CGI; @@ -139,22 +138,19 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); # get CGI parameters -my $ordnum = $input->param('ordnum'); -my $basketno = $input->param('basketno'); -my $booksellerid = $input->param('booksellerid'); -my $existing = $input->param('existing'); # existing biblio, (not basket or order) +my $ordnum = $input->param('ordnum'); +my $basketno = $input->param('basketno'); +my $booksellerid = $input->param('booksellerid'); +my $existing = $input->param('existing'); # existing biblio, (not basket or order) my $title = $input->param('title'); my $author = $input->param('author'); my $copyrightdate = $input->param('copyrightdate'); my $isbn = $input->param('ISBN'); my $itemtype = $input->param('format'); -my $quantity = $input->param('quantity'); -my $listprice = $input->param('list_price'); +my $quantity = $input->param('quantity'); # FIXME: else ERROR! +my $listprice = $input->param('list_price') || 0; my $branch = $input->param('branch'); -if ( $listprice eq '' ) { - $listprice = 0; -} -my $series = $input->param('series'); +my $series = $input->param('series'); my $notes = $input->param('notes'); my $bookfund = $input->param('bookfund'); my $sort1 = $input->param('sort1'); @@ -178,8 +174,8 @@ my $createbibitem = $input->param('createbibitem'); # create, modify or delete biblio # create if $quantity>=0 and $existing='no' # modify if $quantity>=0 and $existing='yes' -# delete if $quantity has been se to 0 by the librarian -my $biblionumber=$input->param('biblionumber'); +# delete if $quantity has been set to 0 by the librarian +my $biblionumber = $input->param('biblionumber'); my $bibitemnum; if ( $quantity ne '0' ) { #check to see if biblio exists @@ -192,8 +188,8 @@ if ( $quantity ne '0' ) { "biblio.author" => "$author", "biblio.copyrightdate" => $copyrightdate ? $copyrightdate : "", "biblio.series" => $series ? $series : "", - "biblioitems.itemtype" => $itemtype ? $itemtype : "", - "biblioitems.isbn" => $isbn ? $isbn : "", + "biblioitems.itemtype" => $itemtype ? $itemtype : "", + "biblioitems.isbn" => $isbn ? $isbn : "", "biblioitems.publishercode" => $publishercode ? $publishercode : "", }); # create the record in catalogue, with framework '' diff --git a/acqui/neworderempty.pl b/acqui/neworderempty.pl index 809301560d..c9cfc07800 100755 --- a/acqui/neworderempty.pl +++ b/acqui/neworderempty.pl @@ -69,25 +69,24 @@ use C4::Input; use C4::Auth; use C4::Bookfund; -use C4::Bookseller; +use C4::Bookseller; # GetBookSellerFromId use C4::Acquisition; -use C4::Suggestions; -use C4::Biblio; +use C4::Suggestions; # GetSuggestion +use C4::Biblio; # GetBiblioData use C4::Output; use C4::Input; use C4::Koha; -use C4::Branch; # GetBranches +use C4::Branch; # GetBranches use C4::Members; my $input = new CGI; -my $booksellerid = $input->param('booksellerid'); +my $booksellerid = $input->param('booksellerid'); # FIXME: else ERROR! my $title = $input->param('title'); my $author = $input->param('author'); my $copyright = $input->param('copyright'); -my @booksellers = GetBookSeller($booksellerid); -my $count = scalar @booksellers; +my $bookseller = GetBookSellerFromId($booksellerid); # FIXME: else ERROR! my $ordnum = $input->param('ordnum'); -my $biblionumber = $input->param('biblionumber'); +my $biblionumber = $input->param('biblionumber'); my $basketno = $input->param('basketno'); my $purchaseorder= $input->param('purchaseordernumber'); my $suggestionid = $input->param('suggestionid'); @@ -108,18 +107,13 @@ if ( $ordnum eq '' ) { # create order # get suggestion fields if applicable. If it's a subscription renewal, then the biblio already exists # otherwise, retrieve suggestion information. if ($suggestionid) { - if ($biblionumber) { - $data = GetBiblioData($biblionumber); - } - else { - $data = GetSuggestion($suggestionid); - } + $data = ($biblionumber) ? GetBiblioData($biblionumber) : GetSuggestion($suggestionid); } } else { #modify order $data = GetOrder($ordnum); $biblionumber = $data->{'biblionumber'}; - #get basketno and suppleirno. too! + #get basketno and supplierno. too! my $data2 = GetBasket( $data->{'basketno'} ); $basketno = $data2->{'basketno'}; $booksellerid = $data2->{'booksellerid'}; @@ -138,7 +132,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( # get currencies (for change rates calcs if needed) my @rates = GetCurrencies(); -$count = scalar @rates; +my $count = scalar @rates; my @loop_currency = (); for ( my $i = 0 ; $i < $count ; $i++ ) { @@ -176,13 +170,11 @@ $template->param( branchloop => \@branchloop , itypeloop => \@itemtypesloop ); my $borrower= GetMember($loggedinuser); my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'}); -my $count2; -my @bookfund; my @select_bookfund; my %select_bookfunds; -@bookfund = GetBookFunds($homebranch); -$count2 = scalar @bookfund; +my @bookfund = GetBookFunds($homebranch); +my $count2 = scalar @bookfund; for ( my $i = 0 ; $i < $count2 ; $i++ ) { push @select_bookfund, $bookfund[$i]->{'bookfundid'}; @@ -191,12 +183,12 @@ for ( my $i = 0 ; $i < $count2 ; $i++ ) { } my $CGIbookfund = CGI::scrolling_list( -name => 'bookfund', - -id => 'bookfund', + -id => 'bookfund', -values => \@select_bookfund, -default => $data->{'bookfundid'}, -labels => \%select_bookfunds, - -size => 1, - -tabindex=>'', + #-size => 1, + -tabindex =>'', -multiple => 0 ); @@ -211,29 +203,23 @@ if ($close) { my $CGIsort1 = buildCGIsort( "Asort1", "sort1", $data->{'sort1'} ); if ($CGIsort1) { $template->param( CGIsort1 => $CGIsort1 ); -} -else { +} else { $template->param( sort1 => $data->{'sort1'} ); } my $CGIsort2 = buildCGIsort( "Asort2", "sort2", $data->{'sort2'} ); if ($CGIsort2) { $template->param( CGIsort2 => $CGIsort2 ); -} -else { +} else { $template->param( sort2 => $data->{'sort2'} ); } -my $bibitemsexists; - #do a biblioitems lookup on bib my @bibitems = GetBiblioItemByBiblioNumber($biblionumber); my $bibitemscount = scalar @bibitems; if ( $bibitemscount > 0 ) { # warn "NEWBIBLIO: bibitems for $biblio exists\n"; - $bibitemsexists = 1; - my @bibitemloop; for ( my $i = 0 ; $i < $bibitemscount ; $i++ ) { my %line; @@ -262,20 +248,20 @@ $template->param( basketno => $basketno, booksellerid => $booksellerid, suggestionid => $suggestionid, - biblionumber => $biblionumber, + biblionumber => $biblionumber, authorisedbyname => $borrower->{'firstname'} . " " . $borrower->{'surname'}, biblioitemnumber => $data->{'biblioitemnumber'}, itemtype => $data->{'itemtype'}, - itemtype_desc => $itemtypes->{$data->{'itemtype'}}->{description}, - discount => $booksellers[0]->{'discount'}, - listincgst => $booksellers[0]->{'listincgst'}, - listprice => $booksellers[0]->{'listprice'}, - gstreg => $booksellers[0]->{'gstreg'}, - invoiceinc => $booksellers[0]->{'invoiceincgst'}, - invoicedisc => $booksellers[0]->{'invoicedisc'}, - nocalc => $booksellers[0]->{'nocalc'}, - name => $booksellers[0]->{'name'}, - currency => $booksellers[0]->{'listprice'}, + itemtype_desc => $itemtypes->{$data->{'itemtype'}}->{description}, + discount => $bookseller->{'discount'}, + listincgst => $bookseller->{'listincgst'}, + listprice => $bookseller->{'listprice'}, + gstreg => $bookseller->{'gstreg'}, + invoiceinc => $bookseller->{'invoiceincgst'}, + invoicedisc => $bookseller->{'invoicedisc'}, + nocalc => $bookseller->{'nocalc'}, + name => $bookseller->{'name'}, + currency => $bookseller->{'listprice'}, gstrate => C4::Context->preference("gist"), loop_currencies => \@loop_currency, orderexists => ( $new eq 'yes' ) ? 0 : 1, @@ -291,7 +277,7 @@ $template->param( total => $data->{ecost}*$data->{quantity}, invoice => $data->{'booksellerinvoicenumber'}, ecost => $data->{'ecost'}, - purchaseordernumber => $data->{'purchaseordernumber'}, + purchaseordernumber => $data->{'purchaseordernumber'}, notes => $data->{'notes'}, publishercode => $data->{'publishercode'}, # donation => $donation -- 2.39.5