From 720bc7b37afbef964f4931f2fdf0dd59d090cc1a Mon Sep 17 00:00:00 2001 From: Paul POULAIN Date: Thu, 16 Aug 2007 12:28:45 +0200 Subject: [PATCH] adding supplier deletion feature. A supplier can be deleted ONLY if it has NO basket Signed-off-by: Chris Cormack --- C4/Bookseller.pm | 21 +++++++++++ acqui/supplier.pl | 7 +++- .../intranet-tmpl/prog/en/acqui/supplier.tmpl | 35 +++++++++++++------ 3 files changed, 52 insertions(+), 11 deletions(-) diff --git a/C4/Bookseller.pm b/C4/Bookseller.pm index fe0ce8bb45..f970774aaf 100755 --- a/C4/Bookseller.pm +++ b/C4/Bookseller.pm @@ -30,6 +30,7 @@ $VERSION = do { my @v = '$Revision$' =~ /\d+/g; shift(@v) . "." . join( "_", map @EXPORT = qw( &GetBookSeller &GetBooksellersWithLateOrders &ModBookseller + &DelBookseller &AddBookseller ); @@ -77,7 +78,13 @@ sub GetBookSeller { my $sth =$dbh->prepare($query); $sth->execute("$searchstring%", $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=?"); while ( my $data = $sth->fetchrow_hashref ) { + $sth2->execute($data->{id}); + ($data->{basketcount}) = $sth2->fetchrow(); + warn "COUNT : ".$data->{basketcount}; push( @results, $data ); } $sth->finish; @@ -240,6 +247,20 @@ sub ModBookseller { $sth->finish; } +=head2 DelBookseller + +&DelBookseller($booksellerid); + +delete the supplier identified by $booksellerid +This sub can be called only if the supplier has no order. + +=cut +sub DelBookseller { + my ($id) = @_; + my $dbh=C4::Context->dbh; + my $sth=$dbh->prepare("DELETE FROM aqbooksellers WHERE id=?"); + $sth->execute($id); +} END { } # module clean-up code here (global destructor) 1; diff --git a/acqui/supplier.pl b/acqui/supplier.pl index 1a8be5b4f5..e3bf2e0968 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -96,8 +96,13 @@ if ($op eq "display"){ invoiceprice=>$booksellers[0]->{'invoiceprice'}, listprice=>$booksellers[0]->{'listprice'}, GST => C4::Context->preference("gist"), + basketcount =>$booksellers[0]->{'basketcount'}, ); -}else{ +} elsif ($op eq 'delete') { + &DelBookseller($id); + print $query->redirect("/cgi-bin/koha/acqui/acqui-home.pl"); + exit; +} else { my @currencies = GetCurrencies(); my $count = scalar @currencies; diff --git a/koha-tmpl/intranet-tmpl/prog/en/acqui/supplier.tmpl b/koha-tmpl/intranet-tmpl/prog/en/acqui/supplier.tmpl index 91145fbc5f..a6c450d32c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/acqui/supplier.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/acqui/supplier.tmpl @@ -134,15 +134,24 @@

Information for :

Company details @@ -246,5 +255,11 @@
- + -- 2.39.5