Finalized XML version for intranet
[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 use strict;
58 use C4::Auth;
59 use C4::Acquisition;
60 use C4::Bookseller;
61 use C4::Bookfund;
62 use C4::Biblio;
63 use CGI;
64 use C4::Interface::CGI::Output;
65 use C4::Date;
66 use Time::localtime;
67
68
69 my $input=new CGI;
70 my $supplierid=$input->param('supplierid');
71 my $basketno=$input->param('basketno');
72 my @booksellers=GetBookSeller($supplierid);
73 my $count = scalar @booksellers;
74
75 my @datetoday = localtime();
76 my $date = (1900+$datetoday[5])."-".($datetoday[4]+1)."-". $datetoday[3];
77 my ($template, $loggedinuser, $cookie)
78     = get_template_and_user({template_name => "acqui/parcel.tmpl",
79                  query => $input,
80                  type => "intranet",
81                  authnotrequired => 0,
82                  flagsrequired => {acquisition => 1},
83                  debug => 1,
84 });
85
86 my @booksellers=GetBookSeller($supplierid);
87
88 my $gstreg=$booksellers[0]->{gstreg};
89 my $incgst=$booksellers[0]->{'invoiceincgst'};
90 my $invcurrency=$booksellers[0]->{'invoiceprice'};
91 my $discount=$booksellers[0]->{'discount'};
92 my $currencyrate;
93 # get currencies (for exchange rates calcs if needed)
94 my @rates = GetCurrencies();
95 my $count = scalar @rates;
96
97 for ( my $i = 0 ; $i < $count ; $i++ ) {
98  if ($rates[$i]->{'currency'} eq $invcurrency){
99     $currencyrate     = $rates[$i]->{'rate'};
100    }
101 }
102 my $me=C4::Context->userenv;
103 my $user=$me->{'cardnumber'};
104 my $totalprice=0;
105 my $totalfreight=0;
106 my $totalquantity=0;
107 my $totaldiscount=0;
108 my $total;
109 my $tototal;
110 my $toggle;
111 my $totalgst;
112 my $totaltoreceive;
113 my $totaltoprice;
114 my $totaltogst;
115 my $totaltodiscount;
116 my @loop_orders;
117 my $countpendings;
118 my $invoice;
119 ##Receiving a single basket or all baskets of a supplier
120 unless($basketno){
121 my $pendingorders = GetPendingOrders($supplierid);
122 $countpendings = scalar @$pendingorders;
123 foreach my $pendingorder (@$pendingorders){
124  my @orders=GetOrders($pendingorder->{basketno});
125   foreach my $order(@orders){
126   $order->{toreceive}=$order->{quantity} - $order->{quantityreceived};
127   $totalquantity+=$order->{quantity};
128   $totaltoreceive+=$order->{toreceive};
129   $totalprice+=$order->{rrp}*$order->{quantity};
130   $totaltoprice+=$order->{rrp}*$order->{toreceive};
131   $totalgst+=(($order->{rrp}*$order->{quantity}) -($order->{rrp}*$order->{quantity}*$order->{discount}/100))* $order->{gst}/100;
132   $totaltogst+=(($order->{rrp}*$order->{toreceive}) -($order->{rrp}*$order->{toreceive}*$order->{discount}/100))* $order->{gst}/100;
133   $totaldiscount +=$order->{rrp}*$order->{quantity}*$order->{discount}/100;
134   $totaltodiscount +=$order->{rrp}*$order->{toreceive}*$order->{discount}/100;
135   $order->{actualrrp}=sprintf( "%.2f",$order->{rrp}/$currencyrate);
136         push @loop_orders, $order;
137   }     
138 }
139   
140 }else{
141 ## one basket
142 $countpendings=1;
143
144 my @orders=GetOrders($basketno);
145   foreach my $order(@orders){
146 $invoice=$order->{booksellerinvoicenumber} unless $invoice;
147   $order->{toreceive}=$order->{quantity} - $order->{quantityreceived};
148   $totalquantity+=$order->{quantity};
149   $totaltoreceive+=$order->{toreceive};
150   $totalprice+=$order->{rrp}*$order->{quantity};
151   $totaltoprice+=$order->{rrp}*$order->{toreceive};
152   $totalgst+=(($order->{rrp}*$order->{quantity}) -($order->{rrp}*$order->{quantity}*$order->{discount}/100))* $order->{gst}/100;
153   $totaltogst+=(($order->{rrp}*$order->{toreceive}) -($order->{rrp}*$order->{toreceive}*$order->{discount}/100))* $order->{gst}/100;
154   $totaldiscount +=$order->{rrp}*$order->{quantity}*$order->{discount}/100;
155   $totaltodiscount +=$order->{rrp}*$order->{toreceive}*$order->{discount}/100;
156   $order->{actualrrp}=sprintf( "%.2f",$order->{rrp}/$currencyrate);
157         push @loop_orders, $order;
158   }     
159 }
160 undef $invcurrency if ($currencyrate ==1);
161
162 $template->param( invoice=>$invoice,
163                         date => format_date($date),
164                         name => $booksellers[0]->{'name'},
165                         supplierid => $supplierid,
166                         countpending => $countpendings,
167                         loop_orders => \@loop_orders,
168                   user=>$user,
169                  totalquantity=>$totalquantity,
170                  totaltoreceive=>$totaltoreceive,
171                   totalprice=>sprintf( "%.2f",$totalprice),
172                  totalactual =>sprintf( "%.2f",$totaltoprice/$currencyrate),
173                         totalgst=>sprintf( "%.2f",$totalgst),
174                         actualgst=>sprintf( "%.2f",$totaltogst/$currencyrate),
175                 totaldiscount=>sprintf( "%.2f",$totaldiscount),
176                 actualdiscount=>sprintf( "%.2f",$totaltodiscount/$currencyrate),        
177                 total=>sprintf( "%.2f",$totalprice+$totalgst-$totaldiscount),
178                 gstreg=>$gstreg,
179                             gstrate=>C4::Context->preference('gist')*100,
180                 currencyrate=>$currencyrate,
181                 incgst =>$incgst,
182                 invcurrency=>$invcurrency ,
183                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
184         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
185         IntranetNav => C4::Context->preference("IntranetNav"),
186                         );
187 output_html_with_http_headers $input, $cookie, $template->output;