fix date formatting in overdue_notices.pl
[koha.git] / acqui / orderreceive.pl
blob313a3847e0bf95aeab67651bc6967476a96349d0
1 #!/usr/bin/perl
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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.
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.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 NAME
26 orderreceive.pl
28 =head1 DESCRIPTION
29 This script shows all order already receive and all pendings orders.
30 It permit to write a new order as 'received'.
32 =head1 CGI PARAMETERS
34 =over 4
36 =item supplierid
37 to know on what supplier this script has to display receive order.
39 =item receive
41 =item invoice
42 the number of this invoice.
44 =item freight
46 =item biblio
47 The biblionumber of this order.
49 =item datereceived
51 =item catview
53 =item gst
55 =back
57 =cut
59 use strict;
60 use CGI;
61 use C4::Context;
62 use C4::Koha; # GetKohaAuthorisedValues GetItemTypes
63 use C4::Acquisition;
64 use C4::Auth;
65 use C4::Output;
66 use C4::Dates qw/format_date/;
67 use C4::Bookseller;
68 use C4::Members;
69 use C4::Branch; # GetBranches
71 my $input = new CGI;
72 my $supplierid = $input->param('supplierid');
73 my $dbh = C4::Context->dbh;
75 my $search = $input->param('receive');
76 my $invoice = $input->param('invoice');
77 my $freight = $input->param('freight');
78 my $biblionumber = $input->param('biblionumber');
79 my $datereceived = C4::Dates->new($input->param('datereceived'),'iso') || C4::Dates->new();
80 my $catview = $input->param('catview');
81 my $gst = $input->param('gst');
83 my @results = SearchOrder( $search, $supplierid, $biblionumber, $catview );
84 my $count = scalar @results;
85 my $order = GetOrder($search);
87 my $bookseller = GetBookSellerFromId( $results[0]->{'booksellerid'} );
89 my $date = $results[0]->{'entrydate'};
91 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
93 template_name => "acqui/orderreceive.tmpl",
94 query => $input,
95 type => "intranet",
96 authnotrequired => 0,
97 flagsrequired => { acquisition => 1 },
98 debug => 1,
101 $template->param($count);
103 if ( $count == 1 ) {
105 my (@itemtypesloop,@locationloop,@ccodeloop);
106 my $itemtypes = GetItemTypes;
107 foreach my $thisitemtype (sort keys %$itemtypes) {
108 my %row = (
109 value => $thisitemtype,
110 description => $itemtypes->{$thisitemtype}->{'description'},
111 selected => ($thisitemtype eq $results[0]->{itemtype}), # ifdef itemtype @ bibliolevel, use it as default for item level.
113 push @itemtypesloop, \%row;
116 my $locs = GetKohaAuthorisedValues( 'items.location' );
117 foreach my $thisloc (sort keys %$locs) {
118 my $row = {
119 value => $thisloc,
120 description => $locs->{$thisloc},
122 push @locationloop, $row;
124 my $ccodes= GetKohaAuthorisedValues( 'items.ccode' );
125 foreach my $thisccode (sort keys %$ccodes) {
126 push @ccodeloop, {
127 value => $thisccode,
128 description => $ccodes->{$thisccode},
131 $template->param(itemtypeloop => \@itemtypesloop ,
132 locationloop => \@locationloop,
133 ccodeloop => \@ccodeloop,
134 itype => C4::Context->preference('item-level_itypes'),
137 my $onlymine=C4::Context->preference('IndependantBranches') &&
138 C4::Context->userenv &&
139 C4::Context->userenv->{flags} !=1 &&
140 C4::Context->userenv->{branch};
141 my $branches = GetBranches($onlymine);
142 my @branchloop;
143 foreach my $thisbranch ( sort keys %$branches ) {
144 my %row = (
145 value => $thisbranch,
146 description => $branches->{$thisbranch}->{'branchname'},
148 $row{'selected'} = 1 if( $thisbranch eq $order->{branchcode}) ;
149 push @branchloop, \%row;
152 my $barcode;
153 # See whether barcodes should be automatically allocated.
154 # FIXME : only incremental is implemented here, and it creates a race condition.
156 if ( C4::Context->preference('autoBarcode') eq 'incremental' ) {
157 my $sth = $dbh->prepare("Select max(barcode) from items");
158 $sth->execute;
159 my $data = $sth->fetchrow_hashref;
160 $barcode = $results[0]->{'barcode'} + 1;
161 $sth->finish;
164 if ( $results[0]->{'quantityreceived'} == 0 ) {
165 $results[0]->{'quantityreceived'} = '';
167 if ( $results[0]->{'unitprice'} == 0 ) {
168 $results[0]->{'unitprice'} = '';
170 # $results[0]->{'copyrightdate'} = format_date( $results[0]->{'copyrightdate'} ); # this usu fails.
171 $template->param(
172 branchloop => \@branchloop,
173 count => 1,
174 biblionumber => $results[0]->{'biblionumber'},
175 ordernumber => $results[0]->{'ordernumber'},
176 biblioitemnumber => $results[0]->{'biblioitemnumber'},
177 supplierid => $results[0]->{'booksellerid'},
178 freight => $freight,
179 gst => $gst,
180 catview => ( $catview ne 'yes' ? 1 : 0 ),
181 name => $bookseller->{'name'},
182 date => format_date($date),
183 title => $results[0]->{'title'},
184 author => $results[0]->{'author'},
185 copyrightdate => $results[0]->{'copyrightdate'},
186 itemtype => $results[0]->{'itemtype'},
187 isbn => $results[0]->{'isbn'},
188 seriestitle => $results[0]->{'seriestitle'},
189 barcode => $barcode,
190 bookfund => $results[0]->{'bookfundid'},
191 quantity => $results[0]->{'quantity'},
192 quantityreceivedplus1 => $results[0]->{'quantityreceived'} + 1,
193 quantityreceived => $results[0]->{'quantityreceived'},
194 rrp => $results[0]->{'rrp'},
195 ecost => $results[0]->{'ecost'},
196 unitprice => $results[0]->{'unitprice'},
197 invoice => $invoice,
198 datereceived => $datereceived->output(),
199 datereceived_iso => $datereceived->output('iso'),
202 else {
203 my @loop;
204 for ( my $i = 0 ; $i < $count ; $i++ ) {
205 my %line = %{ $results[$i] };
207 $line{invoice} = $invoice;
208 $line{datereceived} = $datereceived->output();
209 $line{freight} = $freight;
210 $line{gst} = $gst;
211 $line{title} = $results[$i]->{'title'};
212 $line{author} = $results[$i]->{'author'};
213 $line{supplierid} = $supplierid;
214 push @loop, \%line;
216 $template->param(
217 loop => \@loop,
218 date => format_date($date),
219 datereceived => $datereceived->output(),
220 name => $bookseller->{'name'},
221 supplierid => $supplierid,
222 invoice => $invoice,
226 output_html_with_http_headers $input, $cookie, $template->output;