Merge branch 'master' of /home/jmf/repos/koha-rm-root.git/
[koha.git] / acqui / parcel.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to recieve orders
6 #written by chris@katipo.co.nz 24/2/2000
7
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26
27 =head1 NAME
28
29 parcel.pl
30
31 =head1 DESCRIPTION
32 This script shows all orders receipt or pending for a given supplier.
33 It allows to write an order as 'received' when he arrives.
34
35 =head1 CGI PARAMETERS
36
37 =over 4
38
39 =item supplierid
40 To know the supplier this script has to show orders.
41
42 =item code
43 is the bookseller invoice number.
44
45 =item freight
46
47
48 =item gst
49
50
51 =item datereceived
52 To filter the results list on this given date.
53
54 =back
55
56 =cut
57
58 use C4::Auth;
59 use C4::Acquisition;
60 use C4::Bookseller;
61 use C4::Biblio;
62 use CGI;
63 use C4::Output;
64 use C4::Date;
65
66 use strict;
67
68 my $input=new CGI;
69 my $supplierid=$input->param('supplierid');
70 my @booksellers=GetBookSeller($supplierid);
71 my $count = scalar @booksellers;
72
73 my $invoice=$input->param('invoice') || '';
74 my $freight=$input->param('freight');
75 my $gst=$input->param('gst');
76 my $datereceived=format_date_in_iso($input->param('datereceived')) || format_date(join "-",Date::Calc::Today());
77 my $code=$input->param('code');
78
79 my ($template, $loggedinuser, $cookie)
80     = get_template_and_user({template_name => "acqui/parcel.tmpl",
81                  query => $input,
82                  type => "intranet",
83                  authnotrequired => 0,
84                  flagsrequired => {acquisition => 1},
85                  debug => 1,
86 });
87 my @parcelitems=GetParcel($supplierid,$invoice,$datereceived);
88 my $countlines = scalar @parcelitems;
89
90 my $totalprice=0;
91 my $totalfreight=0;
92 my $totalquantity=0;
93 my $total;
94 my $tototal;
95 my $toggle;
96 my @loop_received = ();
97 for (my $i=0;$i<$countlines;$i++){
98     $total=($parcelitems[$i]->{'unitprice'} + $parcelitems[$i]->{'freight'}) * $parcelitems[$i]->{'quantityreceived'};   #weird, are the freight fees counted by book? (pierre)
99     $parcelitems[$i]->{'unitprice'}+=0;
100     my %line;
101     if ($toggle==0){
102         $line{color}='#EEEEEE';
103         $toggle=1;
104     } else {
105             $line{color}='white';
106             $toggle=0;
107     }
108     %line = %{$parcelitems[$i]};
109     $line{invoice} = $invoice;
110     $line{gst} = $gst;
111     $line{total} = $total;
112     $line{supplierid} = $supplierid;
113     push @loop_received, \%line;
114     $totalprice+=$parcelitems[$i]->{'unitprice'};
115     $totalfreight+=$parcelitems[$i]->{'freight'};
116     $totalquantity+=$parcelitems[$i]->{'quantityreceived'};
117     $tototal+=$total;
118 }
119 my $pendingorders = GetPendingOrders($supplierid);
120 my $countpendings = scalar @$pendingorders;
121
122 my @loop_orders = ();
123 for (my $i=0;$i<$countpendings;$i++){
124     my %line;
125     if ($toggle==0){
126         $line{color}='#EEEEEE';
127         $toggle=1;
128     } else {
129             $line{color}='white';
130             $toggle=0;
131     }
132     %line = %{$pendingorders->[$i]};
133     $line{ecost} = sprintf("%.2f",$line{ecost});
134     $line{unitprice} = sprintf("%.2f",$line{unitprice});
135     $line{invoice} = $invoice;
136     $line{gst} = $gst;
137     $line{total} = $total;
138     $line{supplierid} = $supplierid;
139     push @loop_orders, \%line;
140 }
141
142 $totalfreight=$freight;
143 $tototal=$tototal+$freight;
144
145 $template->param(invoice => $invoice,
146                                                 datereceived => $datereceived,
147                                                 formatteddatereceived => format_date($datereceived),
148                         name => $booksellers[0]->{'name'},
149                         supplierid => $supplierid,
150                         gst => $gst,
151                         freight => $freight,
152                         invoice => $invoice,
153                         countreceived => $countlines,
154                         loop_received => \@loop_received,
155                         countpending => $countpendings,
156                         loop_orders => \@loop_orders,
157                         totalprice => $totalprice,
158                         totalfreight => $totalfreight,
159                         totalquantity => $totalquantity,
160                         tototal => $tototal,
161                         gst => $gst,
162                         grandtot => $tototal+$gst,
163                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
164         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
165         IntranetNav => C4::Context->preference("IntranetNav"),
166                         );
167 output_html_with_http_headers $input, $cookie, $template->output;