3 # Copyright 2009-2010 BibLibre SARL
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 #use warnings; FIXME - Bug 2505
26 use vars qw(@ISA @EXPORT);
29 # set the version for version checking
43 C4::Contract - Koha functions for dealing with bookseller contracts.
51 The functions in this module deal with contracts. They allow to
52 add a new contract, to modify it or to get some informations around
60 $contractlist = GetContracts({
61 booksellerid => $booksellerid,
62 activeonly => $activeonly
65 Looks up the contracts that belong to a bookseller
67 Returns a list of contracts
71 =item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
73 =item C<$activeonly> if exists get only contracts that are still active.
81 if( $filters->{activeonly} ) {
82 $filters->{contractenddate} = {'>=' => \'now()'};
83 delete $filters->{activeonly};
86 my $rs = Koha::Database->new()->schema->resultset('Aqcontract');
87 $rs = $rs->search($filters);
88 $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
94 $contract = GetContract( { contractnumber => $contractnumber } );
96 Looks up the contract that has PRIMKEY (contractnumber) value $contractID
104 my $contractnumber = $params->{contractnumber};
106 return unless $contractnumber;
108 my $contracts = GetContracts({
109 contractnumber => $contractnumber,
111 return $contracts->[0];
116 return unless($contract->{booksellerid});
118 my $rs = Koha::Database->new()->schema->resultset('Aqcontract');
119 return $rs->create($contract)->id;
124 my $result = Koha::Database->new()->schema->resultset('Aqcontract')->find($contract);
125 return unless($result);
127 $result = $result->update($contract);
128 return $result->in_storage;
133 return unless($contract->{contractnumber});
135 my $result = Koha::Database->new()->schema->resultset('Aqcontract')->find($contract);
136 return unless($result);
138 eval { $result->delete };
139 return !( $result->in_storage );
148 Koha Development Team <http://koha-community.org/>