Bug 5691 - Delete all items respects independentbranches system preferences
authorChris Cormack <chrisc@catalyst.net.nz>
Fri, 4 Feb 2011 00:45:57 +0000 (19:45 -0500)
committerChris Cormack <chrisc@catalyst.net.nz>
Fri, 4 Feb 2011 18:41:29 +0000 (07:41 +1300)
Squashed commit of the following:

commit 66cdb8804136803a3f626d183c8f192f61f3c7b1
Author: Chris Cormack <chrisc@catalyst.net.nz>
Date:   Fri Feb 4 12:55:10 2011 +1300

    Bug 5691: Updating copyright statement

commit 79ef6c269afc9c644c51709a7657542a0fc6d7d6
Author: Chris Cormack <chrisc@catalyst.net.nz>
Date:   Fri Feb 4 12:52:13 2011 +1300

    Bug 5691 - Fixing a syntax error and tidying up some formatting

commit a66485dba113c05ed51a3b4ff19f788e335aa1f6
Author: Henri-Damien LAURENT <henridamien.laurent@biblibre.com>
Date:   Tue Oct 5 17:23:55 2010 +0200

    (MT #1365) Delete all items

    Using DelItemCheck in cataloguing/additem.pl
    when deleting all items

commit fe845fd48ab22ff82ad6d8971c468c327b49f3c4
Author: Christophe Croullebois <christophe.croullebois@biblibre.com>
Date:   Wed Sep 22 11:39:28 2010 +0200

    (MT #1365) Delete all items

    Now if IndependantBranches is on and a user try to delete all items, only the items of his branch will be deleted.
    A message explain this fact.

Signed-off-by: Chris Nighswonger <cnighswonger@foundations.edu>
Followup: (MT #1365) Fixing up the English idiom
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Items.pm
cataloguing/additem.pl
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl

index c0d8701..0ea8b86 100644 (file)
@@ -1,6 +1,7 @@
 package C4::Items;
 
 # Copyright 2007 LibLime, Inc.
+# Parts Copyright Biblibre 2010
 #
 # This file is part of Koha.
 #
@@ -2043,21 +2044,31 @@ sub DelItemCheck {
     my $sth=$dbh->prepare("select * from issues i where i.itemnumber=?");
     $sth->execute($itemnumber);
 
-    my $onloan=$sth->fetchrow;
-
-    if ($onloan){
-        $error = "book_on_loan" 
-    }else{
-        # check it doesnt have a waiting reserve
-        $sth=$dbh->prepare("SELECT * FROM reserves WHERE (found = 'W' or found = 'T') AND itemnumber = ?");
-        $sth->execute($itemnumber);
-        my $reserve=$sth->fetchrow;
-        if ($reserve){
-            $error = "book_reserved";
-        }else{
-            DelItem($dbh, $biblionumber, $itemnumber);
-            return 1;
-        }
+    my $item = GetItem($itemnumber);
+    my $onloan = $sth->fetchrow;
+    if ($onloan) {
+        $error = "book_on_loan";
+    }
+    elsif (C4::Context->preference("IndependantBranches") and (C4::Context->userenv->{branch} ne $item->{C4::Context->preference("HomeOrHoldingBranch")||'homebranch'})){
+        $error = "not_same_branch";
+    } 
+    else {
+       if ($onloan){ 
+           $error = "book_on_loan" 
+       }
+       else {
+           # check it doesnt have a waiting reserve
+           $sth=$dbh->prepare("SELECT * FROM reserves WHERE (found = 'W' or found = 'T') AND itemnumber = ?");
+           $sth->execute($itemnumber);
+           my $reserve=$sth->fetchrow;
+           if ($reserve) {
+               $error = "book_reserved";
+           } 
+           else {
+               DelItem($dbh, $biblionumber, $itemnumber);
+               return 1;
+           }
+       }
     }
     return $error;
 }
index b79e7f5..7317698 100755 (executable)
@@ -435,14 +435,28 @@ if ($op eq "additem") {
 } elsif ($op eq "delallitems") {
 #-------------------------------------------------------------------------------
     my @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber);
-    foreach my $biblioitem (@biblioitems){
-        my $items = &GetItemsByBiblioitemnumber($biblioitem->{biblioitemnumber});
-
-        foreach my $item (@$items){
-            # FIXME although it won't delete items that have loans
-            # or waiting holds on them, should explicitly tell operator
-            # about items that are not deleted
-            &DelItemCheck($dbh,$biblionumber,$item->{itemnumber});
+    my $errortest=0;
+    my $itemfail;
+    foreach my $biblioitem (@biblioitems) {
+        my $items = &GetItemsByBiblioitemnumber( $biblioitem->{biblioitemnumber} );
+
+        foreach my $item (@$items) {
+            $error =&DelItemCheck( $dbh, $biblionumber, $item->{itemnumber} );
+            $itemfail =$item;
+        if($error == 1){
+            next
+            }
+        else {
+            push @errors,$error;
+            $errortest++
+            }
+        }
+        if($errortest > 0){
+            $nextop="additem";
+        } 
+        else {
+            print $input->redirect("/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=$biblionumber");
+            exit;
         }
        }
 #-------------------------------------------------------------------------------
index d0be875..6a32740 100644 (file)
@@ -191,6 +191,7 @@ function set_to_today(id, force) {
 <!-- TMPL_IF NAME="no_next_barcode" --><div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="book_on_loan" --><div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="book_reserved" --><div class="dialogalert"><strong>Cannot Delete</strong>: item has a waiting hold.</div><!-- /TMPL_IF -->
+<!-- TMPL_IF Name="not_same_branch" --><div class="dialog alert"><strong>Cannot Delete</strong>: The items do not belong to your branch.</div><!-- /TMPL_IF -->
 
 <div id="cataloguing_additem_itemlist">
     <!-- TMPL_IF name="item_loop" -->