perltidy before next commit.
[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 use strict;
24 use CGI;
25 use C4::Auth;
26 use C4::Output;
27 use C4::Acquisition;
28 use C4::Suggestions;
29 use C4::Biblio;
30 use C4::Output;
31 use C4::Interface::CGI::Output;
32 use C4::Database;
33 use HTML::Template;
34
35 #use Date::Manip;
36
37 my $input = new CGI;
38
39 # get_template_and_user used only to check auth & get user id
40 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
41     {
42         template_name   => "acqui/order.tmpl",
43         query           => $input,
44         type            => "intranet",
45         authnotrequired => 0,
46         flagsrequired   => { acquisition => 1 },
47         debug           => 1,
48     }
49 );
50
51 # get CGI parameters
52 my $ordnum       = $input->param('ordnum');
53 my $basketno     = $input->param('basketno');
54 my $booksellerid = $input->param('booksellerid');
55 my $existing     =
56   $input->param('existing');    # existing biblio, (not basket or order)
57 my $title         = $input->param('title');
58 my $author        = $input->param('author');
59 my $copyrightdate = $input->param('copyrightdate');
60 my $isbn          = $input->param('ISBN');
61 my $itemtype      = $input->param('format');
62 my $quantity      = $input->param('quantity');
63 my $listprice     = $input->param('list_price');
64 if ( $listprice eq '' ) {
65     $listprice = 0;
66 }
67 my $series = $input->param('Series');
68
69 # my $supplier=$input->param('supplier');
70 my $notes         = $input->param('notes');
71 my $bookfund      = $input->param('bookfund');
72 my $sort1         = $input->param('sort1');
73 my $sort2         = $input->param('sort2');
74 my $rrp           = $input->param('rrp');
75 my $ecost         = $input->param('ecost');
76 my $gst           = $input->param('GST');
77 my $budget        = $input->param('budget');
78 my $cost          = $input->param('cost');
79 my $sub           = $input->param('sub');
80 my $invoice       = $input->param('invoice');
81 my $publishercode = $input->param('publishercode');
82 my $suggestionid  = $input->param('suggestionid');
83
84 # create, modify or delete biblio
85 # create if $quantity>=0 and $existing='no'
86 # modify if $quantity>=0 and $existing='yes'
87 # delete if $quantity has been se to 0 by the librarian
88 my $bibnum;
89 my $bibitemnum;
90 if ( $quantity ne '0' ) {
91
92     #check to see if biblio exists
93     if ( $existing eq 'no' ) {
94
95         #if it doesnt create it
96         $bibnum = &newbiblio(
97             {
98                 title         => $title         ? $title         : "",
99                 author        => $author        ? $author        : "",
100                 copyrightdate => $copyrightdate ? $copyrightdate : "",
101                 series        => $series        ? $series        : "",
102             }
103         );
104         $bibitemnum = &newbiblioitem(
105             {
106                 biblionumber  => $bibnum,
107                 itemtype      => $itemtype ? $itemtype : "",
108                 isbn          => $isbn ? $isbn : "",
109                 publishercode => $publishercode ? $publishercode : "",
110             }
111         );
112
113         # change suggestion status if applicable
114         if ($suggestionid) {
115             changestatus( $suggestionid, 'ORDERED', '', $bibnum );
116         }
117     }
118     else {
119         $bibnum     = $input->param('biblio');
120         $bibitemnum = $input->param('bibitemnum');
121         my $oldtype = $input->param('oldtype');
122     }
123     if ($ordnum) {
124
125         #               warn "MODORDER $title / $ordnum / $quantity / $bookfund";
126         modorder(
127             $title,   $ordnum,   $quantity,     $listprice,
128             $bibnum,  $basketno, $booksellerid, $loggedinuser,
129             $notes,   $bookfund, $bibitemnum,   $rrp,
130             $ecost,   $gst,      $budget,       $cost,
131             $invoice, $sort1,    $sort2
132         );
133     }
134     else {
135
136         #       warn "new order : ";
137         $basketno = neworder(
138             $basketno,  $bibnum,       $title,        $quantity,
139             $listprice, $booksellerid, $loggedinuser, $notes,
140             $bookfund,  $bibitemnum,   $rrp,          $ecost,
141             $gst,       $budget,       $cost,         $sub,
142             $invoice,   $sort1,        $sort2
143         );
144     }
145 }
146 else {
147     $bibnum = $input->param('biblio');
148     delorder( $bibnum, $ordnum );
149 }
150 print $input->redirect("basket.pl?basket=$basketno");