*** empty log message ***
[koha.git] / acqui / basket.pl
1 #!/usr/bin/perl
2
3 #script to show display basket of orders
4 #written by chris@katipo.co.nz 24/2/2000
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 # $Id$
24
25 use strict;
26 use C4::Auth;
27 use C4::Koha;
28 use C4::Output;
29 use CGI;
30 use C4::Interface::CGI::Output;
31
32
33 use C4::Acquisition;
34 use C4::Bookfund;
35 use C4::Bookseller;
36 use C4::Date;
37
38 =head1 NAME
39
40 basket.pl
41
42 =head1 DESCRIPTION
43
44  This script display all informations about basket for the supplier given
45  on input arg. Moreover, it allow to add a new order for this supplier from
46  an existing record, a suggestion or from a new record.
47
48 =head1 CGI PARAMETERS
49
50 =over 4
51
52 =item $basketno
53
54 this parameter seems to be unused.
55
56 =item supplierid
57
58 the supplier this script have to display the basket.
59
60 =item order
61
62
63
64 =back
65
66 =cut
67
68 my $query        = new CGI;
69 my $basketno     = $query->param('basketno');
70 my $booksellerid = $query->param('supplierid');
71 my $order        = $query->param('order');
72 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
73     {
74         template_name   => "acqui/basket.tmpl",
75         query           => $query,
76         type            => "intranet",
77         authnotrequired => 0,
78         flagsrequired   => { acquisition => 1 },
79         debug           => 1,
80     }
81 );
82
83 my $basket = GetBasket($basketno);
84
85 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
86 # if no booksellerid in parameter, get it from basket
87 # warn "=>".$basket->{booksellerid};
88 $booksellerid = $basket->{booksellerid} unless $booksellerid;
89 my @booksellers = GetBookSeller($booksellerid);
90 my $count2 = scalar @booksellers;
91
92 # get librarian branch...
93 if ( C4::Context->preference("IndependantBranches") ) {
94     my $userenv = C4::Context->userenv;
95     unless ( $userenv->{flags} == 1 ) {
96         my $validtest = ( $basket->{creationdate} eq '' )
97           || ( $basket->{branch}  eq '' )
98           || ( $userenv->{branch} eq $basket->{branch} )
99           || ( $userenv->{branch} eq '' )
100           || ( $basket->{branch}  eq '' );
101         unless ($validtest) {
102             print $query->redirect("../mainpage.pl");
103             exit 1;
104         }
105     }
106 }
107
108 # if new basket, pre-fill infos
109 $basket->{creationdate} = ""            unless ( $basket->{creationdate} );
110 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
111
112 my ( $count, @results );
113 @results  = GetOrders( $basketno, $order );
114 $count = scalar @results;
115
116 my $line_total;     # total of each line
117 my $sub_total;      # total of line totals
118 my $gist;           # GST
119 my $grand_total;    # $subttotal + $gist
120 my $toggle = 0;
121
122
123 # my $line_total_est; # total of each line
124 my $sub_total_est;      # total of line totals
125 my $gist_est;           # GST
126 my $grand_total_est;    # $subttotal + $gist
127
128 my $qty_total;
129
130 my @books_loop;
131 for ( my $i = 0 ; $i < $count ; $i++ ) {
132     my $rrp = $results[$i]->{'listprice'};
133     $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
134
135     $sub_total_est += $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
136     $line_total = $results[$i]->{'quantity'} * $results[$i]->{'ecost'};
137     $sub_total += $line_total;
138     $qty_total += $results[$i]->{'quantity'};
139     my %line;
140     %line=%{$results[$i]};
141    if ( $toggle == 0 ) {
142         $line{color} = '#EEEEEE';
143         $toggle = 1;
144     }
145     else {
146         $line{color} = 'white';
147         $toggle = 0;
148     }
149     $line{basketno}         = $basketno;
150     $line{i}                = $i;
151     $line{rrp}              = sprintf( "%.2f", $line{'rrp'} );
152     $line{ecost}            = sprintf( "%.2f", $line{'ecost'} );
153     $line{line_total}       = sprintf( "%.2f", $line_total );
154     $line{odd}              = $i % 2;
155     push @books_loop, \%line;
156 }
157 my $prefgist = C4::Context->preference("gist");
158 $gist            = sprintf( "%.2f", $sub_total * $prefgist );
159 $grand_total     = $sub_total + $gist;
160 $grand_total_est =
161   $sub_total_est + sprintf( "%.2f", $sub_total_est * $prefgist );
162 $gist_est = sprintf( "%.2f", $sub_total_est * $prefgist );
163 $template->param(
164     basketno         => $basketno,
165     creationdate     => format_date( $basket->{creationdate} ),
166     authorisedby     => $basket->{authorisedby},
167     authorisedbyname => $basket->{authorisedbyname},
168     closedate        => format_date( $basket->{closedate} ),
169     active           => $booksellers[0]->{'active'},
170     booksellerid     => $booksellers[0]->{'id'},
171     name             => $booksellers[0]->{'name'},
172     address1         => $booksellers[0]->{'address1'},
173     address2         => $booksellers[0]->{'address2'},
174     address3         => $booksellers[0]->{'address3'},
175     address4         => $booksellers[0]->{'address4'},
176     entrydate        => format_date( $results[0]->{'entrydate'} ),
177     books_loop       => \@books_loop,
178     count            => $count,
179     sub_total        => $sub_total,
180     gist             => $gist,
181     grand_total      => $grand_total,
182     sub_total_est    => $sub_total_est,
183     gist_est         => $gist_est,
184     grand_total_est  => $grand_total_est,
185     currency         => $booksellers[0]->{'listprice'},
186     qty_total        => $qty_total,
187 );
188 output_html_with_http_headers $query, $cookie, $template->output;