Bug 15004: Allow to change amounts of duplicated budgets
[koha-ffzg.git] / admin / aqbudgetperiods.pl
index 808f9cb..93cef8a 100755 (executable)
@@ -5,18 +5,18 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 =head1 admin/aqbudgetperiods.pl
 
@@ -46,8 +46,7 @@ script to administer the budget periods table
 
 use Modern::Perl;
 
-use Number::Format qw(format_price);
-use CGI;
+use CGI qw ( -utf8 );
 use List::Util qw/min/;
 use Koha::DateUtils;
 use Koha::Database;
@@ -91,30 +90,11 @@ my ($template, $borrowernumber, $cookie, $staff_flags ) = get_template_and_user(
 );
 
 
+# This is used in incbudgets-active-currency.inc
 my $cur = GetCurrency();
 $template->param( symbol => $cur->{symbol},
                   currency => $cur->{currency}
                );
-my $cur_format = C4::Context->preference("CurrencyFormat");
-my $num;
-
-if ( $cur_format eq 'US' ) {
-    $num = new Number::Format(
-        'int_curr_symbol'   => '',
-        'mon_thousands_sep' => ',',
-        'mon_decimal_point' => '.'
-    );
-} elsif ( $cur_format eq 'FR' ) {
-    $num = new Number::Format(
-        'decimal_fill'      => '2',
-        'decimal_point'     => ',',
-        'int_curr_symbol'   => '',
-        'mon_thousands_sep' => ' ',
-        'thousands_sep'     => ' ',
-        'mon_decimal_point' => ','
-    );
-}
-
 
 # ADD OR MODIFY A BUDGET PERIOD - BUILD SCREEN
 if ( $op eq 'add_form' ) {
@@ -125,14 +105,6 @@ if ( $op eq 'add_form' ) {
                my $budgetperiod_hash=GetBudgetPeriod($budget_period_id);
         # get dropboxes
 
-        my $editnum = new Number::Format(
-            'int_curr_symbol'   => '',
-            'thousands_sep'     => '',
-            'mon_thousands_sep' => '',
-            'mon_decimal_point' => '.'
-        );
-
-        $$budgetperiod_hash{budget_period_total}= $editnum->format_price($$budgetperiod_hash{'budget_period_total'});
         $template->param(
                        %$budgetperiod_hash
         );
@@ -161,7 +133,6 @@ elsif ( $op eq 'delete_confirm' ) {
     my $total = 0;
     my $data = GetBudgetPeriod( $budget_period_id);
 
-       $$data{'budget_period_total'}=$num->format_price(  $data->{'budget_period_total'});
     $template->param(
                %$data
     );
@@ -177,9 +148,11 @@ elsif ( $op eq 'delete_confirmed' ) {
 
 # display the form for duplicating
 elsif ( $op eq 'duplicate_form'){
+    my $budgetperiod = GetBudgetPeriod($budget_period_id, $input);
     $template->param(
         'duplicate_form' => '1',
         'budget_period_id' => $budget_period_id,
+        'budgetperiod' => $budgetperiod,
     );
 }
 
@@ -189,6 +162,9 @@ elsif ( $op eq 'duplicate_budget' ){
 
     my $budget_period_startdate = dt_from_string $input->param('budget_period_startdate');
     my $budget_period_enddate   = dt_from_string $input->param('budget_period_enddate');
+    my $budget_period_description = $input->param('budget_period_description');
+    my $amount_change_percentage = $input->param('amount_change_percentage');
+    my $amount_change_round_increment = $input->param('amount_change_round_increment');
     my $mark_original_budget_as_inactive = $input->param('mark_original_budget_as_inactive');
     my $reset_all_budgets = $input->param('reset_all_budgets');
 
@@ -197,6 +173,9 @@ elsif ( $op eq 'duplicate_budget' ){
             budget_period_id        => $budget_period_id,
             budget_period_startdate => $budget_period_startdate,
             budget_period_enddate   => $budget_period_enddate,
+            budget_period_description => $budget_period_description,
+            amount_change_percentage => $amount_change_percentage,
+            amount_change_round_increment => $amount_change_round_increment,
             mark_original_budget_as_inactive => $mark_original_budget_as_inactive,
             reset_all_budgets => $reset_all_budgets,
         }
@@ -287,7 +266,6 @@ my @period_active_loop;
 
 foreach my $result ( @{$results}[ $first .. $last ] ) {
     my $budgetperiod = $result;
-    $budgetperiod->{'budget_period_total'}     = $num->format_price( $budgetperiod->{'budget_period_total'} );
     $budgetperiod->{budget_active} = 1;
     push( @period_active_loop, $budgetperiod );
 }
@@ -306,7 +284,6 @@ $last = min( $first + $inactivepagesize - 1, scalar @{$results} - 1, );
 my @period_inactive_loop;
 foreach my $result ( @{$results}[ $first .. $last ] ) {
     my $budgetperiod = $result;
-    $budgetperiod->{'budget_period_total'} = $num->format_price( $budgetperiod->{'budget_period_total'} );
     $budgetperiod->{budget_active} = 1;
     push( @period_inactive_loop, $budgetperiod );
 }
@@ -314,6 +291,8 @@ $url = "aqbudgetperiods.pl?tab=2";
 $url .= "&apage=$activepage" if($activepage != 1);
 my $inactive_pagination_bar = pagination_bar ($url, getnbpages( scalar(@$results), $inactivepagesize), $inactivepage, "ipage");
 
+my $branchloop = C4::Branch::GetBranchesLoop();
+
 my $tab = $input->param('tab') ? $input->param('tab') - 1 : 0;
 $template->param(
     period_active_loop      => \@period_active_loop,
@@ -321,6 +300,7 @@ $template->param(
     active_pagination_bar   => $active_pagination_bar,
     inactive_pagination_bar => $inactive_pagination_bar,
     tab                     => $tab,
+    branchloop              => $branchloop,
 );
 
 $template->param($op=>1);