3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
23 use C4::Dates qw(format_date format_date_in_iso);
24 use C4::SQLHelper qw<:all>;
27 use vars qw($VERSION @ISA @EXPORT);
30 # set the version for version checking
31 $VERSION = 3.07.00.049;
37 &GetBudgetByOrderNumber
75 &CheckBudgetParentPerm
82 # ----------------------------BUDGETS.PM-----------------------------";
85 =head1 FUNCTIONS ABOUT BUDGETS
90 my ( $authcat, @hide_cols ) = @_;
91 my $dbh = C4::Context->dbh;
93 my $sth1 = $dbh->prepare(
95 UPDATE aqbudgets_planning SET display = 0
99 foreach my $authvalue (@hide_cols) {
100 # $sth1->{TraceLevel} = 3;
101 $sth1->execute( $authcat, $authvalue );
106 my ( $authcat, $authvalue ) = @_;
108 my $dbh = C4::Context->dbh;
109 my $sth = $dbh->prepare(
111 SELECT count(display) as cnt from aqbudgets_planning
113 AND authvalue = ? and display = 0 |
116 # $sth->{TraceLevel} = 3;
117 $sth->execute( $authcat, $authvalue );
118 my $res = $sth->fetchrow_hashref;
120 return $res->{cnt} > 0 ? 0: 1
124 sub CheckBudgetParentPerm {
125 my ( $budget, $borrower_id ) = @_;
126 my $depth = $budget->{depth};
127 my $parent_id = $budget->{budget_parent_id};
129 my $parent = GetBudget($parent_id);
130 $parent_id = $parent->{budget_parent_id};
131 if ( $parent->{budget_owner_id} == $borrower_id ) {
139 sub AddBudgetPeriod {
140 my ($budgetperiod) = @_;
141 return InsertInTable("aqbudgetperiods",$budgetperiod);
143 # -------------------------------------------------------------------
144 sub GetPeriodsCount {
145 my $dbh = C4::Context->dbh;
146 my $sth = $dbh->prepare("
147 SELECT COUNT(*) AS sum FROM aqbudgetperiods ");
149 my $res = $sth->fetchrow_hashref;
150 return $res->{'sum'};
153 # -------------------------------------------------------------------
154 sub CheckBudgetParent {
155 my ( $new_parent, $budget ) = @_;
156 my $new_parent_id = $new_parent->{'budget_id'};
157 my $budget_id = $budget->{'budget_id'};
158 my $dbh = C4::Context->dbh;
159 my $parent_id_tmp = $new_parent_id;
161 # check new-parent is not a child (or a child's child ;)
162 my $sth = $dbh->prepare(qq|
163 SELECT budget_parent_id FROM
164 aqbudgets where budget_id = ? | );
166 $sth->execute($parent_id_tmp);
167 my $res = $sth->fetchrow_hashref;
168 if ( $res->{'budget_parent_id'} == $budget_id ) {
171 if ( not defined $res->{'budget_parent_id'} ) {
174 $parent_id_tmp = $res->{'budget_parent_id'};
178 # -------------------------------------------------------------------
179 sub BudgetHasChildren {
180 my ( $budget_id ) = @_;
181 my $dbh = C4::Context->dbh;
182 my $sth = $dbh->prepare(qq|
183 SELECT count(*) as sum FROM aqbudgets
184 WHERE budget_parent_id = ? | );
185 $sth->execute( $budget_id );
186 my $sum = $sth->fetchrow_hashref;
187 return $sum->{'sum'};
190 # -------------------------------------------------------------------
191 sub GetBudgetsPlanCell {
192 my ( $cell, $period, $budget ) = @_;
194 my $dbh = C4::Context->dbh;
195 if ( $cell->{'authcat'} eq 'MONTHS' ) {
196 # get the actual amount
197 $sth = $dbh->prepare( qq|
199 SELECT SUM(ecost) AS actual FROM aqorders
200 WHERE budget_id = ? AND
201 entrydate like "$cell->{'authvalue'}%" |
203 $sth->execute( $cell->{'budget_id'} );
204 } elsif ( $cell->{'authcat'} eq 'BRANCHES' ) {
205 # get the actual amount
206 $sth = $dbh->prepare( qq|
208 SELECT SUM(ecost) FROM aqorders
209 LEFT JOIN aqorders_items
210 ON (aqorders.ordernumber = aqorders_items.ordernumber)
212 ON (aqorders_items.itemnumber = items.itemnumber)
213 WHERE budget_id = ? AND homebranch = ? | );
215 $sth->execute( $cell->{'budget_id'}, $cell->{'authvalue'} );
216 } elsif ( $cell->{'authcat'} eq 'ITEMTYPES' ) {
217 # get the actual amount
218 $sth = $dbh->prepare( qq|
220 SELECT SUM( ecost * quantity) AS actual
221 FROM aqorders JOIN biblioitems
222 ON (biblioitems.biblionumber = aqorders.biblionumber )
223 WHERE aqorders.budget_id = ? and itemtype = ? |
225 $sth->execute( $cell->{'budget_id'},
226 $cell->{'authvalue'} );
228 # ELSE GENERIC ORDERS SORT1/SORT2 STAT COUNT.
230 # get the actual amount
231 $sth = $dbh->prepare( qq|
233 SELECT SUM(ecost * quantity) AS actual
235 JOIN aqbudgets ON (aqbudgets.budget_id = aqorders.budget_id )
236 WHERE aqorders.budget_id = ? AND
237 ((aqbudgets.sort1_authcat = ? AND sort1 =?) OR
238 (aqbudgets.sort2_authcat = ? AND sort2 =?)) |
240 $sth->execute( $cell->{'budget_id'},
241 $budget->{'sort1_authcat'},
242 $cell->{'authvalue'},
243 $budget->{'sort2_authcat'},
247 $actual = $sth->fetchrow_array;
249 # get the estimated amount
250 $sth = $dbh->prepare( qq|
252 SELECT estimated_amount AS estimated, display FROM aqbudgets_planning
253 WHERE budget_period_id = ? AND
258 $sth->execute( $cell->{'budget_period_id'},
259 $cell->{'budget_id'},
260 $cell->{'authvalue'},
265 my $res = $sth->fetchrow_hashref;
266 # my $display = $res->{'display'};
267 my $estimated = $res->{'estimated'};
270 return $actual, $estimated;
273 # -------------------------------------------------------------------
275 my ( $budget_plan, $budget_period_id, $authcat ) = @_;
276 my $dbh = C4::Context->dbh;
277 foreach my $buds (@$budget_plan) {
278 my $lines = $buds->{lines};
279 my $sth = $dbh->prepare( qq|
280 DELETE FROM aqbudgets_planning
281 WHERE budget_period_id = ? AND
285 #delete a aqplan line of cells, then insert new cells,
286 # these could be UPDATES rather than DEL/INSERTS...
287 $sth->execute( $budget_period_id, $lines->[0]{budget_id} , $authcat );
289 foreach my $cell (@$lines) {
290 my $sth = $dbh->prepare( qq|
292 INSERT INTO aqbudgets_planning
294 budget_period_id = ?,
296 estimated_amount = ?,
300 $cell->{'budget_id'},
301 $cell->{'budget_period_id'},
303 $cell->{'estimated_amount'},
304 $cell->{'authvalue'},
310 # -------------------------------------------------------------------
312 my ($budget_id) = @_;
313 my $dbh = C4::Context->dbh;
314 my $sth = $dbh->prepare(qq|
315 SELECT SUM( COALESCE(unitprice, ecost) * quantity ) AS sum FROM aqorders
316 WHERE budget_id = ? AND
317 quantityreceived > 0 AND
318 datecancellationprinted IS NULL
320 $sth->execute($budget_id);
321 my $sum = $sth->fetchrow_array;
323 $sth = $dbh->prepare(qq|
324 SELECT SUM(shipmentcost) AS sum
326 WHERE shipmentcost_budgetid = ?
327 AND closedate IS NOT NULL
329 $sth->execute($budget_id);
330 my ($shipmentcost_sum) = $sth->fetchrow_array;
331 $sum += $shipmentcost_sum;
336 # -------------------------------------------------------------------
337 sub GetBudgetOrdered {
338 my ($budget_id) = @_;
339 my $dbh = C4::Context->dbh;
340 my $sth = $dbh->prepare(qq|
341 SELECT SUM(ecost * quantity) AS sum FROM aqorders
342 WHERE budget_id = ? AND
343 quantityreceived = 0 AND
344 datecancellationprinted IS NULL
346 $sth->execute($budget_id);
347 my $sum = $sth->fetchrow_array;
349 $sth = $dbh->prepare(qq|
350 SELECT SUM(shipmentcost) AS sum
352 WHERE shipmentcost_budgetid = ?
353 AND closedate IS NULL
355 $sth->execute($budget_id);
356 my ($shipmentcost_sum) = $sth->fetchrow_array;
357 $sum += $shipmentcost_sum;
364 my $budget_name = &GetBudgetName($budget_id);
366 get the budget_name for a given budget_id
371 my ( $budget_id ) = @_;
372 my $dbh = C4::Context->dbh;
373 my $sth = $dbh->prepare(
380 $sth->execute($budget_id);
381 return $sth->fetchrow_array;
384 # -------------------------------------------------------------------
385 sub GetBudgetAuthCats {
386 my ($budget_period_id) = shift;
387 # now, populate the auth_cats_loop used in the budget planning button
388 # we must retrieve all auth values used by at least one budget
389 my $dbh = C4::Context->dbh;
390 my $sth=$dbh->prepare("SELECT sort1_authcat,sort2_authcat FROM aqbudgets WHERE budget_period_id=?");
391 $sth->execute($budget_period_id);
393 while (my ($sort1_authcat,$sort2_authcat) = $sth->fetchrow) {
394 $authcats{$sort1_authcat}=1;
395 $authcats{$sort2_authcat}=1;
398 foreach (sort keys %authcats) {
399 push @auth_cats_loop,{ authcat => $_ };
401 return \@auth_cats_loop;
404 # -------------------------------------------------------------------
405 sub GetAuthvalueDropbox {
406 my ( $authcat, $default ) = @_;
407 my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
408 my $dbh = C4::Context->dbh;
412 FROM authorised_values
415 LEFT JOIN authorised_values_branches ON ( id = av_id )
420 $query .= " AND ( branchcode = ? OR branchcode IS NULL )" if $branch_limit;
421 $query .= " GROUP BY lib ORDER BY category, lib, lib_opac";
422 my $sth = $dbh->prepare($query);
423 $sth->execute( $authcat, $branch_limit ? $branch_limit : () );
426 my $option_list = [];
427 my @authorised_values = ( q{} );
428 while (my $av = $sth->fetchrow_hashref) {
429 push @{$option_list}, {
430 value => $av->{authorised_value},
432 default => ($default eq $av->{authorised_value}),
436 if ( @{$option_list} ) {
442 # -------------------------------------------------------------------
443 sub GetBudgetPeriods {
444 my ($filters,$orderby) = @_;
445 return SearchInTable("aqbudgetperiods",$filters, $orderby, undef,undef, undef, "wide");
447 # -------------------------------------------------------------------
448 sub GetBudgetPeriod {
449 my ($budget_period_id) = @_;
450 my $dbh = C4::Context->dbh;
451 ## $total = number of records linked to the record that must be deleted
453 ## get information about the record that will be deleted
455 if ($budget_period_id) {
456 $sth = $dbh->prepare( qq|
459 WHERE budget_period_id=? |
461 $sth->execute($budget_period_id);
462 } else { # ACTIVE BUDGET
463 $sth = $dbh->prepare(qq|
466 WHERE budget_period_active=1 |
470 my $data = $sth->fetchrow_hashref;
474 # -------------------------------------------------------------------
476 my ($budget_period_id) = @_;
477 my $dbh = C4::Context->dbh;
478 ; ## $total = number of records linked to the record that must be deleted
481 ## get information about the record that will be deleted
482 my $sth = $dbh->prepare(qq|
485 WHERE budget_period_id=? |
487 return $sth->execute($budget_period_id);
490 # -------------------------------------------------------------------
491 sub ModBudgetPeriod {
492 my ($budget_period_information) = @_;
493 return UpdateInTable("aqbudgetperiods",$budget_period_information);
496 # -------------------------------------------------------------------
497 sub GetBudgetHierarchy {
498 my ( $budget_period_id, $branchcode, $owner ) = @_;
500 my $dbh = C4::Context->dbh;
502 SELECT aqbudgets.*, aqbudgetperiods.budget_period_active, aqbudgetperiods.budget_period_description
504 JOIN aqbudgetperiods USING (budget_period_id)|;
507 # show only period X if requested
508 if ($budget_period_id) {
509 push @where_strings," aqbudgets.budget_period_id = ?";
510 push @bind_params, $budget_period_id;
512 # show only budgets owned by me, my branch or everyone
516 qq{ (budget_owner_id = ? OR budget_branchcode = ? OR ((budget_branchcode IS NULL or budget_branchcode="") AND (budget_owner_id IS NULL OR budget_owner_id="")))};
517 push @bind_params, ( $owner, $branchcode );
519 push @where_strings, ' (budget_owner_id = ? OR budget_owner_id IS NULL or budget_owner_id ="") ';
520 push @bind_params, $owner;
524 push @where_strings," (budget_branchcode =? or budget_branchcode is NULL)";
525 push @bind_params, $branchcode;
528 $query.=" WHERE ".join(' AND ', @where_strings) if @where_strings;
529 $debug && warn $query,join(",",@bind_params);
530 my $sth = $dbh->prepare($query);
531 $sth->execute(@bind_params);
532 my $results = $sth->fetchall_arrayref({});
537 foreach my $r (@res) {
540 $r->{depth} = '0' if !defined $r->{budget_parent_id};
541 foreach my $r2 (@res) {
542 if (defined $r2->{budget_parent_id}
543 && $r2->{budget_parent_id} == $r->{budget_id}) {
544 push @child, $r2->{budget_id};
545 $r2->{depth} = ($r->{depth} + 1) if defined $r->{depth};
548 $r->{child} = \@child if scalar @child > 0; # add the child
549 $depth_cnt++ if !defined $r->{'depth'};
551 last if ($depth_cnt == 0 || $i == 100);
555 # look for top parents 1st
556 my (@sort, $depth_count);
557 ($i, $depth_count) = 0;
560 foreach my $r (@res) {
561 if ($r->{depth} == $depth_count) {
562 $children++ if (ref $r->{child} eq 'ARRAY');
564 # find the parent id element_id and insert it after
567 if ($depth_count > 0) {
570 my $depth = $r->{depth} * 2;
571 $r->{budget_code_indent} = $r->{budget_code};
572 $r->{budget_name_indent} = $r->{budget_name};
573 foreach my $r3 (@sort) {
574 if ($r3->{budget_id} == $r->{budget_parent_id}) {
581 $r->{budget_code_indent} = $r->{budget_code};
582 $r->{budget_name_indent} = $r->{budget_name};
585 if (defined $parent) {
586 splice @sort, ($parent + 1), 0, $r;
593 } # --------------foreach
595 last if $children == 0;
598 # add budget-percent and allocation, and flags for html-template
599 foreach my $r (@sort) {
600 my $subs_href = $r->{'child'};
602 if ( defined $subs_href ) {
603 @subs_arr = @{$subs_href};
606 my $moo = $r->{'budget_code_indent'};
607 $moo =~ s/\ /\ \;/g;
608 $r->{'budget_code_indent'} = $moo;
610 $moo = $r->{'budget_name_indent'};
611 $moo =~ s/\ /\ \;/g;
612 $r->{'budget_name_indent'} = $moo;
614 $r->{'budget_spent'} = GetBudgetSpent( $r->{'budget_id'} );
615 $r->{budget_ordered} = GetBudgetOrdered( $r->{budget_id} );
617 $r->{budget_spent_sublevels} = 0;
618 $r->{budget_ordered_sublevels} = 0;
620 foreach my $sub (@subs_arr) {
621 my $sub_budget = GetBudget($sub);
622 $r->{budget_spent_sublevels} += GetBudgetSpent( $sub_budget->{'budget_id'} );
623 $r->{budget_ordered_sublevels} += GetBudgetOrdered($sub);
629 # -------------------------------------------------------------------
633 return InsertInTable("aqbudgets",$budget);
636 # -------------------------------------------------------------------
639 return UpdateInTable("aqbudgets",$budget);
642 # -------------------------------------------------------------------
644 my ($budget_id) = @_;
645 my $dbh = C4::Context->dbh;
646 my $sth = $dbh->prepare("delete from aqbudgets where budget_id=?");
647 my $rc = $sth->execute($budget_id);
654 &GetBudget($budget_id);
656 get a specific budget
660 # -------------------------------------------------------------------
662 my ( $budget_id ) = @_;
663 my $dbh = C4::Context->dbh;
669 my $sth = $dbh->prepare($query);
670 $sth->execute( $budget_id );
671 my $result = $sth->fetchrow_hashref;
675 =head2 GetBudgetByOrderNumber
677 &GetBudgetByOrderNumber($ordernumber);
679 get a specific budget by order number
683 # -------------------------------------------------------------------
684 sub GetBudgetByOrderNumber {
685 my ( $ordernumber ) = @_;
686 my $dbh = C4::Context->dbh;
689 FROM aqbudgets, aqorders
691 AND aqorders.budget_id = aqbudgets.budget_id
693 my $sth = $dbh->prepare($query);
694 $sth->execute( $ordernumber );
695 my $result = $sth->fetchrow_hashref;
699 =head2 GetBudgetByCode
701 my $budget = &GetBudgetByCode($budget_code);
703 Retrieve all aqbudgets fields as a hashref for the budget that has
708 sub GetBudgetByCode {
709 my ( $budget_code ) = @_;
711 my $dbh = C4::Context->dbh;
715 WHERE budget_code = ?
717 my $sth = $dbh->prepare( $query );
718 $sth->execute( $budget_code );
719 return $sth->fetchrow_hashref;
722 =head2 GetChildBudgetsSpent
724 &GetChildBudgetsSpent($budget-id);
726 gets the total spent of the level and sublevels of $budget_id
730 # -------------------------------------------------------------------
731 sub GetChildBudgetsSpent {
732 my ( $budget_id ) = @_;
733 my $dbh = C4::Context->dbh;
737 WHERE budget_parent_id=?
739 my $sth = $dbh->prepare($query);
740 $sth->execute( $budget_id );
741 my $result = $sth->fetchall_arrayref({});
742 my $total_spent = GetBudgetSpent($budget_id);
744 $total_spent += GetChildBudgetsSpent($_->{"budget_id"}) foreach @$result;
751 &GetBudgets($filter, $order_by);
757 # -------------------------------------------------------------------
760 my $orderby = shift || 'budget_name';
761 return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide");
764 =head2 GetBudgetUsers
766 my @borrowernumbers = &GetBudgetUsers($budget_id);
768 Return the list of borrowernumbers linked to a budget
773 my ($budget_id) = @_;
775 my $dbh = C4::Context->dbh;
777 SELECT borrowernumber
778 FROM aqbudgetborrowers
781 my $sth = $dbh->prepare($query);
782 $sth->execute($budget_id);
785 while (my ($borrowernumber) = $sth->fetchrow_array) {
786 push @borrowernumbers, $borrowernumber
789 return @borrowernumbers;
792 =head2 ModBudgetUsers
794 &ModBudgetUsers($budget_id, @borrowernumbers);
796 Modify the list of borrowernumbers linked to a budget
801 my ($budget_id, @budget_users_id) = @_;
803 return unless $budget_id;
805 my $dbh = C4::Context->dbh;
806 my $query = "DELETE FROM aqbudgetborrowers WHERE budget_id = ?";
807 my $sth = $dbh->prepare($query);
808 $sth->execute($budget_id);
811 INSERT INTO aqbudgetborrowers (budget_id, borrowernumber)
814 $sth = $dbh->prepare($query);
815 foreach my $borrowernumber (@budget_users_id) {
816 next unless $borrowernumber;
817 $sth->execute($budget_id, $borrowernumber);
821 sub CanUserUseBudget {
822 my ($borrower, $budget, $userflags) = @_;
824 if (not ref $borrower) {
825 $borrower = C4::Members::GetMember(borrowernumber => $borrower);
827 if (not ref $budget) {
828 $budget = GetBudget($budget);
831 return 0 unless ($borrower and $budget);
833 if (not defined $userflags) {
834 $userflags = C4::Auth::getuserflags($borrower->{flags},
835 $borrower->{userid});
838 unless ($userflags->{superlibrarian}
839 || (ref $userflags->{acquisition}
840 && $userflags->{acquisition}->{budget_manage_all})
841 || (!ref $userflags->{acquisition} && $userflags->{acquisition}))
843 if (not exists $userflags->{acquisition}) {
847 if (!ref $userflags->{acquisition} && !$userflags->{acquisition}) {
851 # Budget restricted to owner
852 if ( $budget->{budget_permission} == 1 ) {
853 if ( $budget->{budget_owner_id}
854 and $budget->{budget_owner_id} != $borrower->{borrowernumber} )
860 # Budget restricted to owner, users and library
861 elsif ( $budget->{budget_permission} == 2 ) {
862 my @budget_users = GetBudgetUsers( $budget->{budget_id} );
866 $budget->{budget_owner_id}
867 and $budget->{budget_owner_id} !=
868 $borrower->{borrowernumber}
869 or not $budget->{budget_owner_id}
871 and ( 0 == grep { $borrower->{borrowernumber} == $_ }
873 and defined $budget->{budget_branchcode}
874 and $budget->{budget_branchcode} ne
875 C4::Context->userenv->{branch}
882 # Budget restricted to owner and users
883 elsif ( $budget->{budget_permission} == 3 ) {
884 my @budget_users = GetBudgetUsers( $budget->{budget_id} );
887 $budget->{budget_owner_id}
888 and $budget->{budget_owner_id} !=
889 $borrower->{borrowernumber}
890 or not $budget->{budget_owner_id}
892 and ( 0 == grep { $borrower->{borrowernumber} == $_ }
904 sub CanUserModifyBudget {
905 my ($borrower, $budget, $userflags) = @_;
907 if (not ref $borrower) {
908 $borrower = C4::Members::GetMember(borrowernumber => $borrower);
910 if (not ref $budget) {
911 $budget = GetBudget($budget);
914 return 0 unless ($borrower and $budget);
916 if (not defined $userflags) {
917 $userflags = C4::Auth::getuserflags($borrower->{flags},
918 $borrower->{userid});
921 unless ($userflags->{superlibrarian}
922 || (ref $userflags->{acquisition}
923 && $userflags->{acquisition}->{budget_manage_all})
924 || (!ref $userflags->{acquisition} && $userflags->{acquisition}))
926 if (!CanUserUseBudget($borrower, $budget, $userflags)) {
930 if (ref $userflags->{acquisition}
931 && !$userflags->{acquisition}->{budget_modify}) {
939 # -------------------------------------------------------------------
943 @currencies = &GetCurrencies;
945 Returns the list of all known currencies.
947 C<$currencies> is a array; its elements are references-to-hash, whose
948 keys are the fields from the currency table in the Koha database.
953 my $dbh = C4::Context->dbh;
958 my $sth = $dbh->prepare($query);
961 while ( my $data = $sth->fetchrow_hashref ) {
962 push( @results, $data );
967 # -------------------------------------------------------------------
970 my $dbh = C4::Context->dbh;
972 SELECT * FROM currency where active = '1' ";
973 my $sth = $dbh->prepare($query);
975 my $r = $sth->fetchrow_hashref;
981 &ModCurrencies($currency, $newrate);
983 Sets the exchange rate for C<$currency> to be C<$newrate>.
988 my ( $currency, $rate ) = @_;
989 my $dbh = C4::Context->dbh;
994 my $sth = $dbh->prepare($query);
995 $sth->execute( $rate, $currency );
998 # -------------------------------------------------------------------
1000 =head2 ConvertCurrency
1002 $foreignprice = &ConvertCurrency($currency, $localprice);
1004 Converts the price C<$localprice> to foreign currency C<$currency> by
1005 dividing by the exchange rate, and returns the result.
1007 If no exchange rate is found, e is one to one.
1011 sub ConvertCurrency {
1012 my ( $currency, $price ) = @_;
1013 my $dbh = C4::Context->dbh;
1019 my $sth = $dbh->prepare($query);
1020 $sth->execute($currency);
1021 my $cur = ( $sth->fetchrow_array() )[0];
1025 return ( $price / $cur );
1028 END { } # module clean-up code here (global destructor)
1035 Koha Development Team <http://koha-community.org/>