Bug 7175: orderreceive.pl cosmetic changes
[koha.git] / acqui / orderreceive.pl
1 #!/usr/bin/perl
2
3
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 =head1 NAME
25
26 orderreceive.pl
27
28 =head1 DESCRIPTION
29
30 This script shows all order already receive and all pendings orders.
31 It permit to write a new order as 'received'.
32
33 =head1 CGI PARAMETERS
34
35 =over 4
36
37 =item booksellerid
38
39 to know on what supplier this script has to display receive order.
40
41 =item receive
42
43 =item invoice
44
45 the number of this invoice.
46
47 =item freight
48
49 =item biblio
50
51 The biblionumber of this order.
52
53 =item datereceived
54
55 =item catview
56
57 =item gst
58
59 =back
60
61 =cut
62
63 use strict;
64 use warnings;
65
66 use CGI;
67 use C4::Context;
68 use C4::Koha;   # GetKohaAuthorisedValues GetItemTypes
69 use C4::Acquisition;
70 use C4::Auth;
71 use C4::Output;
72 use C4::Dates qw/format_date/;
73 use C4::Bookseller qw/ GetBookSellerFromId /;
74 use C4::Budgets qw/ GetBudget /;
75 use C4::Members;
76 use C4::Branch;    # GetBranches
77 use C4::Items;
78 use C4::Biblio;
79 use C4::Suggestions;
80
81
82 my $input      = new CGI;
83
84 my $dbh          = C4::Context->dbh;
85 my $booksellerid = $input->param('booksellerid');
86 my $ordernumber  = $input->param('ordernumber');
87 my $search       = $input->param('receive');
88 my $invoice      = $input->param('invoice');
89 my $freight      = $input->param('freight');
90 my $datereceived = $input->param('datereceived');
91
92
93 $datereceived = $datereceived ? C4::Dates->new($datereceived, 'iso') : C4::Dates->new();
94
95 my $bookseller = GetBookSellerFromId($booksellerid);
96 my $input_gst = ($input->param('gst') eq '' ? undef : $input->param('gst'));
97 my $gst= $input_gst // $bookseller->{gstrate} // C4::Context->preference("gist") // 0;
98 my $results = SearchOrder($ordernumber,$search);
99
100 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
101     {
102         template_name   => "acqui/orderreceive.tmpl",
103         query           => $input,
104         type            => "intranet",
105         authnotrequired => 0,
106         flagsrequired   => {acquisition => 'order_receive'},
107         debug           => 1,
108     }
109 );
110
111 my $count = scalar @$results;
112 # prepare the form for receiving
113 if ( $count == 1 ) {
114     my $order = $results->[0];
115     if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
116         # Check if ACQ framework exists
117         my $marc = GetMarcStructure(1, 'ACQ');
118         unless($marc) {
119             $template->param('NoACQframework' => 1);
120         }
121         $template->param(
122             AcqCreateItemReceiving => 1,
123             UniqueItemFields => C4::Context->preference('UniqueItemFields'),
124         );
125     }
126
127     if ( $order->{'unitprice'} == 0 ) {
128         $order->{'unitprice'} = '';
129     }
130
131     my $suggestion   = GetSuggestionInfoFromBiblionumber($order->{'biblionumber'});
132
133     my $authorisedby = $order->{'authorisedby'};
134     my $member = GetMember( borrowernumber => $authorisedby );
135
136     my $budget = GetBudget( $order->{'budget_id'} );
137
138     $template->param(
139         count                 => 1,
140         biblionumber          => $order->{'biblionumber'},
141         ordernumber           => $order->{'ordernumber'},
142         biblioitemnumber      => $order->{'biblioitemnumber'},
143         booksellerid          => $order->{'booksellerid'},
144         freight               => $freight,
145         gst                   => $gst,
146         name                  => $bookseller->{'name'},
147         date                  => format_date($order->{entrydate}),
148         title                 => $order->{'title'},
149         author                => $order->{'author'},
150         copyrightdate         => $order->{'copyrightdate'},
151         isbn                  => $order->{'isbn'},
152         seriestitle           => $order->{'seriestitle'},
153         bookfund              => $budget->{budget_name},
154         quantity              => $order->{'quantity'},
155         quantityreceivedplus1 => $order->{'quantityreceived'} + 1,
156         quantityreceived      => $order->{'quantityreceived'},
157         rrp                   => $order->{'rrp'},
158         ecost                 => $order->{'ecost'},
159         unitprice             => $order->{'unitprice'},
160         memberfirstname       => $member->{firstname} || "",
161         membersurname         => $member->{surname} || "",
162         invoice               => $invoice,
163         datereceived          => $datereceived->output(),
164         datereceived_iso      => $datereceived->output('iso'),
165         notes                 => $order->{notes},
166         suggestionid          => $suggestion->{suggestionid},
167         surnamesuggestedby    => $suggestion->{surnamesuggestedby},
168         firstnamesuggestedby  => $suggestion->{firstnamesuggestedby},
169     );
170 }
171 else {
172     my @loop;
173     for ( my $i = 0 ; $i < $count ; $i++ ) {
174         my %line = %{ @$results[$i] };
175
176         $line{invoice}      = $invoice;
177         $line{datereceived} = $datereceived->output();
178         $line{freight}      = $freight;
179         $line{gst}          = $gst;
180         $line{title}        = @$results[$i]->{'title'};
181         $line{author}       = @$results[$i]->{'author'};
182         $line{booksellerid}   = $booksellerid;
183         push @loop, \%line;
184     }
185
186     $template->param(
187         loop         => \@loop,
188         booksellerid   => $booksellerid,
189     );
190 }
191 my $op = $input->param('op');
192 if ($op and $op eq 'edit'){
193     $template->param(edit   =>   1);
194 }
195 output_html_with_http_headers $input, $cookie, $template->output;