adding supplier deletion feature.

A supplier can be deleted ONLY if it has NO basket

Signed-off-by: Chris Cormack <crc@liblime.com>
This commit is contained in:
Paul POULAIN 2007-08-16 12:28:45 +02:00 committed by Chris Cormack
parent 836b9857ed
commit 720bc7b37a
3 changed files with 52 additions and 11 deletions

View File

@ -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;

View File

@ -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;

View File

@ -134,15 +134,24 @@
<!--TMPL_ELSE-->
<h1>Information for : <!-- TMPL_VAR NAME="name" --></h1>
<div id="action">
<a href="supplier.pl?supplierid=<!--TMPL_VAR Name="id"-->&op=enter">
Edit Supplier
</a>
<a href="booksellers.pl?supplier=<!--TMPL_VAR Name="id"-->">
Manage Orders
</a>
<a href="parcels.pl?supplierid=<!--TMPL_VAR Name="id"-->">
Receive Parcel
</a>
<div class="edit">
<a href="supplier.pl?supplierid=<!--TMPL_VAR Name="id"-->&op=enter">
Edit Supplier
</a>
<!-- TMPL_UNLESS name="basketcount" -->
<a href="javascript:confirm_deletion()">
Delete Supplier
</a>
<!-- /TMPL_UNLESS -->
</div>
<div class="view">
<a href="booksellers.pl?supplier=<!--TMPL_VAR Name="id"-->">
Manage Orders
</a>
<a href="parcels.pl?supplierid=<!--TMPL_VAR Name="id"-->">
Receive Parcel
</a>
</div>
</div>
<fieldset>
<legend>Company details</legend>
@ -246,5 +255,11 @@
</fieldset>
</div>
<!--/TMPL_IF-->
<script>
function confirm_deletion() {
if (confirm("Confirm deletion of this supplier ?")) {
window.location="/cgi-bin/koha/acqui/supplier.pl?supplierid=<!--TMPL_VAR Name="id"-->&op=delete";
}
}
</script>
<!-- TMPL_INCLUDE name="intranet-bottom.inc" -->