3 #script to add basket and edit header options (name, notes and contractnumber)
4 #written by john.soros@biblibre.com 15/09/2008
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>.
29 This script is used to edit the basket's "header", or add a new basket, the header contains the supplier ID,
30 notes to the supplier, local notes, and the contractnumber, which identifies the basket to a specific contract.
38 C<$booksellerid> is the id of the supplier we add the basket to.
42 If it exists, C<$basketno> is the basket we edit
51 use C4::Auth qw( get_template_and_user );
52 use C4::Output qw( output_html_with_http_headers );
53 use C4::Acquisition qw( GetBasket ModBasket ModBasketHeader NewBasket );
54 use C4::Contract qw( GetContracts GetContract );
56 use Koha::Acquisition::Booksellers;
57 use Koha::Acquisition::Baskets;
58 use Koha::AdditionalFields;
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => "acqui/basketheader.tt",
66 flagsrequired => { acquisition => 'order_manage' },
71 my $booksellerid = $input->param('booksellerid');
72 my $basketno = $input->param('basketno');
74 my $op = $input->param('op');
75 my $is_an_edit = $input->param('is_an_edit');
77 $template->param( available_additional_fields => Koha::AdditionalFields->search( { tablename => 'aqbasket' } ) );
79 if ( $op eq 'add_form' ) {
83 $basket = GetBasket($basketno);
84 if (! $booksellerid) {
85 $booksellerid=$basket->{'booksellerid'};
87 my $contracts = GetContracts({
88 booksellerid => $booksellerid,
92 @contractloop = @$contracts;
94 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
98 $template->param( is_an_edit => 1);
100 additional_field_values => { map {
101 $_->field->id => $_->value
102 } Koha::Acquisition::Baskets->find($basketno)->additional_field_values->as_list },
107 my $contracts = GetContracts({
108 booksellerid => $booksellerid,
111 push(@contractloop, @$contracts);
113 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
114 my $count = scalar @contractloop;
116 $template->param(contractloop => \@contractloop,
117 basketcontractnumber => $basket->{'contractnumber'});
119 my $booksellers = Koha::Acquisition::Booksellers->search(
121 { order_by => { -asc => 'name' } } );
123 $template->param( add_form => 1,
124 basketname => $basket->{'basketname'},
125 basketnote => $basket->{'note'},
126 basketbooksellernote => $basket->{'booksellernote'},
127 booksellername => $bookseller->name,
128 booksellerid => $booksellerid,
129 basketno => $basketno,
130 booksellers => $booksellers,
131 is_standing => $basket->{is_standing},
132 create_items => $basket->{create_items},
135 my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
136 my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
138 $template->param( billingplace => $billingplace );
139 $template->param( deliveryplace => $deliveryplace );
142 } elsif ( $op eq 'add_validate' ) {
143 #we are confirming the changes, save the basket
147 scalar $input->param('basketname'),
148 scalar $input->param('basketnote'),
149 scalar $input->param('basketbooksellernote'),
150 scalar $input->param('basketcontractnumber') || undef,
151 scalar $input->param('basketbooksellerid'),
152 scalar $input->param('deliveryplace'),
153 scalar $input->param('billingplace'),
154 scalar $input->param('is_standing') ? 1 : undef,
155 scalar $input->param('create_items')
158 $basketno = NewBasket(
159 scalar $input->param('basketbooksellerid'),
161 scalar $input->param('basketname'),
162 scalar $input->param('basketnote'),
163 scalar $input->param('basketbooksellernote'),
164 scalar $input->param('basketcontractnumber') || undef,
165 scalar $input->param('deliveryplace'),
166 scalar $input->param('billingplace'),
167 scalar $input->param('is_standing') ? 1 : undef,
168 scalar $input->param('create_items')
172 my @additional_fields;
173 my $basket_fields = Koha::AdditionalFields->search({ tablename => 'aqbasket' });
174 while ( my $field = $basket_fields->next ) {
175 my $value = $input->param('additional_field_' . $field->id);
176 push @additional_fields, {
181 Koha::Acquisition::Baskets->find($basketno)->set_additional_fields(\@additional_fields);
183 print $input->redirect('basket.pl?basketno='.$basketno);
186 output_html_with_http_headers $input, $cookie, $template->output;