Adding MARC preview to acqui screens
[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
24 use strict;
25 use C4::Auth;
26 use C4::Koha;
27 use C4::Output;
28 use CGI;
29
30
31 use C4::Acquisition;
32 use C4::Bookfund;
33 use C4::Bookseller;
34 use C4::Date;
35
36 =head1 NAME
37
38 basket.pl
39
40 =head1 DESCRIPTION
41
42  This script display all informations about basket for the supplier given
43  on input arg. Moreover, it allow to add a new order for this supplier from
44  an existing record, a suggestion or from a new record.
45
46 =head1 CGI PARAMETERS
47
48 =over 4
49
50 =item $basketno
51
52 this parameter seems to be unused.
53
54 =item supplierid
55
56 the supplier this script have to display the basket.
57
58 =item order
59
60
61
62 =back
63
64 =cut
65
66 my $query        = new CGI;
67 my $basketno     = $query->param('basketno');
68 my $booksellerid = $query->param('supplierid');
69 my $order        = $query->param('order');
70 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
71     {
72         template_name   => "acqui/basket.tmpl",
73         query           => $query,
74         type            => "intranet",
75         authnotrequired => 0,
76         flagsrequired   => { acquisition => 1 },
77         debug           => 1,
78     }
79 );
80
81 my $basket = GetBasket($basketno);
82
83 # FIXME : the query->param('supplierid') below is probably useless. The bookseller is always known from the basket
84 # if no booksellerid in parameter, get it from basket
85 # warn "=>".$basket->{booksellerid};
86 $booksellerid = $basket->{booksellerid} unless $booksellerid;
87 my @booksellers = GetBookSeller($booksellerid);
88 my $count2 = scalar @booksellers;
89
90 # get librarian branch...
91 if ( C4::Context->preference("IndependantBranches") ) {
92     my $userenv = C4::Context->userenv;
93     unless ( $userenv->{flags} == 1 ) {
94         my $validtest = ( $basket->{creationdate} eq '' )
95           || ( $basket->{branch}  eq '' )
96           || ( $userenv->{branch} eq $basket->{branch} )
97           || ( $userenv->{branch} eq '' )
98           || ( $basket->{branch}  eq '' );
99         unless ($validtest) {
100             print $query->redirect("../mainpage.pl");
101             exit 1;
102         }
103     }
104 }
105
106 # if new basket, pre-fill infos
107 $basket->{creationdate} = ""            unless ( $basket->{creationdate} );
108 $basket->{authorisedby} = $loggedinuser unless ( $basket->{authorisedby} );
109 warn $loggedinuser;
110 warn $basket->{creationdate};
111 warn $basket->{authorisedby} ;
112
113 my ( $count, @results );
114 @results  = GetOrders( $basketno, $order );
115 $count = scalar @results;
116
117 my $line_total;     # total of each line
118 my $sub_total;      # total of line totals
119 my $gist;           # GST
120 my $grand_total;    # $subttotal + $gist
121 my $toggle = 0;
122
123
124 # my $line_total_est; # total of each line
125 my $sub_total_est;      # total of line totals
126 my $gist_est;           # GST
127 my $grand_total_est;    # $subttotal + $gist
128
129 my $qty_total;
130
131 my @books_loop;
132 for ( my $i = 0 ; $i < $count ; $i++ ) {
133     my $rrp = $results[$i]->{'listprice'};
134     $rrp = ConvertCurrency( $results[$i]->{'currency'}, $rrp );
135
136     $sub_total_est += $results[$i]->{'quantity'} * $results[$i]->{'rrp'};
137     $line_total = $results[$i]->{'quantity'} * $results[$i]->{'ecost'};
138     $sub_total += $line_total;
139     $qty_total += $results[$i]->{'quantity'};
140     my %line;
141     %line=%{$results[$i]};
142    if ( $toggle == 0 ) {
143         $line{color} = '#EEEEEE';
144         $toggle = 1;
145     }
146     else {
147         $line{color} = 'white';
148         $toggle = 0;
149     }
150     $line{basketno}         = $basketno;
151     $line{i}                = $i;
152     $line{rrp}              = sprintf( "%.2f", $line{'rrp'} );
153     $line{ecost}            = sprintf( "%.2f", $line{'ecost'} );
154     $line{line_total}       = sprintf( "%.2f", $line_total );
155     $line{odd}              = $i % 2;
156     push @books_loop, \%line;
157 }
158 my $prefgist = C4::Context->preference("gist");
159 $gist            = sprintf( "%.2f", $sub_total * $prefgist );
160 $grand_total     = $sub_total + $gist;
161 $grand_total_est =
162   $sub_total_est + sprintf( "%.2f", $sub_total_est * $prefgist );
163 $gist_est = sprintf( "%.2f", $sub_total_est * $prefgist );
164 $template->param(
165     basketno         => $basketno,
166     creationdate     => format_date( $basket->{creationdate} ),
167     authorisedby     => $basket->{authorisedby},
168     authorisedbyname => $basket->{authorisedbyname},
169     closedate        => format_date( $basket->{closedate} ),
170     active           => $booksellers[0]->{'active'},
171     booksellerid     => $booksellers[0]->{'id'},
172     name             => $booksellers[0]->{'name'},
173     address1         => $booksellers[0]->{'address1'},
174     address2         => $booksellers[0]->{'address2'},
175     address3         => $booksellers[0]->{'address3'},
176     address4         => $booksellers[0]->{'address4'},
177     entrydate        => format_date( $results[0]->{'entrydate'} ),
178     books_loop       => \@books_loop,
179     count            => $count,
180     sub_total        => $sub_total,
181     gist             => $gist,
182     grand_total      => $grand_total,
183     sub_total_est    => $sub_total_est,
184     gist_est         => $gist_est,
185     grand_total_est  => $grand_total_est,
186     currency         => $booksellers[0]->{'listprice'},
187     qty_total        => $qty_total,
188 );
189 output_html_with_http_headers $query, $cookie, $template->output;