Bug 20434: Add UNIMARC field 214 and its subfields
[koha.git] / C4 / Contract.pm
blob0de49ad361764389587870e9ae776c36d80265ee
1 package C4::Contract;
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>.
20 use Modern::Perl;
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Context;
24 use Koha::Database;
26 use vars qw(@ISA @EXPORT);
28 BEGIN {
29 require Exporter;
30 @ISA = qw(Exporter);
31 @EXPORT = qw(
32 &GetContracts
33 &GetContract
34 &AddContract
35 &ModContract
36 &DelContract
40 =head1 NAME
42 C4::Contract - Koha functions for dealing with bookseller contracts.
44 =head1 SYNOPSIS
46 use C4::Contract;
48 =head1 DESCRIPTION
50 The functions in this module deal with contracts. They allow to
51 add a new contract, to modify it or to get some informations around
52 a contract.
54 =cut
57 =head2 GetContracts
59 $contractlist = GetContracts({
60 booksellerid => $booksellerid,
61 activeonly => $activeonly
62 });
64 Looks up the contracts that belong to a bookseller
66 Returns a list of contracts
68 =over
70 =item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
72 =item C<$activeonly> if exists get only contracts that are still active.
74 =back
76 =cut
78 sub GetContracts {
79 my ($filters) = @_;
80 if( $filters->{activeonly} ) {
81 $filters->{contractenddate} = {'>=' => \'now()'};
82 delete $filters->{activeonly};
85 my $rs = Koha::Database->new()->schema->resultset('Aqcontract');
86 $rs = $rs->search($filters);
87 $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
88 return [ $rs->all ];
91 =head2 GetContract
93 $contract = GetContract( { contractnumber => $contractnumber } );
95 Looks up the contract that has PRIMKEY (contractnumber) value $contractID
97 Returns a contract
99 =cut
101 sub GetContract {
102 my ($params) = @_;
103 my $contractnumber = $params->{contractnumber};
105 return unless $contractnumber;
107 my $contracts = GetContracts({
108 contractnumber => $contractnumber,
110 return $contracts->[0];
113 sub AddContract {
114 my ($contract) = @_;
115 return unless($contract->{booksellerid});
117 my $rs = Koha::Database->new()->schema->resultset('Aqcontract');
118 return $rs->create($contract)->id;
121 sub ModContract {
122 my ($contract) = @_;
123 my $result = Koha::Database->new()->schema->resultset('Aqcontract')->find($contract);
124 return unless($result);
126 $result = $result->update($contract);
127 return $result->in_storage;
130 sub DelContract {
131 my ($contract) = @_;
132 return unless($contract->{contractnumber});
134 my $result = Koha::Database->new()->schema->resultset('Aqcontract')->find($contract);
135 return unless($result);
137 eval { $result->delete };
138 return !( $result->in_storage );
143 __END__
145 =head1 AUTHOR
147 Koha Development Team <http://koha-community.org/>
149 =cut