[Koha-patches] [PATCH] Bug 7791 : Give the ability to delete records when deleting a basket

Mathieu Saby mathieu.saby at univ-rennes2.fr
Thu Sep 19 10:37:09 CEST 2013


Currently, when a basket is deleted, all the orders are deleted (there is a foreign key in aqorders table on basketno).
This could be dangerous, and there is no warn.
After the deletion, unused biblios are left in the catalogue.
This patch
- adds a more detailed message describing the consequences of deletion
- give the choice of also deleting biblio records if possible

To test :
Test A : 
1. create a basket with 4 orders:
- an order from a new record A
- an order from a record B which has already an item
- an order from a record C used in a subscription
- an order from a record D used in an other order
2. note the biblionumbers of the records used (or open them in other tabs in yout browser)
3. click on "Delete basket"
4. choose button "Delete basket and orders"
5. check the catalogue : records A,B,C,D must still be there
Test B:
1. create a basket with 4 orders:
- an order from a new record A
- an order from a record B which has already an item
- an order from a record C used in a subscription
- an order from a record D used in an other order
2. note the biblionumbers of the records used (or open them in other tabs in yout browser)
3. click on "Delete basket"
4. choose button "Delete basket, orders and records"
5. check the catalogue : records B,C,D must still be there. Record A must be deleted

---
 acqui/basket.pl                                    |   24 +++++++++++-
 .../intranet-tmpl/prog/en/modules/acqui/basket.tt  |   40 +++++++++++++-------
 2 files changed, 49 insertions(+), 15 deletions(-)

diff --git a/acqui/basket.pl b/acqui/basket.pl
index 681cd60..313cef8 100755
--- a/acqui/basket.pl
+++ b/acqui/basket.pl
@@ -97,7 +97,27 @@ $template->param( skip_confirm_reopen => 1) if $confirm_pref eq '2';
 
 if ( $op eq 'delete_confirm' ) {
     my $basketno = $query->param('basketno');
-    DelBasket($basketno);
+    my $delbiblio = $query->param('delbiblio');
+    my @orders = GetOrders($basketno);
+#Delete all orders included in that basket, and all items received.
+    foreach my $myorder (@orders){
+        DelOrder($myorder->{biblionumber},$myorder->{ordernumber});
+        warn "suppression de ".$myorder->{biblionumber}.'  '.$myorder->{ordernumber};
+    }
+# if $delbiblio = 1, delete the records if possible
+    if ((defined $delbiblio)and ($delbiblio ==1)){
+        foreach my $myorder (@orders){
+            my $biblionumber = $myorder->{'biblionumber'};
+            my $countbiblio = CountBiblioInOrders($biblionumber);
+            my $ordernumber = $myorder->{'ordernumber'};
+            my @subscriptions = GetSubscriptionsId ($biblionumber);
+            my $itemcount = GetItemsCount($biblionumber);
+            DelBiblio($myorder->{biblionumber}) if ($countbiblio == 0 && $itemcount == 0 && !(@subscriptions));
+        warn "suppression de la notice ".$myorder->{biblionumber}};
+    }
+
+ # delete the basket
+    DelBasket($basketno,);
     $template->param( delete_confirmed => 1 );
 } elsif ( !$bookseller ) {
     $template->param( NO_BOOKSELLER => 1 );
@@ -399,7 +419,7 @@ sub get_order_infos {
         if ($nb){
             $itemholds += $nb;
         }
-    }
+    }
     # if the biblio is not in other orders and if there is no items elsewhere and no subscriptions and no holds we can then show the link "Delete order and Biblio" see bug 5680
     $line{can_del_bib}          = 1 if $countbiblio <= 1 && $itemcount == scalar @items && !(@subscriptions) && !($holds);
     $line{items}                = ($itemcount) - (scalar @items);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
index 67e299d..e7c6bbb 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt
@@ -43,12 +43,11 @@
                     window.location = "[% script_name %]?op=close&basketno=[% basketno %]";
                 }
             }
-            function confirm_deletion() {
-                var is_confirmed = confirm(_("Are you sure you want to delete this basket?"));
-                if (is_confirmed) {
-                    window.location = "[% script_name %]?op=delete_confirm&basketno=[% basketno %]&booksellerid=[% booksellerid %]";
-                }
+
+            function delete_basket(basketno,booksellerid,delbiblio) {
+                window.location = "[% script_name %]?op=delete_confirm&delbiblio="+delbiblio+"&basketno="+basketno+"&booksellerid="+booksellerid;
             }
+
             function confirm_delete_item(ordernumber, biblionumber) {
                 var is_confirmed = confirm(_("Are you sure you want to delete this order ?"));
                 if (is_confirmed) {
@@ -112,11 +111,7 @@
         } ) );
         var cancelledorderst = $("#cancelledorderst").dataTable($.extend(true, {}, dataTablesDefaults, {
             "sPaginationType": "four_button"
-        } ) );
-        $("#delbasketbutton").on("click",function(e){
-            e.preventDefault();
-            confirm_deletion();
-        });
+        } ) );
         $("#reopenbutton").on("click",function(e){
             e.preventDefault();
             confirm_reopen();
@@ -147,8 +142,8 @@
                 <div id="toolbar" class="btn-toolbar">
                     <div class="btn-group"><a href="#addtoBasket" role="button" class="btn btn-small" data-toggle="modal"><i class="icon-plus"></i> Add to basket</a></div>
                     <div class="btn-group"><a href="basketheader.pl?booksellerid=[% booksellerid %]&basketno=[% basketno %]&op=add_form" class="btn btn-small" id="basketheadbutton"><i class="icon-pencil"></i> Edit basket</a></div>
-                    <div class="btn-group"><a href="#" class="btn btn-small" id="delbasketbutton"><i class="icon-remove"></i> Delete this basket</a></div>
-                    [% IF ( unclosable ) %]
+                    <div class="btn-group"><a href="#deleteBasketModal" role="button" class="btn btn-small" data-toggle="modal" id="delbasketbutton"><i class="icon-remove"></i> Delete this basket</a></div>
+                   [% IF ( unclosable ) %]
                     [% ELSIF ( uncertainprices ) %]
                         <div class="btn-group"><a href="/cgi-bin/koha/acqui/uncertainprice.pl?booksellerid=[% booksellerid %]&owner=1" class="btn btn-small" id="uncertpricesbutton">Uncertain prices</a></div>
                     [% ELSE %]
@@ -157,8 +152,27 @@
                         </div>
                     [% END %]
                         <div class="btn-group"><a href="[% script_name %]?op=export&basketno=[% basketno %]&booksellerid=[% booksellerid %]" class="btn btn-small" id="exportbutton"><i class="icon-download"></i> Export this basket as CSV</a></div>
-
                 </div>
+            <!-- Modal for confirm deletion box-->
+                <div class="modal hide" id="deleteBasketModal" tabindex="-1" role="dialog" aria-labelledby="delbasketModalLabel" aria-hidden="true">
+                    <div class="modal-header">
+                        <button type="button" class="closebtn" data-dismiss="modal" aria-hidden="true">×</button>
+                        <h3>Confirm deletion</h3>
+                    </div>
+                    <div class="modal-body">
+                       <p>Are you sure you want to delete this basket?</p>
+                       <p>Warning:</p>
+                       <p>All orders of this basket will be cancelled and used funds will be refunded.</p>
+                       <p>If items have been created at ordering or receipt stage, they will be deleted.</p>
+                       <p>You can choose to delete records if possible (if they don't have any item attached, any subscription and any other order).</p>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
+                        <button type="submit" class="btn btn-default" onclick="delete_basket([% basketno %],[% booksellerid %],0); return false;" >Delete basket and orders</button>
+                        <button type="submit" class="btn btn-default" onclick="delete_basket([% basketno %],[% booksellerid %],1); return false;">Delete basket, orders and records</button>
+                    </div>
+                </div>
+            <!-- End of Modal-->
             [% ELSE %]
                 [% UNLESS ( grouped ) %]
                 <div id="toolbar" class="btn-toolbar">
-- 
1.7.9.5


-- 
Mathieu Saby
Service d'Informatique Documentaire
Service Commun de la Documentation
Université Rennes 2
Téléphone : 02 99 14 12 65
Courriel : mathieu.saby at univ-rennes2.fr



More information about the Koha-patches mailing list