@@ -, +, @@ GetContracts from C4::Acquisition.pm to C4::Contract.pm - the subroutines GetContract and GetContracts has been moved from C4::Acquisition.pm to C4::Contract.pm and adapted for a general use - adaptation of acqui/basket.pl, acqui/basketheader.pl, acqui/neworderempty.pl, acqui/supplier.pl and admin/aqcontract.pl - the unit tests for the module C4::Contract.pm --- C4/Acquisition.pm | 74 +++++--------------------------------------- C4/Contract.pm | 84 +++++++++++++++++++++++++++++++++++++++++++++----- acqui/basket.pl | 9 ++++-- acqui/basketheader.pl | 16 ++++++++-- acqui/neworderempty.pl | 5 ++- acqui/supplier.pl | 5 ++- admin/aqcontract.pl | 9 +++--- 7 files changed, 115 insertions(+), 87 deletions(-) --- a/C4/Acquisition.pm +++ a/C4/Acquisition.pm @@ -27,6 +27,7 @@ use C4::Dates qw(format_date format_date_in_iso); use MARC::Record; use C4::Suggestions; use C4::Biblio; +use C4::Contract; use C4::Debug; use C4::SQLHelper qw(InsertInTable UpdateInTable); use C4::Bookseller qw(GetBookSellerFromId); @@ -65,7 +66,6 @@ BEGIN { &NewOrderItem &ModItemOrder &GetParcels &GetParcel - &GetContracts &GetContract &GetInvoices &GetInvoice @@ -293,7 +293,9 @@ sub GetBasketAsCSV { my ($basketno, $cgi) = @_; my $basket = GetBasket($basketno); my @orders = GetOrders($basketno); - my $contract = GetContract($basket->{'contractnumber'}); + my $contract = GetContract({ + contractnumber => $basket->{'contractnumber'} + }); my $template = C4::Templates::gettemplate("acqui/csv/basket.tmpl", "intranet", $cgi); @@ -361,7 +363,9 @@ sub GetBasketGroupAsCSV { my @rows; for my $basket (@$baskets) { my @orders = GetOrders( $$basket{basketno} ); - my $contract = GetContract( $$basket{contractnumber} ); + my $contract = GetContract({ + contractnumber => $$basket{contractnumber} + }); my $bookseller = GetBookSellerFromId( $$basket{booksellerid} ); my $basketgroup = GetBasketgroup( $$basket{basketgroupid} ); @@ -2453,72 +2457,8 @@ sub GetRecentAcqui { return $results; } -=head3 GetContracts - - $contractlist = &GetContracts($booksellerid, $activeonly); - -Looks up the contracts that belong to a bookseller - -Returns a list of contracts - -=over - -=item C<$booksellerid> is the "id" field in the "aqbooksellers" table. - -=item C<$activeonly> if exists get only contracts that are still active. - -=back - -=cut - -sub GetContracts { - my ( $booksellerid, $activeonly ) = @_; - my $dbh = C4::Context->dbh; - my $query; - if (! $activeonly) { - $query = " - SELECT * - FROM aqcontract - WHERE booksellerid=? - "; - } else { - $query = "SELECT * - FROM aqcontract - WHERE booksellerid=? - AND contractenddate >= CURDATE( )"; - } - my $result_set = - $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid ); - return @{$result_set}; -} - #------------------------------------------------------------# -=head3 GetContract - - $contract = &GetContract($contractID); - -Looks up the contract that has PRIMKEY (contractnumber) value $contractID - -Returns a contract - -=cut - -sub GetContract { - my ( $contractno ) = @_; - my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM aqcontract - WHERE contractnumber=? - "; - - my $sth = $dbh->prepare($query); - $sth->execute( $contractno ); - my $result = $sth->fetchrow_hashref; - return $result; -} - =head3 AddClaim =over --- a/C4/Contract.pm +++ a/C4/Contract.pm @@ -17,8 +17,10 @@ package C4::Contract; # with Koha; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +use Modern::Perl; use strict; #use warnings; FIXME - Bug 2505 +use C4::Context; use C4::SQLHelper qw(:all); use vars qw($VERSION @ISA @EXPORT); @@ -29,10 +31,11 @@ BEGIN { require Exporter; @ISA = qw(Exporter); @EXPORT = qw( - &GetContract - &AddContract - &ModContract - &DelContract + &GetContracts + &GetContract + &AddContract + &ModContract + &DelContract ); } @@ -50,12 +53,79 @@ The functions in this module deal with contracts. They allow to add a new contract, to modify it or to get some informations around a contract. -This module is just a wrapper for C4::SQLHelper functions, so take a look at -SQLHelper centralised documentation to know how to use the following subs. +=cut + + +=head2 GetContracts + +$contractlist = GetContracts({ + booksellerid => $booksellerid, + activeonly => $activeonly +}); + +Looks up the contracts that belong to a bookseller + +Returns a list of contracts + +=over + +=item C<$booksellerid> is the "id" field in the "aqbooksellers" table. + +=item C<$activeonly> if exists get only contracts that are still active. + +=back =cut -sub GetContract { SearchInTable("aqcontract", shift); } +sub GetContracts { + my ($params) = @_; + my $booksellerid = $params->{booksellerid}; + my $activeonly = $params->{activeonly}; + + my $dbh = C4::Context->dbh; + my $query = "SELECT * FROM aqcontract"; + my $result_set; + if($booksellerid) { + $query .= " WHERE booksellerid=?"; + + if($activeonly) { + $query .= " AND contractenddate >= CURDATE( )"; + } + + $result_set = $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid ); + } + else { + $result_set = $dbh->selectall_arrayref( $query, { Slice => {} } ); + } + + return $result_set; +} + +=head2 GetContract + +$contract = GetContract( { contractnumber => $contractnumber } ); + +Looks up the contract that has PRIMKEY (contractnumber) value $contractID + +Returns a contract + +=cut + +sub GetContract { + my ($params) = @_; + my $contractno = $params->{contractnumber}; + + my $dbh = C4::Context->dbh; + my $query = "SELECT * FROM aqcontract WHERE contractnumber=?"; + + my $sth = $dbh->prepare($query); + $sth->execute($contractno); + my $result = $sth->fetchrow_hashref; + return $result; +} + + +#sub GetContract { SearchInTable("aqcontract", shift); } sub AddContract { InsertInTable("aqcontract", shift); } --- a/acqui/basket.pl +++ a/acqui/basket.pl @@ -30,6 +30,7 @@ use C4::Acquisition; use C4::Budgets; use C4::Branch; use C4::Bookseller qw( GetBookSellerFromId); +use C4::Contract; use C4::Debug; use C4::Biblio; use C4::Members qw/GetMember/; #needed for permissions checking for changing basketgroup of a basket @@ -167,7 +168,9 @@ if ( $op eq 'delete_confirm' ) { } $basket->{creationdate} = "" unless ( $basket->{creationdate} ); $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} ); - my $contract = &GetContract($basket->{contractnumber}); + my $contract = GetContract({ + contractnumber => $basket->{contractnumber} + }); $template->param( basketno => $basketno, basketname => $basket->{'basketname'}, @@ -370,7 +373,9 @@ if ( $op eq 'delete_confirm' ) { push @cancelledorders_loop, $line; } - my $contract = &GetContract($basket->{contractnumber}); + my $contract = GetContract({ + contractnumber => $basket->{contractnumber} + }); my @orders = GetOrders($basketno); if ($basket->{basketgroupid}){ --- a/acqui/basketheader.pl +++ a/acqui/basketheader.pl @@ -52,8 +52,9 @@ use C4::Context; use C4::Auth; use C4::Branch; use C4::Output; -use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/; +use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/; use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/; +use C4::Contract qw/GetContracts/; my $input = new CGI; @@ -84,7 +85,12 @@ if ( $op eq 'add_form' ) { if (! $booksellerid) { $booksellerid=$basket->{'booksellerid'}; } - @contractloop = &GetContracts($booksellerid, 1); + my $contracts = GetContracts({ + booksellerid => $booksellerid, + activeonly => 1, + }); + + @contractloop = @$contracts; for (@contractloop) { if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) { $_->{'selected'} = 1; @@ -94,7 +100,11 @@ if ( $op eq 'add_form' ) { } else { #new basket my $basket; - push(@contractloop, &GetContracts($booksellerid, 1)); + my $contracts = GetContracts({ + booksellerid => $booksellerid, + activeonly => 1, + }); + push(@contractloop, @$contracts); } my $bookseller = GetBookSellerFromId($booksellerid); my $count = scalar @contractloop; --- a/acqui/neworderempty.pl +++ a/acqui/neworderempty.pl @@ -78,6 +78,7 @@ use C4::Input; use C4::Bookseller qw/ GetBookSellerFromId /; use C4::Acquisition; +use C4::Contract; use C4::Suggestions; # GetSuggestion use C4::Biblio; # GetBiblioData GetMarcPrice use C4::Items; #PrepareItemRecord @@ -132,7 +133,9 @@ our $basket = GetBasket($basketno); $booksellerid = $basket->{booksellerid} unless $booksellerid; my $bookseller = GetBookSellerFromId($booksellerid); -my $contract = &GetContract($basket->{contractnumber}); +my $contract = GetContract({ + contractnumber => $basket->{contractnumber} +}); #simple parameters reading (all in one :-) our $params = $input->Vars; --- a/acqui/supplier.pl +++ a/acqui/supplier.pl @@ -43,7 +43,7 @@ To know the bookseller this script has to display details. use strict; use warnings; use C4::Auth; -use C4::Contract qw/GetContract/; +use C4::Contract; use C4::Biblio; use C4::Output; use CGI; @@ -70,8 +70,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( #build array for currencies if ( $op eq 'display' ) { - - my $contracts = GetContract( { booksellerid => $booksellerid } ); + my $contracts = GetContracts( { booksellerid => $booksellerid } ); $template->param( booksellerid => $booksellerid, --- a/admin/aqcontract.pl +++ a/admin/aqcontract.pl @@ -61,8 +61,9 @@ if ( $op eq 'add_form' ) { # if contractnumber exists, it's a modify action, so read values to modify... if ($contractnumber) { - my $contract = - @{ GetContract( { contractnumber => $contractnumber } ) }[0]; + my $contract = GetContract({ + contractnumber => $contractnumber + }); $template->param( contractnumber => $contract->{contractnumber}, @@ -118,7 +119,7 @@ elsif ( $op eq 'add_validate' ) { elsif ( $op eq 'delete_confirm' ) { $template->param( delete_confirm => 1 ); - my $contract = @{GetContract( { contractnumber => $contractnumber } )}[0]; + my $contract = GetContract( { contractnumber => $contractnumber } ); $template->param( contractnumber => $$contract{contractnumber}, @@ -146,7 +147,7 @@ else { $template->param(else => 1); # get contracts - my @contracts = @{GetContract( { booksellerid => $booksellerid } )}; + my @contracts = @{GetContracts( { booksellerid => $booksellerid } )}; # format dates for ( @contracts ) { --