3 #script to administer the contract table
4 #written 02/09/2008 by john.soros@biblibre.com
6 # Copyright 2008-2009 BibLibre SARL
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 use C4::Auth qw( get_template_and_user );
27 use C4::Output qw( output_html_with_http_headers );
35 use Koha::DateUtils qw( dt_from_string );
37 use Koha::Acquisition::Booksellers;
40 my $contractnumber = $input->param('contractnumber');
41 my $booksellerid = $input->param('booksellerid');
42 my $op = $input->param('op') || 'list';
44 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
46 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47 { template_name => "admin/aqcontract.tt",
50 flagsrequired => { acquisition => 'contracts_manage' },
55 contractnumber => $contractnumber,
56 booksellerid => $booksellerid,
57 booksellername => $bookseller->name,
58 basketcount => $bookseller->baskets->count,
59 active => $bookseller->active,
60 subscriptioncount => $bookseller->subscriptions->count,
63 #ADD_FORM: called if $op is 'add_form'. Used to create form to add or modify a record
64 if ( $op eq 'add_form' ) {
65 $template->param( add_form => 1 );
67 # if contractnumber exists, it's a modify action, so read values to modify...
68 if ($contractnumber) {
69 my $contract = GetContract({
70 contractnumber => $contractnumber
74 contractnumber => $contract->{contractnumber},
75 contractname => $contract->{contractname},
76 contractdescription => $contract->{contractdescription},
77 contractstartdate => $contract->{contractstartdate},
78 contractenddate => $contract->{contractenddate},
82 contractnumber => undef,
83 contractname => undef,
84 contractdescription => undef,
85 contractstartdate => undef,
86 contractenddate => undef,
92 #ADD_VALIDATE: called by add_form, used to insert/modify data in DB
93 elsif ( $op eq 'add_validate' ) {
94 ## Please see file perltidy.ERR
95 $template->param( add_validate => 1 );
97 my $is_a_modif = $input->param("is_a_modif");
99 my $contractstart_dt = $input->param('contractstartdate');
100 my $contractend_dt = $input->param('contractenddate');
101 unless ( $contractstart_dt and $contractend_dt ) {
102 my $today = dt_from_string;
103 $contractstart_dt ||= $today;
104 $contractend_dt ||= $today;
109 contractstartdate => $contractstart_dt,
110 contractenddate => $contractend_dt,
111 contractname => scalar $input->param('contractname'),
112 contractdescription => scalar $input->param('contractdescription'),
113 booksellerid => scalar $input->param('booksellerid'),
114 contractnumber => scalar $input->param('contractnumber'),
118 contractname => scalar $input->param('contractname'),
119 contractdescription => scalar $input->param('contractdescription'),
120 booksellerid => scalar $input->param('booksellerid'),
121 contractstartdate => scalar $input->param('contractstartdate'),
122 contractenddate => scalar $input->param('contractenddate'),
126 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
129 # END $OP eq ADD_VALIDATE
131 #DELETE_CONFIRM: called by default form, used to confirm deletion of data in DB
132 elsif ( $op eq 'delete_confirm' ) {
133 $template->param( delete_confirm => 1 );
135 my $contract = GetContract( { contractnumber => $contractnumber } );
138 contractnumber => $$contract{contractnumber},
139 contractname => $$contract{contractname},
140 contractdescription => $$contract{contractdescription},
141 contractstartdate => $$contract{contractstartdate},
142 contractenddate => $$contract{contractenddate},
145 # END $OP eq DELETE_CONFIRM
147 #DELETE_CONFIRMED: called by delete_confirm, used to effectively confirm deletion of data in DB
148 elsif ( $op eq 'delete_confirmed' ) {
149 my $deleted = DelContract( { contractnumber => $contractnumber } );
152 print $input->redirect("/cgi-bin/koha/acqui/supplier.pl?booksellerid=$booksellerid");
155 $template->param( error => 'not_deleted' );
161 # DEFAULT: Builds a list of contracts and displays them
162 if ( $op eq 'list' ) {
163 $template->param(else => 1);
166 my @contracts = @{GetContracts( { booksellerid => $booksellerid } )};
168 $template->param(loop => \@contracts);
170 #---- END $OP eq DEFAULT
173 output_html_with_http_headers $input, $cookie, $template->output;