help.pl - bugfix module usage (HTML::Template::Pro)
[koha.git] / acqui / addorder.pl
1 #!/usr/bin/perl
2
3 #script to add an order into the system
4 #written 29/2/00 by chris@katipo.co.nz
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
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.
14 #
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.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23
24 =head1 NAME
25
26 addorder.pl
27
28 =head1 DESCRIPTION
29
30 this script allows to add an order.
31 It is called by :
32
33 =item neworderbiblio.pl to add an order from nothing.
34
35 =item neworderempty.pl to add an order from an existing biblio.
36
37 =item newordersuggestion.pl to add an order from an existing suggestion.
38
39 =head1 CGI PARAMETERS
40
41 All of the cgi parameters below are related to the new order.
42
43 =over 4
44
45 =item C<ordnum>
46 the number of this new order.
47
48 =item C<basketno>
49 the number of this new basket
50
51 =item C<booksellerid>
52 the bookseller the librarian has to pay.
53
54 =item C<existing>
55
56 =item C<title>
57 the title of the record ordered.
58
59 =item C<author>
60 the author of the record ordered.
61
62 =item C<copyrightdate>
63 the copyrightdate of the record ordered.
64
65 =item C<ISBN>
66 the ISBN of the record ordered.
67
68 =item C<format>
69
70 =item C<quantity>
71 the quantity to order.
72
73 =item C<list_price>
74 the price of this order.
75
76 =item C<branch>
77 the branch where this order will be received.
78
79 =item C<series>
80
81 =item C<notes>
82 Notes on this basket.
83
84 =item C<bookfund>
85 bookfund use to pay this order.
86
87 =item C<sort1> & C<sort2>
88
89 =item C<rrp>
90
91 =item C<ecost>
92
93 =item C<GST>
94
95 =item C<budget>
96
97 =item C<cost>
98
99 =item C<sub>
100
101 =item C<invoice>
102 the number of the invoice for this order.
103
104 =item C<publishercode>
105
106 =item C<suggestionid>
107 if it is an order from an existing suggestion : the id of this suggestion.
108
109 =item C<donation>
110
111 =back
112
113 =cut
114
115 use strict;
116 use CGI;
117 use C4::Auth;
118 use C4::Acquisition;
119 use C4::Suggestions;
120 use C4::Biblio;
121 use C4::Output;
122
123
124
125 #use Date::Manip;
126
127 my $input = new CGI;
128
129 # get_template_and_user used only to check auth & get user id
130 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
131     {
132         template_name   => "acqui/booksellers.tmpl",
133         query           => $input,
134         type            => "intranet",
135         authnotrequired => 0,
136         flagsrequired   => { acquisition => 1 },
137         debug           => 1,
138     }
139 );
140
141 # get CGI parameters
142 my $ordnum       = $input->param('ordnum');
143 my $basketno     = $input->param('basketno');
144 my $booksellerid = $input->param('booksellerid');
145 my $existing     = $input->param('existing');    # existing biblio, (not basket or order)
146 my $title         = $input->param('title');
147 my $author        = $input->param('author');
148 my $copyrightdate = $input->param('copyrightdate');
149 my $isbn          = $input->param('ISBN');
150 my $itemtype      = $input->param('format');
151 my $quantity      = $input->param('quantity');
152 my $listprice     = $input->param('list_price');
153 my $branch        = $input->param('branch');
154 if ( $listprice eq '' ) {
155     $listprice = 0;
156 }
157 my $series = $input->param('series');
158 my $notes         = $input->param('notes');
159 my $bookfund      = $input->param('bookfund');
160 my $sort1         = $input->param('sort1');
161 my $sort2         = $input->param('sort2');
162 my $rrp           = $input->param('rrp');
163 my $ecost         = $input->param('ecost');
164 my $gst           = $input->param('GST');
165 my $budget        = $input->param('budget');
166 my $cost          = $input->param('cost');
167 my $sub           = $input->param('sub');
168 my $purchaseorder = $input->param('purchaseordernumber');
169 my $invoice       = $input->param('invoice');
170 my $publishercode = $input->param('publishercode');
171 my $suggestionid  = $input->param('suggestionid');
172 my $user          = $input->remote_user;
173
174 #warn "CREATEBIBITEM =  $input->param('createbibitem')";
175 #warn Dumper $input->param('createbibitem');
176 my $createbibitem = $input->param('createbibitem');
177
178 # create, modify or delete biblio
179 # create if $quantity>=0 and $existing='no'
180 # modify if $quantity>=0 and $existing='yes'
181 # delete if $quantity has been se to 0 by the librarian
182 my $biblionumber=$input->param('biblionumber');
183 my $bibitemnum;
184 if ( $quantity ne '0' ) {
185     #check to see if biblio exists
186     if ( $existing eq 'no' ) {
187
188         #if it doesnt create it
189         my $record = TransformKohaToMarc(
190             {
191                 "biblio.title"              => "$title",
192                 "biblio.author"             => "$author",
193                 "biblio.copyrightdate"      => $copyrightdate ? $copyrightdate : "",
194                 "biblio.series"             => $series        ? $series        : "",
195                 "biblioitems.itemtype"      => $itemtype ? $itemtype : "",
196                 "biblioitems.isbn"          => $isbn ? $isbn : "",
197                 "biblioitems.publishercode" => $publishercode ? $publishercode : "",
198             });
199         # create the record in catalogue, with framework ''
200         ($biblionumber,$bibitemnum) = AddBiblio($record,'');
201
202         # change suggestion status if applicable
203         if ($suggestionid) {
204             ModStatus( $suggestionid, 'ORDERED', '', $biblionumber );
205         }
206     }
207     # if we already have $ordnum, then it's an ordermodif
208     if ($ordnum) {
209         ModOrder(
210             $title,   $ordnum,   $quantity,     $listprice,
211             $biblionumber,  $basketno, $booksellerid, $loggedinuser,
212             $notes,   $bookfund, $bibitemnum,   $rrp,
213             $ecost,   $gst,      $budget,       $cost,
214             $invoice, $sort1,    $sort2,                $purchaseorder
215         );
216     }
217     else { # else, it's a new line
218         ( $basketno, $ordnum ) = NewOrder(
219             $basketno,  $biblionumber,       $title,        $quantity,
220             $listprice, $booksellerid, $loggedinuser, $notes,
221             $bookfund,  $bibitemnum,   $rrp,          $ecost,
222             $gst,       $budget,       $cost,         $sub,
223             $invoice,   $sort1,        $sort2,          $purchaseorder
224         );
225     }
226 }
227 else { # qty=0, delete the line
228     $biblionumber = $input->param('biblionumber');
229     DelOrder( $biblionumber, $ordnum );
230 }
231 print $input->redirect("basket.pl?basketno=$basketno");