Bug 6554: Followup for serial search
[koha_fer] / serials / subscription-detail.pl
index 53b5ee2..8bfee43 100755 (executable)
 # with Koha; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI;
+use C4::Acquisition;
 use C4::Auth;
+use C4::Bookseller qw/GetBookSellerFromId/;
+use C4::Budgets;
 use C4::Koha;
 use C4::Dates qw/format_date/;
 use C4::Serials;
@@ -34,6 +36,13 @@ my $issueconfirmed = $query->param('issueconfirmed');
 my $dbh = C4::Context->dbh;
 my ($template, $loggedinuser, $cookie, $hemisphere);
 my $subscriptionid = $query->param('subscriptionid');
+
+if ( $op and $op eq "close" ) {
+    C4::Serials::CloseSubscription( $subscriptionid );
+} elsif ( $op and $op eq "reopen" ) {
+    C4::Serials::ReopenSubscription( $subscriptionid );
+}
+
 my $subs = GetSubscription($subscriptionid);
 
 $subs->{enddate} = GetExpirationDate($subscriptionid);
@@ -141,13 +150,13 @@ if ( defined $subscriptionid ) {
         $tmpl_infos->{valuegsti_spent} = sprintf( "%.2f", $tmpl_infos->{valuegsti_spent} );
         $tmpl_infos->{valuegste_spent} = sprintf( "%.2f", $tmpl_infos->{valuegste_spent} );
         $tmpl_infos->{budget_name_spent} = GetBudgetName $lastOrderReceived->{budget_id};
-        $tmpl_infos->{invoicenumber} = $lastOrderReceived->{booksellerinvoicenumber};
+        $tmpl_infos->{invoiceid} = $lastOrderReceived->{invoiceid};
         $tmpl_infos->{spent_exists} = 1;
     }
 }
 
 $template->param(
-       subscriptionid => $subscriptionid,
+    subscriptionid => $subscriptionid,
     serialslist => \@serialslist,
     hasRouting  => $hasRouting,
     routing => C4::Context->preference("RoutingSerials"),
@@ -167,7 +176,9 @@ $template->param(
     default_bib_view => $default_bib_view,
     (uc(C4::Context->preference("marcflavour"))) => 1,
     show_acquisition_details => defined $tmpl_infos->{ordered_exists} || defined $tmpl_infos->{spent_exists} ? 1 : 0,
-    );
+    basketno => $order->{basketno},
+    %$tmpl_infos,
+);
 
 output_html_with_http_headers $query, $cookie, $template->output;
 
@@ -185,3 +196,36 @@ sub get_default_view {
     }
     return 'detail';
 }
+
+sub get_value_with_gst_params {
+    my $value = shift;
+    my $gstrate = shift;
+    my $bookseller = shift;
+    if ( $bookseller->{listincgst} ) {
+        return ( $value, $value / ( 1 + $gstrate ) );
+    } else {
+        return ( $value * ( 1 + $gstrate ), $value );
+    }
+}
+
+sub get_gste {
+    my $value = shift;
+    my $gstrate = shift;
+    my $bookseller = shift;
+    if ( $bookseller->{invoiceincgst} ) {
+        return $value / ( 1 + $gstrate );
+    } else {
+        return $value;
+    }
+}
+
+sub get_gst {
+    my $value = shift;
+    my $gstrate = shift;
+    my $bookseller = shift;
+    if ( $bookseller->{invoiceincgst} ) {
+        return $value / ( 1 + $gstrate ) * $gstrate;
+    } else {
+        return $value * ( 1 + $gstrate ) - $value;
+    }
+}