&ModBudgetPlan
- &GetCurrency
- &GetCurrencies
- &ConvertCurrency
-
&GetBudgetsPlanCell
&AddBudgetPlanValue
&GetBudgetAuthCats
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({
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;
$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 );
$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;