Bug 12508: adding an error message if a contract cannot be removed
[koha_fer] / admin / aqcontract.pl
index 7126c99..43a6b0a 100755 (executable)
@@ -33,7 +33,7 @@ use C4::Contract;
 my $input          = new CGI;
 my $contractnumber = $input->param('contractnumber');
 my $booksellerid   = $input->param('booksellerid');
-my $op             = $input->param('op') || '';
+my $op             = $input->param('op') || 'list';
 
 my $bookseller = GetBookSellerFromId($booksellerid);
 
@@ -51,8 +51,8 @@ $template->param(
     contractnumber => $contractnumber,
     booksellerid   => $booksellerid,
     booksellername => $bookseller->{name},
-    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
-    dateformat     => C4::Context->preference("dateformat"),
+    basketcount   => $bookseller->{'basketcount'},
+    subscriptioncount   => $bookseller->{'subscriptioncount'},
 );
 
 #ADD_FORM: called if $op is 'add_form'. Used to create form to add or  modify a record
@@ -70,7 +70,6 @@ if ( $op eq 'add_form' ) {
             contractdescription => $contract->{contractdescription},
             contractstartdate => format_date( $contract->{contractstartdate} ),
             contractenddate   => format_date( $contract->{contractenddate} ),
-            DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar,
         );
     } else {
         $template->param(
@@ -79,7 +78,6 @@ if ( $op eq 'add_form' ) {
             contractdescription      => undef,
             contractstartdate        => undef,
             contractenddate          => undef,
-            DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar,
         );
     }
 
@@ -111,7 +109,7 @@ elsif ( $op eq 'add_validate' ) {
         });
     }
 
-    print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid");
+    print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
     exit;
 
     # END $OP eq ADD_VALIDATE
@@ -134,17 +132,20 @@ elsif ( $op eq 'delete_confirm' ) {
 }
 #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
 elsif ( $op eq 'delete_confirmed' ) {
-    $template->param( delete_confirmed => 1 );
+    my $deleted = DelContract( { contractnumber => $contractnumber } );
 
-    DelContract( { contractnumber => $contractnumber } );
-
-    print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?supplierid=$booksellerid");
-    exit;
+    if ( $deleted ) {
+        print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
+        exit;
+    } else {
+        $template->param( error => 'not_deleted' );
+        $op = 'list';
+    }
 
-    # END $OP eq DELETE_CONFIRMED
+    # END $OP eq LIST
 }
 # DEFAULT: Builds a list of contracts and displays them
-else {
+if ( $op eq 'list' ) {
     $template->param(else => 1);
 
     # get contracts