Bug 12493: moving the subroutines GetContract and GetContracts from C4::Acquisition...
[koha.git] / C4 / Contract.pm
1 package C4::Contract;
2
3 # Copyright 2009-2010 BibLibre SARL
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Context;
24 use C4::SQLHelper qw(:all);
25
26 use vars qw($VERSION @ISA @EXPORT);
27
28 BEGIN {
29         # set the version for version checking
30     $VERSION = 3.07.00.049;
31     require Exporter;
32         @ISA    = qw(Exporter);
33         @EXPORT = qw(
34         &GetContracts
35         &GetContract
36         &AddContract
37         &ModContract
38         &DelContract
39         );
40 }
41
42 =head1 NAME
43
44 C4::Contract - Koha functions for dealing with bookseller contracts.
45
46 =head1 SYNOPSIS
47
48 use C4::Contract;
49
50 =head1 DESCRIPTION
51
52 The functions in this module deal with contracts. They allow to
53 add a new contract, to modify it or to get some informations around
54 a contract.
55
56 =cut
57
58
59 =head2 GetContracts
60
61 $contractlist = GetContracts({
62     booksellerid => $booksellerid,
63     activeonly => $activeonly
64 });
65
66 Looks up the contracts that belong to a bookseller
67
68 Returns a list of contracts
69
70 =over
71
72 =item C<$booksellerid> is the "id" field in the "aqbooksellers" table.
73
74 =item C<$activeonly> if exists get only contracts that are still active.
75
76 =back
77
78 =cut
79
80 sub GetContracts {
81     my ($params) = @_;
82     my $booksellerid = $params->{booksellerid};
83     my $activeonly = $params->{activeonly};
84
85     my $dbh = C4::Context->dbh;
86     my $query = "SELECT * FROM aqcontract";
87     my $result_set;
88     if($booksellerid) {
89         $query .= " WHERE booksellerid=?";
90
91         if($activeonly) {
92             $query .= " AND contractenddate >= CURDATE( )";
93         }
94
95         $result_set = $dbh->selectall_arrayref( $query, { Slice => {} }, $booksellerid );
96     }
97     else {
98         $result_set = $dbh->selectall_arrayref( $query, { Slice => {} } );
99     }
100
101     return $result_set;
102 }
103
104 =head2 GetContract
105
106 $contract = GetContract( { contractnumber => $contractnumber } );
107
108 Looks up the contract that has PRIMKEY (contractnumber) value $contractID
109
110 Returns a contract
111
112 =cut
113
114 sub GetContract {
115     my ($params) = @_;
116     my $contractno = $params->{contractnumber};
117
118     my $dbh = C4::Context->dbh;
119     my $query = "SELECT * FROM aqcontract WHERE contractnumber=?";
120
121     my $sth = $dbh->prepare($query);
122     $sth->execute($contractno);
123     my $result = $sth->fetchrow_hashref;
124     return $result;
125 }
126
127
128 #sub GetContract { SearchInTable("aqcontract", shift); }
129
130 sub AddContract { InsertInTable("aqcontract", shift); }
131
132 sub ModContract { UpdateInTable("aqcontract", shift); }
133
134 sub DelContract { DeleteInTable("aqcontract", shift); }
135
136 1;
137
138 __END__
139
140 =head1 AUTHOR
141
142 Koha Development Team <http://koha-community.org/>
143
144 =cut