Merge remote branch 'kc/new/bug_5058' into kcmaster
[koha.git] / C4 / Budgets.pm
blob005bba8d176629a9c015c7ce9117a3670a5da066
1 package C4::Budgets;
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
10 # version.
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.
20 use strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Context;
23 use C4::Dates qw(format_date format_date_in_iso);
24 use C4::SQLHelper qw<:all>;
25 use C4::Debug;
27 use vars qw($VERSION @ISA @EXPORT);
29 BEGIN {
30 # set the version for version checking
31 $VERSION = 3.01;
32 require Exporter;
33 @ISA = qw(Exporter);
34 @EXPORT = qw(
36 &GetBudget
37 &GetBudgets
38 &GetBudgetHierarchy
39 &AddBudget
40 &ModBudget
41 &DelBudget
42 &GetBudgetSpent
43 &GetBudgetOrdered
44 &GetPeriodsCount
45 &GetChildBudgetsSpent
47 &GetBudgetPeriod
48 &GetBudgetPeriods
49 &ModBudgetPeriod
50 &AddBudgetPeriod
51 &DelBudgetPeriod
53 &GetBudgetPeriodsDropbox
54 &GetBudgetSortDropbox
55 &GetAuthvalueDropbox
56 &GetBudgetPermDropbox
58 &ModBudgetPlan
60 &GetCurrency
61 &GetCurrencies
62 &ModCurrencies
63 &ConvertCurrency
65 &GetBudgetsPlanCell
66 &AddBudgetPlanValue
67 &GetBudgetAuthCats
68 &BudgetHasChildren
69 &CheckBudgetParent
70 &CheckBudgetParentPerm
72 &HideCols
73 &GetCols
77 # ----------------------------BUDGETS.PM-----------------------------";
80 =head1 FUNCTIONS ABOUT BUDGETS
82 =cut
84 sub HideCols {
85 my ( $authcat, @hide_cols ) = @_;
86 my $dbh = C4::Context->dbh;
88 my $sth1 = $dbh->prepare(
89 qq|
90 UPDATE aqbudgets_planning SET display = 0
91 WHERE authcat = ?
92 AND authvalue = ? |
94 foreach my $authvalue (@hide_cols) {
95 # $sth1->{TraceLevel} = 3;
96 $sth1->execute( $authcat, $authvalue );
100 sub GetCols {
101 my ( $authcat, $authvalue ) = @_;
103 my $dbh = C4::Context->dbh;
104 my $sth = $dbh->prepare(
106 SELECT count(display) as cnt from aqbudgets_planning
107 WHERE authcat = ?
108 AND authvalue = ? and display = 0 |
111 # $sth->{TraceLevel} = 3;
112 $sth->execute( $authcat, $authvalue );
113 my $res = $sth->fetchrow_hashref;
115 return $res->{cnt} > 0 ? 0: 1
119 sub CheckBudgetParentPerm {
120 my ( $budget, $borrower_id ) = @_;
121 my $depth = $budget->{depth};
122 my $parent_id = $budget->{budget_parent_id};
123 while ($depth) {
124 my $parent = GetBudget($parent_id);
125 $parent_id = $parent->{budget_parent_id};
126 if ( $parent->{budget_owner_id} == $borrower_id ) {
127 return 1;
129 $depth--
131 return 0;
134 sub AddBudgetPeriod {
135 my ($budgetperiod) = @_;
136 return InsertInTable("aqbudgetperiods",$budgetperiod);
138 # -------------------------------------------------------------------
139 sub GetPeriodsCount {
140 my $dbh = C4::Context->dbh;
141 my $sth = $dbh->prepare("
142 SELECT COUNT(*) AS sum FROM aqbudgetperiods ");
143 $sth->execute();
144 my $res = $sth->fetchrow_hashref;
145 return $res->{'sum'};
148 # -------------------------------------------------------------------
149 sub CheckBudgetParent {
150 my ( $new_parent, $budget ) = @_;
151 my $new_parent_id = $new_parent->{'budget_id'};
152 my $budget_id = $budget->{'budget_id'};
153 my $dbh = C4::Context->dbh;
154 my $parent_id_tmp = $new_parent_id;
156 # check new-parent is not a child (or a child's child ;)
157 my $sth = $dbh->prepare(qq|
158 SELECT budget_parent_id FROM
159 aqbudgets where budget_id = ? | );
160 while (1) {
161 $sth->execute($parent_id_tmp);
162 my $res = $sth->fetchrow_hashref;
163 if ( $res->{'budget_parent_id'} == $budget_id ) {
164 return 1;
166 if ( not defined $res->{'budget_parent_id'} ) {
167 return 0;
169 $parent_id_tmp = $res->{'budget_parent_id'};
173 # -------------------------------------------------------------------
174 sub BudgetHasChildren {
175 my ( $budget_id ) = @_;
176 my $dbh = C4::Context->dbh;
177 my $sth = $dbh->prepare(qq|
178 SELECT count(*) as sum FROM aqbudgets
179 WHERE budget_parent_id = ? | );
180 $sth->execute( $budget_id );
181 my $sum = $sth->fetchrow_hashref;
182 return $sum->{'sum'};
185 # -------------------------------------------------------------------
186 sub GetBudgetsPlanCell {
187 my ( $cell, $period, $budget ) = @_;
188 my ($actual, $sth);
189 my $dbh = C4::Context->dbh;
190 if ( $cell->{'authcat'} eq 'MONTHS' ) {
191 # get the actual amount
192 $sth = $dbh->prepare( qq|
194 SELECT SUM(ecost) AS actual FROM aqorders
195 WHERE budget_id = ? AND
196 entrydate like "$cell->{'authvalue'}%" |
198 $sth->execute( $cell->{'budget_id'} );
199 } elsif ( $cell->{'authcat'} eq 'BRANCHES' ) {
200 # get the actual amount
201 $sth = $dbh->prepare( qq|
203 SELECT SUM(ecost) FROM aqorders
204 LEFT JOIN aqorders_items
205 ON (aqorders.ordernumber = aqorders_items.ordernumber)
206 LEFT JOIN items
207 ON (aqorders_items.itemnumber = items.itemnumber)
208 WHERE budget_id = ? AND homebranch = ? | );
210 $sth->execute( $cell->{'budget_id'}, $cell->{'authvalue'} );
211 } elsif ( $cell->{'authcat'} eq 'ITEMTYPES' ) {
212 # get the actual amount
213 $sth = $dbh->prepare( qq|
215 SELECT SUM( ecost * quantity) AS actual
216 FROM aqorders JOIN biblioitems
217 ON (biblioitems.biblionumber = aqorders.biblionumber )
218 WHERE aqorders.budget_id = ? and itemtype = ? |
220 $sth->execute( $cell->{'budget_id'},
221 $cell->{'authvalue'} );
223 # ELSE GENERIC ORDERS SORT1/SORT2 STAT COUNT.
224 else {
225 # get the actual amount
226 $sth = $dbh->prepare( qq|
228 SELECT SUM(ecost * quantity) AS actual
229 FROM aqorders
230 JOIN aqbudgets ON (aqbudgets.budget_id = aqorders.budget_id )
231 WHERE aqorders.budget_id = ? AND
232 ((aqbudgets.sort1_authcat = ? AND sort1 =?) OR
233 (aqbudgets.sort2_authcat = ? AND sort2 =?)) |
235 $sth->execute( $cell->{'budget_id'},
236 $budget->{'sort1_authcat'},
237 $cell->{'authvalue'},
238 $budget->{'sort2_authcat'},
239 $cell->{'authvalue'}
242 $actual = $sth->fetchrow_array;
244 # get the estimated amount
245 $sth = $dbh->prepare( qq|
247 SELECT estimated_amount AS estimated, display FROM aqbudgets_planning
248 WHERE budget_period_id = ? AND
249 budget_id = ? AND
250 authvalue = ? AND
251 authcat = ? |
253 $sth->execute( $cell->{'budget_period_id'},
254 $cell->{'budget_id'},
255 $cell->{'authvalue'},
256 $cell->{'authcat'},
260 my $res = $sth->fetchrow_hashref;
261 # my $display = $res->{'display'};
262 my $estimated = $res->{'estimated'};
265 return $actual, $estimated;
268 # -------------------------------------------------------------------
269 sub ModBudgetPlan {
270 my ( $budget_plan, $budget_period_id, $authcat ) = @_;
271 my $dbh = C4::Context->dbh;
272 foreach my $buds (@$budget_plan) {
273 my $lines = $buds->{lines};
274 my $sth = $dbh->prepare( qq|
275 DELETE FROM aqbudgets_planning
276 WHERE budget_period_id = ? AND
277 budget_id = ? AND
278 authcat = ? |
280 #delete a aqplan line of cells, then insert new cells,
281 # these could be UPDATES rather than DEL/INSERTS...
282 $sth->execute( $budget_period_id, $lines->[0]{budget_id} , $authcat );
284 foreach my $cell (@$lines) {
285 my $sth = $dbh->prepare( qq|
287 INSERT INTO aqbudgets_planning
288 SET budget_id = ?,
289 budget_period_id = ?,
290 authcat = ?,
291 estimated_amount = ?,
292 authvalue = ? |
294 $sth->execute(
295 $cell->{'budget_id'},
296 $cell->{'budget_period_id'},
297 $cell->{'authcat'},
298 $cell->{'estimated_amount'},
299 $cell->{'authvalue'},
305 # -------------------------------------------------------------------
306 sub GetBudgetSpent {
307 my ($budget_id) = @_;
308 my $dbh = C4::Context->dbh;
309 my $sth = $dbh->prepare(qq|
310 SELECT SUM(ecost * quantity) AS sum FROM aqorders
311 WHERE budget_id = ? AND
312 quantityreceived > 0 AND
313 datecancellationprinted IS NULL
316 $sth->execute($budget_id);
317 my $sum = $sth->fetchrow_array;
318 return $sum;
321 # -------------------------------------------------------------------
322 sub GetBudgetOrdered {
323 my ($budget_id) = @_;
324 my $dbh = C4::Context->dbh;
325 my $sth = $dbh->prepare(qq|
326 SELECT SUM(ecost * quantity) AS sum FROM aqorders
327 WHERE budget_id = ? AND
328 quantityreceived = 0 AND
329 datecancellationprinted IS NULL
332 $sth->execute($budget_id);
333 my $sum = $sth->fetchrow_array;
334 return $sum;
337 # -------------------------------------------------------------------
338 sub GetBudgetPermDropbox {
339 my ($perm) = @_;
340 my %labels;
341 $labels{'0'} = 'None';
342 $labels{'1'} = 'Owner';
343 $labels{'2'} = 'Library';
344 my $radio = CGI::scrolling_list(
345 -id => 'budget_permission',
346 -name => 'budget_permission',
347 -values => [ '0', '1', '2' ],
348 -default => $perm,
349 -labels => \%labels,
350 -size => 1,
352 return $radio;
355 # -------------------------------------------------------------------
356 sub GetBudgetAuthCats {
357 my ($budget_period_id) = shift;
358 # now, populate the auth_cats_loop used in the budget planning button
359 # we must retrieve all auth values used by at least one budget
360 my $dbh = C4::Context->dbh;
361 my $sth=$dbh->prepare("SELECT sort1_authcat,sort2_authcat FROM aqbudgets WHERE budget_period_id=?");
362 $sth->execute($budget_period_id);
363 my %authcats;
364 while (my ($sort1_authcat,$sort2_authcat) = $sth->fetchrow) {
365 $authcats{$sort1_authcat}=1;
366 $authcats{$sort2_authcat}=1;
368 my @auth_cats_loop;
369 foreach (sort keys %authcats) {
370 push @auth_cats_loop,{ authcat => $_ };
372 return \@auth_cats_loop;
375 # -------------------------------------------------------------------
376 sub GetAuthvalueDropbox {
377 my ( $name, $authcat, $default ) = @_;
378 my @authorised_values;
379 my %authorised_lib;
380 my $value;
381 my $dbh = C4::Context->dbh;
382 my $sth = $dbh->prepare(
383 "SELECT authorised_value,lib
384 FROM authorised_values
385 WHERE category = ?
386 ORDER BY lib"
388 $sth->execute( $authcat );
390 push @authorised_values, '';
391 while (my ($value, $lib) = $sth->fetchrow_array) {
392 push @authorised_values, $value;
393 $authorised_lib{$value} = $lib;
396 return 0 if keys(%authorised_lib) == 0;
398 my $budget_authvalue_dropbox = CGI::scrolling_list(
399 -values => \@authorised_values,
400 -labels => \%authorised_lib,
401 -default => $default,
402 -override => 1,
403 -size => 1,
404 -multiple => 0,
405 -name => $name,
406 -id => $name,
409 return $budget_authvalue_dropbox
412 # -------------------------------------------------------------------
413 sub GetBudgetPeriodsDropbox {
414 my ($budget_period_id) = @_;
415 my %labels;
416 my @values;
417 my ($active, $periods) = GetBudgetPeriods();
418 foreach my $r (@$periods) {
419 $labels{"$r->{budget_period_id}"} = $r->{budget_period_description};
420 push @values, $r->{budget_period_id};
423 # if no buget_id is passed then its an add
424 my $budget_period_dropbox = CGI::scrolling_list(
425 -name => 'budget_period_id',
426 -values => \@values,
427 -default => $budget_period_id ? $budget_period_id : $active,
428 -size => 1,
429 -labels => \%labels,
431 return $budget_period_dropbox;
434 # -------------------------------------------------------------------
435 sub GetBudgetPeriods {
436 my ($filters,$orderby) = @_;
437 return SearchInTable("aqbudgetperiods",$filters, $orderby, undef,undef, undef, "wide");
439 # -------------------------------------------------------------------
440 sub GetBudgetPeriod {
441 my ($budget_period_id) = @_;
442 my $dbh = C4::Context->dbh;
443 ## $total = number of records linked to the record that must be deleted
444 my $total = 0;
445 ## get information about the record that will be deleted
446 my $sth;
447 if ($budget_period_id) {
448 $sth = $dbh->prepare( qq|
449 SELECT *
450 FROM aqbudgetperiods
451 WHERE budget_period_id=? |
453 $sth->execute($budget_period_id);
454 } else { # ACTIVE BUDGET
455 $sth = $dbh->prepare(qq|
456 SELECT *
457 FROM aqbudgetperiods
458 WHERE budget_period_active=1 |
460 $sth->execute();
462 my $data = $sth->fetchrow_hashref;
463 return $data;
466 # -------------------------------------------------------------------
467 sub DelBudgetPeriod{
468 my ($budget_period_id) = @_;
469 my $dbh = C4::Context->dbh;
470 ; ## $total = number of records linked to the record that must be deleted
471 my $total = 0;
473 ## get information about the record that will be deleted
474 my $sth = $dbh->prepare(qq|
475 DELETE
476 FROM aqbudgetperiods
477 WHERE budget_period_id=? |
479 return $sth->execute($budget_period_id);
482 # -------------------------------------------------------------------
483 sub ModBudgetPeriod {
484 my ($budget_period_information) = @_;
485 return UpdateInTable("aqbudgetperiods",$budget_period_information);
488 # -------------------------------------------------------------------
489 sub GetBudgetHierarchy {
490 my ($budget_period_id, $branchcode, $owner) = @_;
491 my @bind_params;
492 my $dbh = C4::Context->dbh;
493 my $query = qq|
494 SELECT aqbudgets.*
495 FROM aqbudgets |;
496 # show only period X if requested
497 my @where_strings;
498 if ($budget_period_id) {
499 push @where_strings," aqbudgets.budget_period_id = ?";
500 push @bind_params, $budget_period_id;
502 # show only budgets owned by me, my branch or everyone
503 if ($owner) {
504 if ($branchcode) {
505 push @where_strings,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="")))};
506 push @bind_params, ($owner, $branchcode);
507 } else {
508 push @where_strings, ' (budget_owner_id = ? OR budget_owner_id IS NULL or budget_owner_id ="") ';
509 push @bind_params, $owner;
511 } else {
512 if ($branchcode) {
513 push @where_strings," (budget_branchcode =? or budget_branchcode is NULL)";
514 push @bind_params, $branchcode;
517 $query.=" WHERE ".join(' AND ', @where_strings) if @where_strings;
518 $debug && warn $query,join(",",@bind_params);
519 my $sth = $dbh->prepare($query);
520 $sth->execute(@bind_params);
521 my $results = $sth->fetchall_arrayref({});
522 my @res = @$results;
523 my $i = 0;
524 while (1) {
525 my $depth_cnt = 0;
526 foreach my $r (@res) {
527 my @child;
528 # look for children
529 $r->{depth} = '0' if !defined $r->{budget_parent_id};
530 foreach my $r2 (@res) {
531 if (defined $r2->{budget_parent_id}
532 && $r2->{budget_parent_id} == $r->{budget_id}) {
533 push @child, $r2->{budget_id};
534 $r2->{depth} = ($r->{depth} + 1) if defined $r->{depth};
537 $r->{child} = \@child if scalar @child > 0; # add the child
538 $depth_cnt++ if !defined $r->{'depth'};
540 last if ($depth_cnt == 0 || $i == 100);
541 $i++;
544 # look for top parents 1st
545 my (@sort, $depth_count);
546 ($i, $depth_count) = 0;
547 while (1) {
548 my $children = 0;
549 foreach my $r (@res) {
550 if ($r->{depth} == $depth_count) {
551 $children++ if (ref $r->{child} eq 'ARRAY');
553 # find the parent id element_id and insert it after
554 my $i2 = 0;
555 my $parent;
556 if ($depth_count > 0) {
558 # add indent
559 my $depth = $r->{depth} * 2;
560 $r->{budget_code_indent} = $r->{budget_code};
561 $r->{budget_name_indent} = $r->{budget_name};
562 foreach my $r3 (@sort) {
563 if ($r3->{budget_id} == $r->{budget_parent_id}) {
564 $parent = $i2;
565 last;
567 $i2++;
569 } else {
570 $r->{budget_code_indent} = $r->{budget_code};
571 $r->{budget_name_indent} = $r->{budget_name};
574 if (defined $parent) {
575 splice @sort, ($parent + 1), 0, $r;
576 } else {
577 push @sort, $r;
581 $i++;
582 } # --------------foreach
583 $depth_count++;
584 last if $children == 0;
587 # add budget-percent and allocation, and flags for html-template
588 foreach my $r (@sort) {
589 my $subs_href = $r->{'child'};
590 my @subs_arr = @$subs_href if defined $subs_href;
592 my $moo = $r->{'budget_code_indent'};
593 $moo =~ s/\ /\&nbsp\;/g;
594 $r->{'budget_code_indent'} = $moo;
596 $moo = $r->{'budget_name_indent'};
597 $moo =~ s/\ /\&nbsp\;/g;
598 $r->{'budget_name_indent'} = $moo;
600 $r->{'budget_spent'} = GetBudgetSpent( $r->{'budget_id'} );
602 $r->{'budget_amount_total'} = $r->{'budget_amount'};
604 # foreach sub-levels
605 my $unalloc_count ;
607 foreach my $sub (@subs_arr) {
608 my $sub_budget = GetBudget($sub);
610 $r->{budget_spent_sublevel} += GetBudgetSpent( $sub_budget->{'budget_id'} );
611 $unalloc_count += $sub_budget->{'budget_amount'};
614 return \@sort;
617 # -------------------------------------------------------------------
619 sub AddBudget {
620 my ($budget) = @_;
621 return InsertInTable("aqbudgets",$budget);
624 # -------------------------------------------------------------------
625 sub ModBudget {
626 my ($budget) = @_;
627 return UpdateInTable("aqbudgets",$budget);
630 # -------------------------------------------------------------------
631 sub DelBudget {
632 my ($budget_id) = @_;
633 my $dbh = C4::Context->dbh;
634 my $sth = $dbh->prepare("delete from aqbudgets where budget_id=?");
635 my $rc = $sth->execute($budget_id);
636 return $rc;
640 =head2 GetBudget
642 &GetBudget($budget_id);
644 get a specific budget
646 =cut
648 # -------------------------------------------------------------------
649 sub GetBudget {
650 my ( $budget_id ) = @_;
651 my $dbh = C4::Context->dbh;
652 my $query = "
653 SELECT *
654 FROM aqbudgets
655 WHERE budget_id=?
657 my $sth = $dbh->prepare($query);
658 $sth->execute( $budget_id );
659 my $result = $sth->fetchrow_hashref;
660 return $result;
663 =head2 GetBudgets
665 &GetBudgets($filter, $order_by);
667 gets all budgets
669 =cut
671 # -------------------------------------------------------------------
672 sub GetChildBudgetsSpent {
673 my ( $budget_id ) = @_;
674 my $dbh = C4::Context->dbh;
675 my $query = "
676 SELECT *
677 FROM aqbudgets
678 WHERE budget_parent_id=?
680 my $sth = $dbh->prepare($query);
681 $sth->execute( $budget_id );
682 my $result = $sth->fetchall_arrayref({});
683 my $total_spent = GetBudgetSpent($budget_id);
684 if ($result){
685 $total_spent += GetChildBudgetsSpent($_->{"budget_id"}) foreach @$result;
687 return $total_spent;
690 =head2 GetChildBudgetsSpent
692 &GetChildBudgetsSpent($budget-id);
694 gets the total spent of the level and sublevels of $budget_id
696 =cut
698 # -------------------------------------------------------------------
699 sub GetBudgets {
700 my ($filters,$orderby) = @_;
701 return SearchInTable("aqbudgets",$filters, $orderby, undef,undef, undef, "wide");
704 # -------------------------------------------------------------------
706 =head2 GetCurrencies
708 @currencies = &GetCurrencies;
710 Returns the list of all known currencies.
712 C<$currencies> is a array; its elements are references-to-hash, whose
713 keys are the fields from the currency table in the Koha database.
715 =cut
717 sub GetCurrencies {
718 my $dbh = C4::Context->dbh;
719 my $query = "
720 SELECT *
721 FROM currency
723 my $sth = $dbh->prepare($query);
724 $sth->execute;
725 my @results = ();
726 while ( my $data = $sth->fetchrow_hashref ) {
727 push( @results, $data );
729 return @results;
732 # -------------------------------------------------------------------
734 sub GetCurrency {
735 my $dbh = C4::Context->dbh;
736 my $query = "
737 SELECT * FROM currency where active = '1' ";
738 my $sth = $dbh->prepare($query);
739 $sth->execute;
740 my $r = $sth->fetchrow_hashref;
741 return $r;
744 =head2 ModCurrencies
746 &ModCurrencies($currency, $newrate);
748 Sets the exchange rate for C<$currency> to be C<$newrate>.
750 =cut
752 sub ModCurrencies {
753 my ( $currency, $rate ) = @_;
754 my $dbh = C4::Context->dbh;
755 my $query = qq|
756 UPDATE currency
757 SET rate=?
758 WHERE currency=? |;
759 my $sth = $dbh->prepare($query);
760 $sth->execute( $rate, $currency );
763 # -------------------------------------------------------------------
765 =head2 ConvertCurrency
767 $foreignprice = &ConvertCurrency($currency, $localprice);
769 Converts the price C<$localprice> to foreign currency C<$currency> by
770 dividing by the exchange rate, and returns the result.
772 If no exchange rate is found, e is one to one.
774 =cut
776 sub ConvertCurrency {
777 my ( $currency, $price ) = @_;
778 my $dbh = C4::Context->dbh;
779 my $query = "
780 SELECT rate
781 FROM currency
782 WHERE currency=?
784 my $sth = $dbh->prepare($query);
785 $sth->execute($currency);
786 my $cur = ( $sth->fetchrow_array() )[0];
787 unless ($cur) {
788 $cur = 1;
790 return ( $price / $cur );
793 =head2 _columns
795 returns an array containing fieldname followed by PRI as value if PRIMARY Key
797 =cut
799 sub _columns(;$) {
800 my $tablename=shift||"aqbudgets";
801 return @{C4::Context->dbh->selectcol_arrayref("SHOW columns from $tablename",{Columns=>[1,4]})};
804 sub _filter_fields{
805 my $budget=shift;
806 my $tablename=shift;
807 my @keys;
808 my @values;
809 my %columns= _columns($tablename);
810 #Filter Primary Keys of table
811 my $elements=join "|",grep {$columns{$_} ne "PRI"} keys %columns;
812 foreach my $field (grep {/\b($elements)\b/} keys %$budget){
813 $$budget{$field}=format_date_in_iso($$budget{$field}) if ($field=~/date/ && $$budget{$field} !~C4::Dates->regexp("iso"));
814 my $strkeys= " $field = ? ";
815 if ($field=~/branch/){
816 $strkeys="( $strkeys OR $field='' OR $field IS NULL) ";
818 push @values, $$budget{$field};
819 push @keys, $strkeys;
821 return (\@keys,\@values);
824 END { } # module clean-up code here (global destructor)
827 __END__
829 =head1 AUTHOR
831 Koha Development Team <http://koha-community.org/>
833 =cut