Bug 19377: Remove $5 charge from sample item types
[koha.git] / acqui / basketheader.pl
blob6de0a4d47ba2dd623c8bfc78e91edf26631dcf9e
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::Booksellers;
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::Booksellers->find( $booksellerid );
108 my $count = scalar @contractloop;
109 if ( $count > 0) {
110 $template->param(contractloop => \@contractloop,
111 basketcontractnumber => $basket->{'contractnumber'});
113 my @booksellers = Koha::Acquisition::Booksellers->search(
114 undef,
115 { order_by => { -asc => 'name' } } );
117 $template->param( add_form => 1,
118 basketname => $basket->{'basketname'},
119 basketnote => $basket->{'note'},
120 basketbooksellernote => $basket->{'booksellernote'},
121 booksellername => $bookseller->name,
122 booksellerid => $booksellerid,
123 basketno => $basketno,
124 booksellers => \@booksellers,
125 is_standing => $basket->{is_standing},
128 my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
129 my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
131 $template->param( billingplace => $billingplace );
132 $template->param( deliveryplace => $deliveryplace );
134 #End Edit
135 } elsif ( $op eq 'add_validate' ) {
136 #we are confirming the changes, save the basket
137 if ( $is_an_edit ) {
138 ModBasketHeader(
139 $basketno,
140 scalar $input->param('basketname'),
141 scalar $input->param('basketnote'),
142 scalar $input->param('basketbooksellernote'),
143 scalar $input->param('basketcontractnumber') || undef,
144 scalar $input->param('basketbooksellerid'),
145 scalar $input->param('deliveryplace'),
146 scalar $input->param('billingplace'),
147 scalar $input->param('is_standing') ? 1 : undef,
148 scalar $input->param('create_items')
150 } else { #New basket
151 $basketno = NewBasket(
152 $booksellerid,
153 $loggedinuser,
154 scalar $input->param('basketname'),
155 scalar $input->param('basketnote'),
156 scalar $input->param('basketbooksellernote'),
157 scalar $input->param('basketcontractnumber') || undef,
158 scalar $input->param('deliveryplace'),
159 scalar $input->param('billingplace'),
160 scalar $input->param('is_standing') ? 1 : undef,
161 scalar $input->param('create_items')
164 print $input->redirect('basket.pl?basketno='.$basketno);
165 exit 0;
167 output_html_with_http_headers $input, $cookie, $template->output;