Bug 11030 - Add 359, 947 and 969 fields in french unimarc_complete framework - followup
[koha_fer] / acqui / basket.pl
index df37788..4f2a37e 100755 (executable)
@@ -115,20 +115,36 @@ if ( $op eq 'delete_confirm' ) {
 #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)){
+        my @cannotdelbiblios ;
         foreach my $myorder (@orders){
             my $biblionumber = $myorder->{'biblionumber'};
             my $countbiblio = CountBiblioInOrders($biblionumber);
             my $ordernumber = $myorder->{'ordernumber'};
-            my @subscriptions = GetSubscriptionsId ($biblionumber);
+            my $subscriptions = scalar GetSubscriptionsId ($biblionumber);
             my $itemcount = GetItemsCount($biblionumber);
-            DelBiblio($myorder->{biblionumber}) if ($countbiblio == 0 && $itemcount == 0 && !(@subscriptions));
-        warn "suppression de la notice ".$myorder->{biblionumber}};
+            my $error;
+            if ($countbiblio == 0 && $itemcount == 0 && $subscriptions == 0) {
+                $error = DelBiblio($myorder->{biblionumber}) }
+            else {
+                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
+                                         title=> $myorder->{'title'},
+                                         author=> $myorder->{'author'},
+                                         countbiblio=> $countbiblio,
+                                         itemcount=>$itemcount,
+                                         subscriptions=>$subscriptions};
+            }
+            if ($error) {
+                push @cannotdelbiblios, {biblionumber=> ($myorder->{biblionumber}),
+                                         title=> $myorder->{'title'},
+                                         author=> $myorder->{'author'},
+                                         othererror=> $error};
+            }
+        }
+        $template->param( cannotdelbiblios => \@cannotdelbiblios );
     }
-
  # delete the basket
     DelBasket($basketno,);
     $template->param( delete_confirmed => 1 );
@@ -138,7 +154,7 @@ if ( $op eq 'delete_confirm' ) {
     $template->param( delete_confirm => 1 );
     if ( C4::Context->preference("IndependentBranches") ) {
         my $userenv = C4::Context->userenv;
-        unless ( $userenv->{flags} == 1 ) {
+        unless ( C4::Context->IsSuperLibrarian() ) {
             my $validtest = ( $basket->{creationdate} eq '' )
               || ( $userenv->{branch} eq $basket->{branch} )
               || ( $userenv->{branch} eq '' )
@@ -173,9 +189,6 @@ if ( $op eq 'delete_confirm' ) {
         address3             => $bookseller->{'address3'},
         address4             => $bookseller->{'address4'},
       );
-} elsif ($op eq 'attachbasket' && $template->{'VARS'}->{'CAN_user_acquisition_group_manage'} == 1) {
-      print $query->redirect('/cgi-bin/koha/acqui/basketgroup.pl?basketno=' . $basket->{'basketno'} . '&op=attachbasket&booksellerid=' . $booksellerid);
-    # check if we have to "close" a basket before building page
 } elsif ($op eq 'export') {
     print $query->header(
         -type       => 'text/csv',
@@ -241,7 +254,7 @@ if ( $op eq 'delete_confirm' ) {
     # get librarian branch...
     if ( C4::Context->preference("IndependentBranches") ) {
         my $userenv = C4::Context->userenv;
-        unless ( $userenv->{flags} == 1 ) {
+        unless ( C4::Context->IsSuperLibrarian() ) {
             my $validtest = ( $basket->{creationdate} eq '' )
               || ( $userenv->{branch} eq $basket->{branch} )
               || ( $userenv->{branch} eq '' )
@@ -290,13 +303,6 @@ if ( $op eq 'delete_confirm' ) {
                 $basketgroup = $bg;
             }
         }
-        my %emptygroup = ( id   =>   undef,
-                           name =>   "No group");
-        if ( ! $basket->{basketgroupid} ) {
-            $emptygroup{default} = 1;
-            $emptygroup{nogroup} = 1;
-        }
-        unshift( @$basketgroups, \%emptygroup );
     }
 
     # if the basket is closed, calculate estimated delivery date