Bug 31374: Add privatenote column to table settings
[koha-ffzg.git] / admin / currency.pl
index 9c8f825..28dc2d2 100755 (executable)
 
 use Modern::Perl;
 use CGI qw ( -utf8 );
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Output;
+use C4::Output qw( output_html_with_http_headers );
 
-use Koha::Acquisition::Currency;
+use Koha::Acquisition::Booksellers;
 use Koha::Acquisition::Currencies;
+use Koha::Acquisition::Orders;
 
 my $input         = CGI->new;
 my $searchfield   = $input->param('searchfield') || $input->param('description') || q{};
@@ -38,8 +39,7 @@ our ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {   template_name   => 'admin/currency.tt',
         query           => $input,
         type            => 'intranet',
-        authnotrequired => 0,
-        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
+        flagsrequired   => { acquisition => 'currencies_manage' },
     }
 );
 
@@ -56,6 +56,7 @@ if ( $op eq 'add_form' ) {
     my $isocode       = $input->param('isocode');
     my $rate          = $input->param('rate');
     my $active        = $input->param('active');
+    my $p_sep_by_space = $input->param('p_sep_by_space');
     my $is_a_modif    = $input->param('is_a_modif');
 
     if ($is_a_modif) {
@@ -64,6 +65,7 @@ if ( $op eq 'add_form' ) {
         $currency->isocode($isocode);
         $currency->rate($rate);
         $currency->active($active);
+        $currency->p_sep_by_space($p_sep_by_space);
         eval { $currency->store; };
         if ($@) {
             push @messages, { type => 'error', code => 'error_on_update' };
@@ -77,6 +79,7 @@ if ( $op eq 'add_form' ) {
                 isocode  => $isocode,
                 rate     => $rate,
                 active   => $active,
+                p_sep_by_space => $p_sep_by_space,
             }
         );
         eval { $currency->store; };
@@ -91,14 +94,14 @@ if ( $op eq 'add_form' ) {
 } elsif ( $op eq 'delete_confirm' ) {
     my $currency = Koha::Acquisition::Currencies->find($currency_code);
 
-    # TODO rewrite the following when Koha::Acquisition::Orders will use Koha::Objects
-    my $schema = Koha::Database->schema;
-    my $nb_of_orders = $schema->resultset('Aqorder')->search( { currency => $currency->currency } )->count;
+    my $nb_of_orders = Koha::Acquisition::Orders->search( { currency => $currency->currency } )->count;
+    my $nb_of_vendors = Koha::Acquisition::Booksellers->search( { -or => { listprice => $currency->currency, invoiceprice => $currency->currency } })->count;
     $template->param(
         currency     => $currency,
         nb_of_orders => $nb_of_orders,
+        nb_of_vendors => $nb_of_vendors,
     );
-} elsif ( $op eq 'delete' ) {
+} elsif ( $op eq 'delete_confirmed' ) {
     my $currency = Koha::Acquisition::Currencies->find($currency_code);
     my $deleted = eval { $currency->delete; };