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 = ?
716 ORDER BY budget_id DESC
719 my $sth = $dbh->prepare( $query );
720 $sth->execute( $budget_code );
721 return $sth->fetchrow_hashref;
724 =head2 GetChildBudgetsSpent
726 &GetChildBudgetsSpent($budget-id);
728 gets the total spent of the level and sublevels of $budget_id
732 # -------------------------------------------------------------------
733 sub GetChildBudgetsSpent {
734 my ( $budget_id ) = @_;
735 my $dbh = C4::Context->dbh;
739 WHERE budget_parent_id=?
741 my $sth = $dbh->prepare($query);
742 $sth->execute( $budget_id );
743 my $result = $sth->fetchall_arrayref({});
744 my $total_spent = GetBudgetSpent($budget_id);
746 $total_spent += GetChildBudgetsSpent($_->{"budget_id"}) foreach @$result;
753 &GetBudgets($filter, $order_by);
759 # -------------------------------------------------------------------
762 my $orderby = shift || 'budget_name';
763 return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide");
766 =head2 GetBudgetUsers
768 my @borrowernumbers = &GetBudgetUsers($budget_id);
770 Return the list of borrowernumbers linked to a budget
775 my ($budget_id) = @_;
777 my $dbh = C4::Context->dbh;
779 SELECT borrowernumber
780 FROM aqbudgetborrowers
783 my $sth = $dbh->prepare($query);
784 $sth->execute($budget_id);
787 while (my ($borrowernumber) = $sth->fetchrow_array) {
788 push @borrowernumbers, $borrowernumber
791 return @borrowernumbers;
794 =head2 ModBudgetUsers
796 &ModBudgetUsers($budget_id, @borrowernumbers);
798 Modify the list of borrowernumbers linked to a budget
803 my ($budget_id, @budget_users_id) = @_;
805 return unless $budget_id;
807 my $dbh = C4::Context->dbh;
808 my $query = "DELETE FROM aqbudgetborrowers WHERE budget_id = ?";
809 my $sth = $dbh->prepare($query);
810 $sth->execute($budget_id);
813 INSERT INTO aqbudgetborrowers (budget_id, borrowernumber)
816 $sth = $dbh->prepare($query);
817 foreach my $borrowernumber (@budget_users_id) {
818 next unless $borrowernumber;
819 $sth->execute($budget_id, $borrowernumber);
823 sub CanUserUseBudget {
824 my ($borrower, $budget, $userflags) = @_;
826 if (not ref $borrower) {
827 $borrower = C4::Members::GetMember(borrowernumber => $borrower);
829 if (not ref $budget) {
830 $budget = GetBudget($budget);
833 return 0 unless ($borrower and $budget);
835 if (not defined $userflags) {
836 $userflags = C4::Auth::getuserflags($borrower->{flags},
837 $borrower->{userid});
840 unless ($userflags->{superlibrarian}
841 || (ref $userflags->{acquisition}
842 && $userflags->{acquisition}->{budget_manage_all})
843 || (!ref $userflags->{acquisition} && $userflags->{acquisition}))
845 if (not exists $userflags->{acquisition}) {
849 if (!ref $userflags->{acquisition} && !$userflags->{acquisition}) {
853 # Budget restricted to owner
854 if ( $budget->{budget_permission} == 1 ) {
855 if ( $budget->{budget_owner_id}
856 and $budget->{budget_owner_id} != $borrower->{borrowernumber} )
862 # Budget restricted to owner, users and library
863 elsif ( $budget->{budget_permission} == 2 ) {
864 my @budget_users = GetBudgetUsers( $budget->{budget_id} );
868 $budget->{budget_owner_id}
869 and $budget->{budget_owner_id} !=
870 $borrower->{borrowernumber}
871 or not $budget->{budget_owner_id}
873 and ( 0 == grep { $borrower->{borrowernumber} == $_ }
875 and defined $budget->{budget_branchcode}
876 and $budget->{budget_branchcode} ne
877 C4::Context->userenv->{branch}
884 # Budget restricted to owner and users
885 elsif ( $budget->{budget_permission} == 3 ) {
886 my @budget_users = GetBudgetUsers( $budget->{budget_id} );
889 $budget->{budget_owner_id}
890 and $budget->{budget_owner_id} !=
891 $borrower->{borrowernumber}
892 or not $budget->{budget_owner_id}
894 and ( 0 == grep { $borrower->{borrowernumber} == $_ }
906 sub CanUserModifyBudget {
907 my ($borrower, $budget, $userflags) = @_;
909 if (not ref $borrower) {
910 $borrower = C4::Members::GetMember(borrowernumber => $borrower);
912 if (not ref $budget) {
913 $budget = GetBudget($budget);
916 return 0 unless ($borrower and $budget);
918 if (not defined $userflags) {
919 $userflags = C4::Auth::getuserflags($borrower->{flags},
920 $borrower->{userid});
923 unless ($userflags->{superlibrarian}
924 || (ref $userflags->{acquisition}
925 && $userflags->{acquisition}->{budget_manage_all})
926 || (!ref $userflags->{acquisition} && $userflags->{acquisition}))
928 if (!CanUserUseBudget($borrower, $budget, $userflags)) {
932 if (ref $userflags->{acquisition}
933 && !$userflags->{acquisition}->{budget_modify}) {
941 # -------------------------------------------------------------------
945 @currencies = &GetCurrencies;
947 Returns the list of all known currencies.
949 C<$currencies> is a array; its elements are references-to-hash, whose
950 keys are the fields from the currency table in the Koha database.
955 my $dbh = C4::Context->dbh;
960 my $sth = $dbh->prepare($query);
963 while ( my $data = $sth->fetchrow_hashref ) {
964 push( @results, $data );
969 # -------------------------------------------------------------------
972 my $dbh = C4::Context->dbh;
974 SELECT * FROM currency where active = '1' ";
975 my $sth = $dbh->prepare($query);
977 my $r = $sth->fetchrow_hashref;
983 &ModCurrencies($currency, $newrate);
985 Sets the exchange rate for C<$currency> to be C<$newrate>.
990 my ( $currency, $rate ) = @_;
991 my $dbh = C4::Context->dbh;
996 my $sth = $dbh->prepare($query);
997 $sth->execute( $rate, $currency );
1000 # -------------------------------------------------------------------
1002 =head2 ConvertCurrency
1004 $foreignprice = &ConvertCurrency($currency, $localprice);
1006 Converts the price C<$localprice> to foreign currency C<$currency> by
1007 dividing by the exchange rate, and returns the result.
1009 If no exchange rate is found, e is one to one.
1013 sub ConvertCurrency {
1014 my ( $currency, $price ) = @_;
1015 my $dbh = C4::Context->dbh;
1021 my $sth = $dbh->prepare($query);
1022 $sth->execute($currency);
1023 my $cur = ( $sth->fetchrow_array() )[0];
1027 return ( $price / $cur );
1030 END { } # module clean-up code here (global destructor)
1037 Koha Development Team <http://koha-community.org/>