Bug 17301 - Add callnumber to label-edit-batch.pl
[koha.git] / acqui / basketheader.pl
blobc0db854e3da261ecdef84c097befc23a25ee1382
1 #!/usr/bin/perl
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>.
23 =head1 NAME
25 basketheader.pl
27 =head1 DESCRIPTION
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.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item booksellerid
38 C<$booksellerid> is the id of the supplier we add the basket to.
40 =item basketid
42 If it exists, C<$basketno> is the basket we edit
44 =back
46 =cut
48 use strict;
49 use warnings;
50 use CGI qw ( -utf8 );
51 use C4::Context;
52 use C4::Auth;
53 use C4::Output;
54 use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/;
55 use C4::Contract qw/GetContracts/;
57 use Koha::Acquisition::Bookseller;
59 my $input = new CGI;
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "acqui/basketheader.tt",
63 query => $input,
64 type => "intranet",
65 authnotrequired => 0,
66 flagsrequired => { acquisition => 'order_manage' },
67 debug => 1,
71 #parameters:
72 my $booksellerid = $input->param('booksellerid');
73 my $basketno = $input->param('basketno');
74 my $basket;
75 my $op = $input ->param('op');
76 my $is_an_edit= $input ->param('is_an_edit');
78 if ( $op eq 'add_form' ) {
79 my @contractloop;
80 if ( $basketno ) {
81 #this is an edit
82 $basket = GetBasket($basketno);
83 if (! $booksellerid) {
84 $booksellerid=$basket->{'booksellerid'};
86 my $contracts = GetContracts({
87 booksellerid => $booksellerid,
88 activeonly => 1,
89 });
91 @contractloop = @$contracts;
92 for (@contractloop) {
93 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
94 $_->{'selected'} = 1;
97 $template->param( is_an_edit => 1);
98 } else {
99 #new basket
100 my $basket;
101 my $contracts = GetContracts({
102 booksellerid => $booksellerid,
103 activeonly => 1,
105 push(@contractloop, @$contracts);
107 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
108 my $count = scalar @contractloop;
109 if ( $count > 0) {
110 $template->param(contractloop => \@contractloop,
111 basketcontractnumber => $basket->{'contractnumber'});
113 my @booksellers = Koha::Acquisition::Bookseller->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 );
131 #End Edit
132 } elsif ( $op eq 'add_validate' ) {
133 #we are confirming the changes, save the basket
134 if ( $is_an_edit ) {
135 ModBasketHeader(
136 $basketno,
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,
146 } else { #New basket
147 $basketno = NewBasket(
148 $booksellerid,
149 $loggedinuser,
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);
160 exit 0;
162 output_html_with_http_headers $input, $cookie, $template->output;