Bug 4969: deletion of suppliers
authorAdrien Saurat <adrien.saurat@biblibre.com>
Fri, 2 Mar 2012 13:23:17 +0000 (14:23 +0100)
committerPaul Poulain <paul.poulain@biblibre.com>
Tue, 13 Mar 2012 14:12:26 +0000 (15:12 +0100)
If a vendor/bookseller has no basket/subscription link, it can now
be deleted (after a JS confirmation).

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Verified that I can only delete vendors without linked orders or
subscriptions.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
C4/Bookseller.pm
acqui/supplier.pl
koha-tmpl/intranet-tmpl/prog/en/includes/acquisitions-toolbar.inc

index 6a91f99..f14bd02 100644 (file)
@@ -84,6 +84,9 @@ sub GetBookSellerFromId {
         ( $vendor->{basketcount} ) = $dbh->selectrow_array(
             'SELECT count(*) FROM aqbasket where booksellerid = ?',
             {}, $id );
+        ( $vendor->{subscriptioncount} ) = $dbh->selectrow_array(
+            'SELECT count(*) FROM subscription WHERE aqbooksellerid = ?',
+            {}, $id );
     }
     return $vendor;
 }
index 8896b3b..fdeef06 100755 (executable)
@@ -114,10 +114,15 @@ if ( $op eq 'display' ) {
         GST           => $tax_rate,
         default_tax   => defined($seller_gstrate),
         basketcount   => $supplier->{'basketcount'},
+        subscriptioncount   => $supplier->{'subscriptioncount'},
         contracts     => $contracts,
     );
 } elsif ( $op eq 'delete' ) {
-    DelBookseller($booksellerid);
+    # no further message needed for the user
+    # the DELETE button only appears in the template if basketcount == 0
+    if ( $supplier->{'basketcount'} == 0 ) {
+        DelBookseller($booksellerid);
+    }
     print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
     exit;
 } else {
index 37cdf7c..d8e2c1e 100644 (file)
@@ -16,6 +16,7 @@
         new YAHOO.widget.Button("newsupplier");
         new YAHOO.widget.Button("newbasket");
         new YAHOO.widget.Button("editsupplier");
+        new YAHOO.widget.Button("deletesupplier");
         new YAHOO.widget.Button("receive");
         new YAHOO.widget.Button("newcontract");
         new YAHOO.widget.Button("editcontracts");
@@ -46,6 +47,9 @@
         [% IF ( booksellerid ) %]
             [% IF ( CAN_user_acquisition_vendors_manage ) %]
                 <li><a id="editsupplier" href="/cgi-bin/koha/acqui/supplier.pl?booksellerid=[% booksellerid %]&amp;op=enter">Edit</a></li>
+                [% UNLESS ( basketcount OR subscriptioncount ) %]
+                    <li><a id="deletesupplier" href="javascript:confirm_deletion()">Delete</a></li>
+                [% END %]
                 <li><a id="newcontract" href="/cgi-bin/koha/admin/aqcontract.pl?op=add_form&booksellerid=[% booksellerid %]">New Contract</a></li>
                 <li><a id="editcontracts" href="/cgi-bin/koha/admin/aqcontract.pl?booksellerid=[% booksellerid %]">Contracts</a></li>
                 [% UNLESS ( basketcount ) %]