Bug 13407: Bumping required version of PDF::Reuse
[koha.git] / admin / aqcontract.pl
index 9d3f0ac..8997c31 100755 (executable)
@@ -27,18 +27,19 @@ use C4::Context;
 use C4::Auth;
 use C4::Output;
 use C4::Dates qw/format_date format_date_in_iso/;
-use C4::Bookseller qw/GetBookSellerFromId/;
 use C4::Contract;
 
+use Koha::Acquisition::Bookseller;
+
 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);
+my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
-    {   template_name   => "admin/aqcontract.tmpl",
+    {   template_name   => "admin/aqcontract.tt",
         query           => $input,
         type            => "intranet",
         authnotrequired => 0,
@@ -51,8 +52,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
@@ -61,8 +62,9 @@ if ( $op eq 'add_form' ) {
 
    # if contractnumber exists, it's a modify action, so read values to modify...
     if ($contractnumber) {
-        my $contract =
-          @{ GetContract( { contractnumber => $contractnumber } ) }[0];
+        my $contract = GetContract({
+            contractnumber => $contractnumber
+        });
 
         $template->param(
             contractnumber      => $contract->{contractnumber},
@@ -70,7 +72,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 +80,6 @@ if ( $op eq 'add_form' ) {
             contractdescription      => undef,
             contractstartdate        => undef,
             contractenddate          => undef,
-            DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar,
         );
     }
 
@@ -120,7 +120,7 @@ elsif ( $op eq 'add_validate' ) {
 elsif ( $op eq 'delete_confirm' ) {
     $template->param( delete_confirm => 1 );
 
-    my $contract = @{GetContract( { contractnumber => $contractnumber } )}[0];
+    my $contract = GetContract( { contractnumber => $contractnumber } );
 
     $template->param(
         contractnumber      => $$contract{contractnumber},
@@ -134,21 +134,24 @@ 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?booksellerid=$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
-    my @contracts = @{GetContract( { booksellerid => $booksellerid } )};
+    my @contracts = @{GetContracts( { booksellerid => $booksellerid } )};
 
     # format dates
     for ( @contracts ) {