Bug 13871 - OverDrive message when user authentication fails
[koha.git] / C4 / Budgets.pm
index 79012ba..9c50bda 100644 (file)
@@ -59,10 +59,6 @@ BEGIN {
 
         &ModBudgetPlan
 
-        &GetCurrency
-        &GetCurrencies
-        &ConvertCurrency
-        
                &GetBudgetsPlanCell
         &AddBudgetPlanValue
         &GetBudgetAuthCats
@@ -915,77 +911,16 @@ sub CanUserModifyBudget {
     return 1;
 }
 
-# -------------------------------------------------------------------
-
-=head2 GetCurrencies
-
-  @currencies = &GetCurrencies;
-
-Returns the list of all known currencies.
-
-C<$currencies> is a array; its elements are references-to-hash, whose
-keys are the fields from the currency table in the Koha database.
+sub _round {
+    my ($value, $increment) = @_;
 
-=cut
-
-sub GetCurrencies {
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT *
-        FROM   currency
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute;
-    my @results = ();
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push( @results, $data );
+    if ($increment && $increment != 0) {
+        $value = int($value / $increment) * $increment;
     }
-    return @results;
-}
-
-# -------------------------------------------------------------------
-
-sub GetCurrency {
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT * FROM currency where active = '1'    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute;
-    my $r = $sth->fetchrow_hashref;
-    return $r;
-}
 
-# -------------------------------------------------------------------
-
-=head2 ConvertCurrency
-
-  $foreignprice = &ConvertCurrency($currency, $localprice);
-
-Converts the price C<$localprice> to foreign currency C<$currency> by
-dividing by the exchange rate, and returns the result.
-
-If no exchange rate is found, e is one to one.
-
-=cut
-
-sub ConvertCurrency {
-    my ( $currency, $price ) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query = "
-        SELECT rate
-        FROM   currency
-        WHERE  currency=?
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($currency);
-    my $cur = ( $sth->fetchrow_array() )[0];
-    unless ($cur) {
-        $cur = 1;
-    }
-    return ( $price / $cur );
+    return $value;
 }
 
-
 =head2 CloneBudgetPeriod
 
   my $new_budget_period_id = CloneBudgetPeriod({
@@ -1011,6 +946,8 @@ sub CloneBudgetPeriod {
     my $budget_period_startdate   = $params->{budget_period_startdate};
     my $budget_period_enddate     = $params->{budget_period_enddate};
     my $budget_period_description = $params->{budget_period_description};
+    my $amount_change_percentage  = $params->{amount_change_percentage};
+    my $amount_change_round_increment = $params->{amount_change_round_increment};
     my $mark_original_budget_as_inactive =
       $params->{mark_original_budget_as_inactive} || 0;
     my $reset_all_budgets = $params->{reset_all_budgets} || 0;
@@ -1022,6 +959,14 @@ sub CloneBudgetPeriod {
     $budget_period->{budget_period_description} = $budget_period_description;
     # The new budget (budget_period) should be active by default
     $budget_period->{budget_period_active}    = 1;
+
+    if ($amount_change_percentage) {
+        my $total = $budget_period->{budget_period_total};
+        $total += $total * $amount_change_percentage / 100;
+        $total = _round($total, $amount_change_round_increment);
+        $budget_period->{budget_period_total} = $total;
+    }
+
     my $original_budget_period_id = $budget_period->{budget_period_id};
     delete $budget_period->{budget_period_id};
     my $new_budget_period_id = AddBudgetPeriod( $budget_period );
@@ -1049,6 +994,15 @@ sub CloneBudgetPeriod {
             $budget->{budget_amount} = 0;
             ModBudget( $budget );
         }
+    } elsif ($amount_change_percentage) {
+        my $budgets = GetBudgets({ budget_period_id => $new_budget_period_id });
+        for my $budget ( @$budgets ) {
+            my $amount = $budget->{budget_amount};
+            $amount += $amount * $amount_change_percentage / 100;
+            $amount = _round($amount, $amount_change_round_increment);
+            $budget->{budget_amount} = $amount;
+            ModBudget( $budget );
+        }
     }
 
     return $new_budget_period_id;