New styles for bulk hold and bulk tag inputs on search results page.
[koha.git] / acqui / parcel.pl
1 #!/usr/bin/perl
2
3
4 #script to recieve orders
5 #written by chris@katipo.co.nz 24/2/2000
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25
26 =head1 NAME
27
28 parcel.pl
29
30 =head1 DESCRIPTION
31 This script shows all orders receipt or pending for a given supplier.
32 It allows to write an order as 'received' when he arrives.
33
34 =head1 CGI PARAMETERS
35
36 =over 4
37
38 =item supplierid
39 To know the supplier this script has to show orders.
40
41 =item code
42 is the bookseller invoice number.
43
44 =item freight
45
46
47 =item gst
48
49
50 =item datereceived
51 To filter the results list on this given date.
52
53 =back
54
55 =cut
56
57 use C4::Auth;
58 use C4::Acquisition;
59 use C4::Bookseller;
60 use C4::Biblio;
61 use CGI;
62 use C4::Output;
63 use C4::Dates qw/format_date format_date_in_iso/;
64
65 use strict;
66
67 my $input=new CGI;
68 my $supplierid=$input->param('supplierid');
69 my $bookseller=GetBookSellerFromId($supplierid);
70
71 my $invoice=$input->param('invoice') || '';
72 my $freight=$input->param('freight');
73 my $gst=$input->param('gst');
74 my $datereceived =  ($input->param('op') eq 'new') ? C4::Dates->new($input->param('datereceived')) 
75                                         :  C4::Dates->new($input->param('datereceived'), 'iso')   ;
76 $datereceived = C4::Dates->new() unless $datereceived;
77 my $code=$input->param('code');
78 my @rcv_err = $input->param('error');
79 my @rcv_err_barcode = $input->param('error_bc');
80
81 my ($template, $loggedinuser, $cookie)
82     = get_template_and_user({template_name => "acqui/parcel.tmpl",
83                  query => $input,
84                                  type => "intranet",
85                  authnotrequired => 0,
86                  flagsrequired => {acquisition => 1},
87                  debug => 1,
88 });
89
90 # If receiving error, report the error (coming from finishrecieve.pl(sic)).
91 if( scalar(@rcv_err) ) {
92         my $cnt=0;
93         my $error_loop;
94         for my $err (@rcv_err) {
95                 push @$error_loop, { "error_$err" => 1 , barcode => $rcv_err_barcode[$cnt] };
96                 $cnt++;
97         }
98         $template->param( receive_error => 1 ,
99                                                 error_loop => $error_loop,
100                                         );
101 }
102
103 my $cfstr = "%.2f";  # currency format string -- could get this from currency table.
104 my @parcelitems=GetParcel($supplierid,$invoice,$datereceived->output('iso'));
105 my $countlines = scalar @parcelitems;
106 my $totalprice=0;
107 my $totalfreight=0;
108 my $totalquantity=0;
109 my $total;
110 my $tototal;
111 my $toggle;
112 my @loop_received = ();
113 for (my $i=0;$i<$countlines;$i++){
114     #$total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
115     $total=($parcelitems[$i]->{'unitprice'}  ) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
116         $parcelitems[$i]->{'unitprice'}+=0;
117     my %line;
118     if ($toggle==0){
119         $line{color}='#EEEEEE';
120         $toggle=1;
121     } else {
122             $line{color}='white';
123             $toggle=0;
124     }
125     %line = %{$parcelitems[$i]};
126     $line{invoice} = $invoice;
127     $line{gst} = $gst;
128     $line{total} = sprintf($cfstr,$total);
129     $line{supplierid} = $supplierid;
130     push @loop_received, \%line;
131     $totalprice+=$parcelitems[$i]->{'unitprice'};
132         $line{unitprice} = sprintf($cfstr,$parcelitems[$i]->{'unitprice'});
133 #double FIXME - totalfreight is redefined later.
134
135  # FIXME - each order in a  parcel holds the freight for the whole parcel. This means if you receive a parcel with items from multiple budgets, you'll see the freight charge in each budget..
136      if ( $i > 0 && $totalfreight != $parcelitems[$i]->{'freight'}) {
137                warn "FREIGHT CHARGE MISMATCH!!";
138        }
139     $totalfreight=$parcelitems[$i]->{'freight'};
140     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
141     $tototal+=$total;
142 }
143
144 my $pendingorders = GetPendingOrders($supplierid);
145 my $countpendings = scalar @$pendingorders;
146
147 # pending orders totals
148 my ($totalPunitprice,$totalPquantity,$totalPecost, $totalPqtyrcvd);
149 my $ordergrandtotal;
150 my @loop_orders = ();
151 for (my $i=0;$i<$countpendings;$i++){
152     my %line;
153     if ($toggle==0){
154         $line{color}='#EEEEEE';
155         $toggle=1;
156     } else {
157             $line{color}='white';
158             $toggle=0;
159     }
160     %line = %{$pendingorders->[$i]};
161         $line{quantity}+=0;
162         $line{quantityreceived}+=0;
163         $line{unitprice}+=0;
164     $totalPunitprice += $line{unitprice};
165     $totalPquantity +=$line{quantity};
166     $totalPqtyrcvd +=$line{quantityreceived};
167     $totalPecost += $line{ecost};
168     $line{ecost} = sprintf("%.2f",$line{ecost});
169     $line{ordertotal} = sprintf("%.2f",$line{ecost}*$line{quantity});
170     $line{unitprice} = sprintf("%.2f",$line{unitprice});
171     $line{invoice} = $invoice;
172     $line{gst} = $gst;
173     $line{total} = $total;
174     $line{supplierid} = $supplierid;
175         $ordergrandtotal += $line{ecost}*$line{quantity};
176     push @loop_orders, \%line;
177 }
178 $freight = $totalfreight unless $freight;
179 #$totalfreight=$freight;
180 $tototal=$tototal+$freight;
181
182 $template->param(invoice => $invoice,
183                 datereceived => $datereceived->output('iso'),
184                 invoicedatereceived => $datereceived->output('iso'), 
185                 formatteddatereceived => $datereceived->output(),
186                 name => $bookseller->{'name'},
187                 supplierid => $supplierid,
188                 gst => $gst,
189                 freight => $freight,
190                 invoice => $invoice,
191                 countreceived => $countlines,
192                 loop_received => \@loop_received,
193                 countpending => $countpendings,
194                 loop_orders => \@loop_orders,
195                 totalprice => sprintf($cfstr,$totalprice),
196                 totalfreight => $totalfreight,
197                 totalquantity => $totalquantity,
198                 tototal => sprintf($cfstr,$tototal),
199                 ordergrandtotal => sprintf($cfstr,$ordergrandtotal),
200                 gst => $gst,
201                 grandtot => sprintf($cfstr,$tototal+$gst),
202                 totalPunitprice => sprintf("%.2f",$totalPunitprice),
203                 totalPquantity => $totalPquantity,
204                 totalPqtyrcvd => $totalPqtyrcvd,
205                 totalPecost => sprintf("%.2f",$totalPecost),
206                 );
207 output_html_with_http_headers $input, $cookie, $template->output;