Bug 10274: Execute sql queries into a transaction
[koha.git] / acqui / basketheader.pl
blob93bd7f8ebff77345c9995cf9e3a96ae3f9e0e87f
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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
51 use C4::Context;
52 use C4::Auth;
53 use C4::Branch;
54 use C4::Output;
55 use C4::Acquisition qw/GetBasket NewBasket GetContracts ModBasketHeader/;
56 use C4::Bookseller qw/GetBookSellerFromId GetBookSeller/;
59 my $input = new CGI;
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "acqui/basketheader.tmpl",
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 $branches = GetBranches;
75 my $basket;
76 my $op = $input ->param('op');
77 my $is_an_edit= $input ->param('is_an_edit');
79 if ( $op eq 'add_form' ) {
80 my @contractloop;
81 if ( $basketno ) {
82 #this is an edit
83 $basket = GetBasket($basketno);
84 if (! $booksellerid) {
85 $booksellerid=$basket->{'booksellerid'};
87 @contractloop = &GetContracts($booksellerid, 1);
88 for (@contractloop) {
89 if ( $basket->{'contractnumber'} eq $_->{'contractnumber'} ) {
90 $_->{'selected'} = 1;
93 $template->param( is_an_edit => 1);
94 } else {
95 #new basket
96 my $basket;
97 push(@contractloop, &GetContracts($booksellerid, 1));
99 my $bookseller = GetBookSellerFromId($booksellerid);
100 my $count = scalar @contractloop;
101 if ( $count > 0) {
102 $template->param(contractloop => \@contractloop,
103 basketcontractnumber => $basket->{'contractnumber'});
105 my @booksellers = C4::Bookseller::GetBookSeller();
106 $template->param( add_form => 1,
107 basketname => $basket->{'basketname'},
108 basketnote => $basket->{'note'},
109 basketbooksellernote => $basket->{'booksellernote'},
110 booksellername => $bookseller->{'name'},
111 booksellerid => $booksellerid,
112 basketno => $basketno,
113 booksellers => \@booksellers,
114 deliveryplace => $basket->{deliveryplace},
115 billingplace => $basket->{billingplace},
118 my $billingplace = $basket->{'billingplace'} || C4::Context->userenv->{"branch"};
119 my $deliveryplace = $basket->{'deliveryplace'} || C4::Context->userenv->{"branch"};
121 # Build the combobox to select the billing place
122 my @billingplaceloop;
124 my $branches = C4::Branch::GetBranchesLoop( $billingplace );
125 $template->param( billingplaceloop => $branches );
126 $branches = C4::Branch::GetBranchesLoop( $deliveryplace );
127 $template->param( deliveryplaceloop => $branches );
129 #End Edit
130 } elsif ( $op eq 'add_validate' ) {
131 #we are confirming the changes, save the basket
132 if ( $is_an_edit ) {
133 ModBasketHeader(
134 $basketno,
135 $input->param('basketname'),
136 $input->param('basketnote'),
137 $input->param('basketbooksellernote'),
138 $input->param('basketcontractnumber') || undef,
139 $input->param('basketbooksellerid'),
140 $input->param('deliveryplace'),
141 $input->param('billingplace'),
143 } else { #New basket
144 $basketno = NewBasket(
145 $booksellerid,
146 $loggedinuser,
147 $input->param('basketname'),
148 $input->param('basketnote'),
149 $input->param('basketbooksellernote'),
150 $input->param('basketcontractnumber') || undef,
151 $input->param('deliveryplace'),
152 $input->param('billingplace'),
155 print $input->redirect('basket.pl?basketno='.$basketno);
156 exit 0;
158 output_html_with_http_headers $input, $cookie, $template->output;