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
54 use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
55 use C4::Contract qw/GetContracts/;
57 use Koha::Acquisition::Booksellers;
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "acqui/basketheader.tt",
66 flagsrequired => { acquisition => 'order_manage' },
72 my $booksellerid = $input->param('booksellerid');
73 my $basketno = $input->param('basketno');
75 my $op = $input ->param('op');
76 my $is_an_edit= $input ->param('is_an_edit');
78 if ( $op eq 'add_form' ) {
82 $basket = GetBasket($basketno);
83 if (! $booksellerid) {
84 $booksellerid=$basket->{'booksellerid'};
86 my $contracts = GetContracts({
87 booksellerid => $booksellerid,
91 @contractloop = @$contracts;
93 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
97 $template->param( is_an_edit => 1);
101 my $contracts = GetContracts({
102 booksellerid => $booksellerid,
105 push(@contractloop, @$contracts);
107 my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid );
108 my $count = scalar @contractloop;
110 $template->param(contractloop => \@contractloop,
111 basketcontractnumber => $basket->{'contractnumber'});
113 my @booksellers = Koha::Acquisition::Booksellers->search;
114 $template->param( add_form => 1,
115 basketname => $basket->{'basketname'},
116 basketnote => $basket->{'note'},
117 basketbooksellernote => $basket->{'booksellernote'},
118 booksellername => $bookseller->name,
119 booksellerid => $booksellerid,
120 basketno => $basketno,
121 booksellers => \@booksellers,
122 is_standing => $basket->{is_standing},
125 my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
126 my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
128 $template->param( billingplace => $billingplace );
129 $template->param( deliveryplace => $deliveryplace );
132 } elsif ( $op eq 'add_validate' ) {
133 #we are confirming the changes, save the basket
137 $input->param('basketname'),
138 $input->param('basketnote'),
139 $input->param('basketbooksellernote'),
140 $input->param('basketcontractnumber') || undef,
141 $input->param('basketbooksellerid'),
142 $input->param('deliveryplace'),
143 $input->param('billingplace'),
144 $input->param('is_standing') ? 1 : undef,
147 $basketno = NewBasket(
150 $input->param('basketname'),
151 $input->param('basketnote'),
152 $input->param('basketbooksellernote'),
153 $input->param('basketcontractnumber') || undef,
154 $input->param('deliveryplace'),
155 $input->param('billingplace'),
156 $input->param('is_standing') ? 1 : undef,
159 print $input->redirect('basket.pl?basketno='.$basketno);
162 output_html_with_http_headers $input, $cookie, $template->output;