From d8513105aa60635bdc392dca45caa9f13a930979 Mon Sep 17 00:00:00 2001 From: toins Date: Mon, 31 Jul 2006 14:36:40 +0000 Subject: [PATCH] 3 New functions : NewBookFund, DelBookFund & SearchBookFund. --- C4/Bookfund.pm | 117 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/C4/Bookfund.pm b/C4/Bookfund.pm index ba4b322788..e646f26de8 100755 --- a/C4/Bookfund.pm +++ b/C4/Bookfund.pm @@ -46,9 +46,11 @@ They allow to get and/or set some informations for a specific budget or currency @ISA = qw(Exporter); @EXPORT = qw( &GetBookFund &GetBookFunds &GetBookFundBreakdown &GetCurrencies + &NewBookFund &ModBookFund &ModCurrencies &Countbookfund &ConvertCurrency + &DelBookFund ); =head1 FUNCTIONS @@ -280,6 +282,33 @@ sub GetBookFundBreakdown { return ( $spent, $comtd ); } +=head3 NewBookFund + +=over 4 + +&NewBookFund(bookfundid, bookfundname, branchcode); + +this function create a new bookfund into the database. + +=back + +=cut + +sub NewBookFund{ + my ($bookfundid, $bookfundname, $branchcode) = @_; + $branchcode = undef unless $branchcode; + my $dbh = C4::Context->dbh; + my $query = " + INSERT + INTO aqbookfund + (bookfundid, bookfundname, branchcode) + VALUES + (?, ?, ?) + "; + my $sth=$dbh->prepare($query); + $sth->execute($bookfundid,$bookfundname,$branchcode); +} + #-------------------------------------------------------------# =head3 ModBookFund @@ -319,6 +348,64 @@ sub ModBookFund { #-------------------------------------------------------------# +=head3 SearchBookFund + +=over 4 +@results = SearchBookFund( + $bookfundid,$filter,$filter_bookfundid, + $filter_bookfundname,$filter_branchcode); + +this function searchs among the bookfunds corresponding to our filtering rules. + +=back + +=cut + +sub SearchBookFund { + my $dbh = C4::Context->dbh; + my ($filter, + $filter_bookfundid, + $filter_bookfundname, + $filter_branchcode + ) = @_; + + my @bindings; + + my $query = " + SELECT bookfundid, + bookfundname, + bookfundgroup, + branchcode + FROM aqbookfund + WHERE 1 = 1"; + + if ($filter) { + if ($filter_bookfundid) { + $query.= "AND bookfundid = ?"; + push @bindings, $filter_bookfundid; + } + if ($filter_bookfundname) { + $query.= "AND bookfundname like ?"; + push @bindings, '%'.$filter_bookfundname.'%'; + } + if ($filter_branchcode) { + $query.= "AND branchcode = ?"; + push @bindings, $filter_branchcode; + } + } + $query.= "ORDER BY bookfundid"; + + my $sth = $dbh->prepare($query); + $sth->execute(@bindings); + my @results; + while (my $row = $sth->fetchrow_hashref) { + push @results, $row; + } + return @results; +} + +#-------------------------------------------------------------# + =head3 ModCurrencies =over 4 @@ -408,6 +495,36 @@ sub ConvertCurrency { return ( $price / $cur ); } +#-------------------------------------------------------------# + +=head3 DelBookFund + +=over 4 + +&DelBookFund($bookfundid); +this function delete a bookfund which has $bokfundid as parameter on aqbookfund table and delete the approriate budget. + +=back + +=cut + +sub DelBookFund { + my $bookfundid = shift; + my $dbh = C4::Context->dbh; + my $query = " + DELETE FROM aqbookfund + WHERE bookfundid=? + "; + my $sth=$dbh->prepare($query); + $sth->execute($bookfundid); + $sth->finish; + $query = " + DELETE FROM aqbudget where bookfundid=? + "; + $sth=$dbh->prepare($query); + $sth->execute($bookfundid); + $sth->finish; +} END { } # module clean-up code here (global destructor) -- 2.39.5