adding supplier deletion feature.
authorPaul POULAIN <paul@koha-fr.org>
Thu, 16 Aug 2007 10:28:45 +0000 (12:28 +0200)
committerChris Cormack <crc@liblime.com>
Thu, 16 Aug 2007 11:56:00 +0000 (06:56 -0500)
A supplier can be deleted ONLY if it has NO basket

Signed-off-by: Chris Cormack <crc@liblime.com>
C4/Bookseller.pm
acqui/supplier.pl
koha-tmpl/intranet-tmpl/prog/en/acqui/supplier.tmpl

index fe0ce8b..f970774 100755 (executable)
@@ -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;
index 1a8be5b..e3bf2e0 100755 (executable)
@@ -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;
     
index 91145fb..a6c450d 100644 (file)
 <!--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>
         </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" -->