From 18b8a1c659ce4c8245d79ea51c725c4d04f0fb0f Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Wed, 23 Jan 2008 15:04:24 -0600 Subject: [PATCH] Fix for bug 1791 Signed-off-by: Joshua Ferraro --- C4/Bookseller.pm | 30 ++++++++++++++----- acqui/basket.pl | 30 +++++++++---------- .../prog/en/modules/acqui/basket.tmpl | 6 ++-- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index e5feff2cfe..c549d820b1 100644 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -26,7 +26,7 @@ BEGIN { $VERSION = 3.01; @ISA = qw(Exporter); @EXPORT = qw( - &GetBookSeller &GetBooksellersWithLateOrders + &GetBookSeller &GetBooksellersWithLateOrders &GetBookSellerFromId &ModBookseller &DelBookseller &AddBookseller @@ -65,17 +65,13 @@ aqbooksellers table in the Koha database. sub GetBookSeller { my ($searchstring) = @_; my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM aqbooksellers - WHERE name LIKE ? OR id = ? - "; + my $query = "SELECT * FROM aqbooksellers WHERE name LIKE ?"; my $sth =$dbh->prepare($query); - $sth->execute("$searchstring%", $searchstring ); + $sth->execute( "$searchstring%" ); my @results; # count how many baskets this bookseller has. # if it has none, the bookseller can be deleted - my $sth2 = $dbh->prepare("select count(*) from aqbasket where booksellerid=?"); + my $sth2 = $dbh->prepare("SELECT count(*) FROM aqbasket WHERE booksellerid=?"); while ( my $data = $sth->fetchrow_hashref ) { $sth2->execute($data->{id}); ($data->{basketcount}) = $sth2->fetchrow(); @@ -86,6 +82,24 @@ sub GetBookSeller { } +sub GetBookSellerFromId { + my ($id) = @_; + 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=?"); + $sth2->execute($id); + $data->{basketcount}=$sth2->fetchrow(); + $sth->finish; + $sth2->finish; + return ($data); + } + else { + return 0; + } +} #-----------------------------------------------------------------# =head2 GetBooksellersWithLateOrders diff --git a/acqui/basket.pl b/acqui/basket.pl index 0208c2f6c5..5f071e9659 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -86,13 +86,12 @@ my $basket = GetBasket($basketno); # if no booksellerid in parameter, get it from basket # warn "=>".$basket->{booksellerid}; $booksellerid = $basket->{booksellerid} unless $booksellerid; -my @booksellers = GetBookSeller($booksellerid); -my $count2 = scalar @booksellers; -# FIXME: do something with count2? -# FIXME: how do you know the first BookSeller in the array is the one you want? -# FIXME: GetBookSeller should be changing to reliably return 1 record based on ID, -# but we still should give some kind of Error back to the user if it fails. +my ($bookseller) = GetBookSellerFromId($booksellerid); +if (! $bookseller){ + $template->param( NO_BOOKSELLER => 1 ); +} +else { # get librarian branch... if ( C4::Context->preference("IndependantBranches") ) { my $userenv = C4::Context->userenv; @@ -164,7 +163,7 @@ my $prefgist = C4::Context->preference("gist"); $gist = sprintf( "%.2f", $sub_total * $prefgist ); $grand_total = $sub_total; $grand_total_est = $sub_total_est; -unless ($booksellers[0]->{'listincgst'}) { +unless ($bookseller->{'listincgst'}) { $grand_total += $gist; $grand_total_est += sprintf( "%.2f", $sub_total_est * $prefgist ); } @@ -176,13 +175,13 @@ $template->param( authorisedby => $basket->{authorisedby}, authorisedbyname => $basket->{authorisedbyname}, closedate => format_date( $basket->{closedate} ), - active => $booksellers[0]->{'active'}, - booksellerid => $booksellers[0]->{'id'}, - name => $booksellers[0]->{'name'}, - address1 => $booksellers[0]->{'address1'}, - address2 => $booksellers[0]->{'address2'}, - address3 => $booksellers[0]->{'address3'}, - address4 => $booksellers[0]->{'address4'}, + active => $bookseller->{'active'}, + booksellerid => $bookseller->{'id'}, + name => $bookseller->{'name'}, + address1 => $bookseller->{'address1'}, + address2 => $bookseller->{'address2'}, + address3 => $bookseller->{'address3'}, + address4 => $bookseller->{'address4'}, entrydate => format_date( $results[0]->{'entrydate'} ), books_loop => \@books_loop, count => $count, @@ -193,8 +192,9 @@ $template->param( gist_est => $gist_est, grand_total_est => $grand_total_est, grand_total_rrp => $grand_total_rrp, - currency => $booksellers[0]->{'listprice'}, + currency => $bookseller->{'listprice'}, qty_total => $qty_total, GST => $prefgist, ); + } output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl index 218555de8c..db774fe5e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tmpl @@ -26,7 +26,9 @@
- + +

Supplier Not Found

+

New Basket for ">

@@ -148,7 +150,7 @@
- +
-- 2.39.5